Skip to content

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.

milo
from "std/inflate" import { Inflate }

API reference ​

Huff ​

milo
pub struct Huff

A canonical Huffman table: count[len] = #codes of that bit length, symbol[] = symbols sorted by (length, value).

Fields: count: Vec<i64>, symbol: Vec<i64>.

Inflate ​

milo
pub struct Inflate

Inflate namespace — Inflate.raw (raw inflate), .gzip, .zlib decompressors.

Inflate.gzip ​

milo
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 ​

milo
fn Inflate.gzipMax(src: &string, max: i64): Result<string, string>

Inflate.gzip with an output cap, as rawMax.

Inflate.raw ​

milo
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 ​

milo
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 ​

milo
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 ​

milo
fn Inflate.zlibMax(src: &string, max: i64): Result<string, string>

Inflate.zlib with an output cap, as rawMax.

InfState ​

milo
pub struct InfState

Decoder 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 index
  • bitbuf: i64: bit accumulator (LSB-first)
  • bitcnt: i64: valid bits in bitbuf
  • err: bool: set when the reader runs off the end of input
  • out: string: decompressed bytes
  • limit: i64: most output bytes allowed; past it the stream fails with -30