Expand description
Manual LZW compression and decompression helpers.
LZW starts from the LZ78 idea of building a dictionary of phrases, but it removes the explicit “suffix byte” from the token stream. Instead, both the encoder and decoder grow the same dictionary deterministically as they read codes.
§Format Overview
The compressed stream begins with the ASCII header LZW0. The remainder is
a sequence of 16-bit little-endian dictionary codes.
The initial dictionary contains all 256 one-byte values. Whenever the
encoder emits a code for phrase W and then sees the next phrase WK, the
new combined phrase is inserted into the dictionary. The decoder mirrors
that same update rule.
See the book entry Dictionary coding.
Functions§
- lzw_
compress - Compress a byte slice with a manual LZW encoder.
- lzw_
decompress - Decompress a byte slice previously produced by
lzw_compress. - try_
lzw_ decompress - Fallible variant of
lzw_decompress.