wire / wire-format / deflate-format

DEFLATE compressed data format (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.

wire-format kind wire-format status standard verification verified tier B wire-format@1

aka: DEFLATE compressed data format (RFC 1951)

wire format

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.

fieldsizemeaning
BFINAL1 bit1 if this is the last block.
BTYPE2 bits00 = stored (uncompressed), 01 = fixed Huffman, 10 = dynamic Huffman, 11 = reserved (error).
Stored blockvariableIf BTYPE=00: LEN (2 bytes) + NLEN (2 bytes, one's complement) + LEN bytes of literal data.
Fixed HuffmanvariableIf 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 HuffmanvariableIf 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 matchvariableA back-reference: <length (3-258), distance (1-32768)> encoded as (length code, extra bits) + (distance code, extra bits).
End of blockvariableLiteral 256 (end-of-block symbol) terminates each block.

example:

03 00

Minimal empty DEFLATE stream (BFINAL=1, BTYPE=00 stored, LEN=0)


provenance

agent: curl -H 'accept: application/json' wire.phall.io/wire-format/deflate-format or /wire-format/deflate-format.json