The LZ4 compression algorithm, that is recommended for fast compression.
- iOS 9.0+
- macOS 10.11+
- Mac Catalyst 13.0+
- tvOS 9.0+
- watchOS 2.0+
LZ4 is a high-performance compressor. The encoded format that the Compression library produces and consumes is compatible with the open source version, apart from the addition of a very simple frame to the raw stream to allow some additional validation and functionality.
An LZ4-encoded buffer is a sequence of blocks, each of which begins with a header. The following description of the headers is provided so that you can wrap another LZ4 encoder or decoder to produce or consume the same data stream:
A compressed block header consists of the octets
0x31, followed by the size in bytes of the decoded (plaintext) data represented by the block and the size (in bytes) of the encoded data stored in the block. The headers stores both size fields as (possibly unaligned) 32-bit little-endian values. The actual LZ4-encoded data stream immediately follows the compressed block header.
An uncompressed block header consists of the octets
0x2d, followed by two sizes: the number of bytes of the decoded (plaintext) data represented by the block and the number of bytes of the encoded data stored in the block.
An end of stream block header consists of the octets
0x24and marks the end of the LZ4 frame. Do not read or write any further data beyond this header.
If you are implementing a wrapper for a raw LZ4 decoder, keep in mind that a compressed block may refer to data from the previous block, so the (decoded) previous block must be available to the decoder.