inflate ( bytes -- bytes' )
Raw DEFLATE compression

Prev:deflate ( bytes -- bytes' )
Next:invalid-deflate ( reason -- * )


Vocabulary
compression.deflate

Inputs
bytesa byte-array


Outputs
bytes'a byte-array


Word description
Decompresses a raw RFC 1951 DEFLATE stream. Supports stored, fixed Huffman, and dynamic Huffman blocks, including overlapping matches and references into earlier blocks. Stops at the end of the final block; remaining padding bits and trailing bytes are ignored. The complete result is held in memory.

Errors
Throws invalid-deflate for truncated or malformed input, including invalid Huffman trees, reserved codes, and references before the beginning of the output.

Definition


:: inflate ( bytes -- bytes' )
bytes <lsb0-bit-reader> :> reader
BV{ } clone :> output f :> final!
[ final not ] [
1 reader read-bits 1 = final! 2 reader read-bits {
{ 0 [ reader output stored-block ] }
{
1
[
fixed-lengths f huffman-table 32 5 <array>
f huffman-table
reader output compressed-block
]
}
{
2
[
reader dynamic-tables reader output
compressed-block
]
}
{ 3 [ "reserved block type" invalid-deflate ] }
} case
] while output >byte-array ;