LZ0 is an experimental lossless compression format and C implementation for small-to-medium binary files and structured data. Its central design choice is to put more work into compression so decompression can remain exceptionally small and fast: the decoder uses no dynamic allocation, only minimal state, and caller-provided input and output buffers. It avoids adaptive entropy coding, favoring explicit LZ operations and Elias gamma integers to simplify decoding and improve throughput, while aiming for compression ratios comparable to ZX0. The format supports literal runs, copies using the previously used offset, copies with a newly encoded offset, and an end marker; overlapping copies allow short matches to expand into longer repeated sequences. A command-line file adds an eight-byte header containing a magic value and the original size, while the raw bitstream has no header.
The H2C8 encoder combines a hash-chain match finder, an O(N) suffix-array search, and a sparse dynamic-programming parser to seek good matches without the exhaustive search that can make ZX0 slow on larger inputs. It emits an MSB-first stream, with raw literal bytes interleaved among control bits, and uses a compact offset scheme plus specialized coding for match lengths. The project’s intended niche is applications where decoder size, memory use, auditability, or speed matter - such as bootloaders, microcontrollers, kernels, and retro systems. LZ0 trades away some compression efficiency relative to entropy-coded alternatives, and its encoder is more complex than its decoder; the format is independent of the encoder, allowing its search strategies to evolve without changing decompression.
Summary generated by AI from the linked article. hn.today is not affiliated with Hacker News or Y Combinator.