Contents

COMPRESSION_LZMESH

The LZMESH compression algorithm, which is recommended for fast, general-purpose compression on Apple platforms.

Declaration

var COMPRESSION_LZMESH: compression_algorithm { get }

Discussion

LZMESH is the Apple general-purpose compression algorithm, designed to replace both COMPRESSION_LZFSE and COMPRESSION_ZLIB across Apple platforms. It combines LZ77 with length-limited Huffman coding and a lazy match parser to deliver better compression ratio than both COMPRESSION_LZFSE and COMPRESSION_ZLIB while encoding significantly faster than either. LZMESH decodes 3.5x faster than COMPRESSION_ZLIB on Apple silicon.

An LZMESH-encoded buffer is a sequence of blocks terminated by an end-of-stream marker. There are three block types:

Raw block

A header followed by uncompressed bytes. The encoder emits raw blocks when the data is incompressible, so the output is never significantly larger than the input.

Compressed block

A header followed by LZMESH-encoded data. Each block can represent up to 4 GB of uncompressed content.

End-of-stream block

A single-byte marker that terminates the stream.

Each compressed block includes a footer that records block encoding parameters. Both headers and footers reserve flag bits for future format extensions.

LZMESH is available through the buffer API only — compression_encode_buffer(_:_:_:_:_:_:) and compression_decode_buffer(_:_:_:_:_:_:).

The decoder requires only 64 KB of scratch memory, making it well suited for memory-constrained environments.

See Also

Algorithm Constants