COMPRESSION_LZMA
The LZMA compression algorithm, which is recommended for high-compression ratio.
Declaration
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 or 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 — 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(_:_:_:_:_:_:) and compression_decode_buffer(_:_:_:_:_:_:) — and the streaming API via compression_stream_init(_:_:_:), so you can use it for in-memory payloads or for processing data incrementally as it arrives.