The libcompression library provides an API for two styles of data compression:
Block compression, where all of the input data is compressed or decompressed by one call to the compression or decompression function.
Streaming compression, where the compression or decompression function is called repeatedly to compress or decompress data from a source buffer to a destination buffer. Between calls, processed data is moved out of the destination buffer and new data is loaded into the source buffer.
Choosing a Compression Algorithm
Apple provides four algorithms, each of which is believed to be the best choice in some set of circumstances.
Three commonly-known encoders are implemented: LZ4, ZLIB level 5, and LZMA level 6. In addition, we provide an encoder for Apple’s proprietary algorithm, LZFSE.
Choose an encoder according to the following guidelines:
Use LZ4 if speed is critical, and you are willing to sacrifice compression ratio to achieve it.
Use LZMA if compression ratio is critical, and you are willing to sacrifice speed to achieve it. Note that LZMA is an order of magnitude slower for both compression and decompression than other choices.
Otherwise, if speed and compression are more or less equally important, use either ZLIB or LZFSE. The choice depends on whether you require interoperability with non-Apple devices.
If you do require interoperability with non-Apple devices, use ZLIB. If you do not, use LZFSE.
LZFSE is an Apple-developed algorithm that is faster than ZLIB, and generally achieves a better compression ratio. However, it is slower than LZ4 and does not compress as well as LZMA, so you will still want to use LZ4 if speed is critical or LZMA if compression ratio is critical.
Here's some explanation of FSE: