wire / wire-format / deflate-format
DEFLATE is the core compression algorithm used by gzip, zlib, and ZIP. It combines LZ77 (sliding window, 32KB) with Huffman coding. The bitstream consists of blocks: each block has a 3-bit header (BFINAL, BTYPE) followed by either stored data, fixed Huffman codes, or dynamic Huffman codes with a code-length alphabet.
aka: DEFLATE compressed data format (RFC 1951)
spec: RFC 1951
DEFLATE is the core compression algorithm used by gzip, zlib, and ZIP. It combines LZ77 (sliding window, 32KB) with Huffman coding. The bitstream consists of blocks: each block has a 3-bit header (BFINAL, BTYPE) followed by either stored data, fixed Huffman codes, or dynamic Huffman codes with a code-length alphabet.
| field | size | meaning |
|---|---|---|
| BFINAL | 1 bit | 1 if this is the last block. |
| BTYPE | 2 bits | 00 = stored (uncompressed), 01 = fixed Huffman, 10 = dynamic Huffman, 11 = reserved (error). |
| Stored block | variable | If BTYPE=00: LEN (2 bytes) + NLEN (2 bytes, one's complement) + LEN bytes of literal data. |
| Fixed Huffman | variable | If BTYPE=01: literals 0-143 = 8 bits, 144-255 = 9 bits, 256-279 = 7 bits, 280-287 = 8 bits; distances 0-31 = 5 bits. |
| Dynamic Huffman | variable | If BTYPE=10: code length counts (5 bits each for 286 lit/len + 30 dist codes), then code lengths for the code-length alphabet, then the actual lit/len and distance code lengths, then the compressed data. |
| LZ77 match | variable | A back-reference: <length (3-258), distance (1-32768)> encoded as (length code, extra bits) + (distance code, extra bits). |
| End of block | variable | Literal 256 (end-of-block symbol) terminates each block. |
example:
03 00
Minimal empty DEFLATE stream (BFINAL=1, BTYPE=00 stored, LEN=0)
agent: curl -H 'accept: application/json' wire.phall.io/wire-format/deflate-format
or /wire-format/deflate-format.json