zip_shrink only.Expand description
ZIP method 1 — Shrink: dynamic LZW with a partial-clear marker.
Shrink is the original PKZIP 1.x LZW variant. Codes are emitted at a variable width starting at 9 bits and growing up to 13 bits as the dictionary fills. Codes 0..=255 are literals. Code 256 is a control escape; the next code at the current width is interpreted as a sub-command:
1— increase the code width by one (capped at 13).2— partial clear: walk the dictionary and free every entry that has no successors (a leaf), keeping the prefix nodes intact.
Bit packing is LSB-first within each byte, matching every other
PKZIP LZW variant. The dictionary is sized to 8192 entries (HSIZE).
§Wire format on our side
ZIP method-1 payloads have no self-describing length. To make the codec usable as a standalone streaming format, we wrap the raw payload in a minimal four-byte header that carries the uncompressed length:
+-----------+================+
| u32 LE n | shrink payload |
+-----------+================+n is the number of decompressed bytes the decoder will emit. This is
analogous to legacy .lzma’s “alone” framing (which uses an 8-byte
length). If you are extracting a method-1 entry from a real ZIP, splice
the length you already have from the central directory in front of the
raw payload and feed the result to this decoder.
§Scope
Decoder only. The encoder is shipped as Error::Unsupported from every
method — implementing the partial-clear heuristic plus the leaf-aware
dictionary maintenance is well beyond the decoder, and producing
byte-identical streams to PKZIP 1.x’s reference encoder isn’t required
by any consumer we care about. Compress new data with a more modern
method (deflate, deflate64, lzma, zstd) instead.
§References
- PKWARE APPNOTE.TXT — the historical “Shrinking” section (now mostly removed; see archived 1.x copies).
- Info-ZIP
unshrink.c(BSD-style; reference for the partial-clear leaf-marking algorithm).
Structs§
- Decoder
- Streaming Shrink decoder.
- Encoder
- Encoder stub. ZIP Shrink encoding is out of scope for this build; every
method here returns
Error::Unsupported. - ZipShrink
- Zero-sized marker type implementing
Algorithmfor ZIP Shrink.