Expand description
DEFLATE (RFC 1951): a compressor and a complete inflater.
The compressor is LZ77 over a 32 KiB window with a hash-chain match finder and one step of lazy matching, feeding a Huffman coder that writes both fixed (BTYPE=01) and dynamic (BTYPE=10) blocks. For every block it prices the three encodings the format allows — stored, fixed and dynamic — and writes whichever is smallest, so incompressible data costs five bytes per 64 KiB rather than growing, and small blocks do not pay for a code-length header they cannot amortise.
The inflater decodes anything a conforming compressor produces — stored,
fixed and dynamic blocks from zlib, gzip, browsers or this file — and
never panics on malformed input; every way a stream can be wrong is an
InflateError. Output is capped (decompress_with_limit) because a
decompression bomb is the cheapest denial of service there is: a kilobyte
of input can legitimately describe a gigabyte of output.
The framings that wrap a raw stream live next door in gzip.rs.
Enums§
- Inflate
Error - Everything that can be wrong with a DEFLATE, zlib or gzip stream. The framing errors live here too so the three decoders share one type.
Constants§
- DEFAULT_
MAX_ OUTPUT - The most output
decompresswill produce before giving up. Callers that know their own body limit should usedecompress_with_limitinstead; this is only the ceiling for the convenience form.
Functions§
- compress
- Compress
inputas a raw DEFLATE stream. - decompress
- Inflate a raw DEFLATE stream, with output capped at
DEFAULT_MAX_OUTPUT. - decompress_
with_ limit - Inflate a raw DEFLATE stream, refusing to produce more than
max_outbytes. Use this with the body limit you already enforce: the output is never allocated ahead of being produced, so a bomb fails at the cap, not at the allocator.