<!--
{
  "availability" : [
    "iOS: -",
    "iPadOS: -",
    "macCatalyst: -",
    "macOS: -",
    "tvOS: -",
    "visionOS: -",
    "watchOS: -"
  ],
  "documentType" : "symbol",
  "framework" : "Compression",
  "identifier" : "/documentation/Compression/COMPRESSION_LZMA",
  "metadataVersion" : "0.1.0",
  "role" : "Global Variable",
  "symbol" : {
    "kind" : "Global Variable",
    "modules" : [
      "Compression"
    ],
    "preciseIdentifier" : "c:@EA@compression_algorithm@COMPRESSION_LZMA"
  },
  "title" : "COMPRESSION_LZMA"
}
-->

# COMPRESSION_LZMA

The LZMA compression algorithm, which is recommended for high-compression ratio.

```
var COMPRESSION_LZMA: compression_algorithm { get }
```

## Discussion

LZMA is a high-ratio compression algorithm that combines an LZ77 match finder with range coding driven by a Markov-chain context model. It typically achieves significantly higher compression ratios than [`COMPRESSION_ZLIB`](/documentation/Compression/COMPRESSION_ZLIB) or [`COMPRESSION_LZFSE`](/documentation/Compression/COMPRESSION_LZFSE), at the cost of being roughly an order of magnitude slower than the other Compression library algorithms for both encoding and decoding. Use LZMA when output size is the dominant concern, for example, when bandwidth or storage is far more expensive than CPU time, or when the payload is compressed once and decompressed many times.

The Compression library implements the LZMA encoder at level 6 only. This is the default compression level for open-source LZMA and provides excellent compression. The decoder accepts data compressed at any level, so you can interoperate with files produced by other LZMA implementations regardless of the level they used.

The Compression library only supports LZMA2 embedded in the XZ container. Encoded buffers and streams produced by the Compression library are valid `.xz` payloads and standard `xz` tooling on other platforms can typically decoded these payloads. It’s recommended that you use:

- ZMA when you need cross-platform decompression and are able to trade LZMA’s speed for its higher ratio.
  *`COMPRESSION_ZLIB``if speed matters more than ratio for cross-platform interoperability.
- For Apple-only payloads, prefer [`COMPRESSION_LZRAVEN`](/documentation/Compression/COMPRESSION_LZRAVEN) — it often matches or exceeds LZMA’s compression ratio, encodes a bit faster, and decodes 3x faster on Apple silicon.

LZMA is supported by both the buffer API — [`compression_encode_buffer(_:_:_:_:_:_:)`](/documentation/Compression/compression_encode_buffer(_:_:_:_:_:_:)) and [`compression_decode_buffer(_:_:_:_:_:_:)`](/documentation/Compression/compression_decode_buffer(_:_:_:_:_:_:)) — and the streaming API via [`compression_stream_init(_:_:_:)`](/documentation/Compression/compression_stream_init(_:_:_:)), so you can use it for in-memory payloads or for processing data incrementally as it arrives.

---

Copyright &copy; 2026 Apple Inc. All rights reserved. | [Terms of Use](https://www.apple.com/legal/internet-services/terms/site.html) | [Privacy Policy](https://www.apple.com/privacy/privacy-policy)