std/inflate
Pure-Milo DEFLATE decompression (RFC 1951) plus gzip (RFC 1952) and zlib (RFC 1950) unwrapping. This is the decompressor everything downstream needs: gzip HTTP bodies, PNG IDAT, git objects. Structure follows Mark Adler's puff.c. Compress with std/deflate.
from "std/inflate" import { Inflate }API reference
Huff
pub struct HuffA canonical Huffman table: count[len] = #codes of that bit length, symbol[] = symbols sorted by (length, value).
Fields: count: Vec<i64>, symbol: Vec<i64>.
Inflate
pub struct InflateInflate namespace — Inflate.raw (raw inflate), .gzip, .zlib decompressors.
Inflate.gzip
fn Inflate.gzip(src: &string): Result<string, string>Unwrap a gzip stream and decompress its body. Errs on malformed input or a checksum mismatch.
Inflate.gzipMax
fn Inflate.gzipMax(src: &string, max: i64): Result<string, string>Inflate.gzip with an output cap, as rawMax.
Inflate.raw
fn Inflate.raw(src: &string): Result<string, string>Decompress a raw DEFLATE stream (no container header). Malformed input is an Err, not a crash.
Inflate.rawMax
fn Inflate.rawMax(src: &string, max: i64): Result<string, string>Inflate.raw that fails with INFLATE_TOO_BIG instead of producing more than max bytes: for input from someone else (a request body), where a few KiB can claim gigabytes.
Inflate.zlib
fn Inflate.zlib(src: &string): Result<string, string>Unwrap a zlib stream and decompress its body. Errs on malformed input or a checksum mismatch.
Inflate.zlibMax
fn Inflate.zlibMax(src: &string, max: i64): Result<string, string>Inflate.zlib with an output cap, as rawMax.
InfState
pub struct InfStateDecoder state. src is passed alongside as a borrow — a struct can't hold a second-class reference, so only the mutable owned pieces live here.
Fields:
inpos: i64: next input byte indexbitbuf: i64: bit accumulator (LSB-first)bitcnt: i64: valid bits in bitbuferr: bool: set when the reader runs off the end of inputout: string: decompressed byteslimit: i64: most output bytes allowed; past it the stream fails with -30