deflate · API

deflate.raw

Raw DEFLATE (RFC 1951) — inflate and deflate, in pure Mojo.

Raw DEFLATE is the compressed stream on its own: no zlib (RFC 1950) header, no gzip (RFC 1952) wrapper, no trailing checksum. A caller that needs one of those framings parses it itself and hands the body here — Avro's deflate block codec is raw already, and Parquet's GZIP codec is this plus a gzip header and trailer.

Implementing it rather than binding zlib keeps the tin free of FFI and of any sibling dependency, so a consumer needs nothing but -I ../deflate.mojo/src.

inflate handles all three block types (stored, fixed-Huffman, dynamic-Huffman). deflate emits fixed-Huffman blocks from a single-slot hash-chain LZ77 matcher — the same "fast" strategy snappy.mojo uses — which keeps the encoder small.

Functions

inflate

def inflate(data: Span[UInt8]) -> List[UInt8]

Decompress a raw DEFLATE stream.

inflate_at

def inflate_at(data: Span[UInt8], mut end: Int) -> List[UInt8]

Decompress a DEFLATE stream, and report where it ended.

end is set to the offset of the first byte after the stream, rounded up to a byte boundary. Callers with several streams back to back — concatenated gzip members, for instance — need it to find the next one; callers that do not can use inflate.

deflate

def deflate(data: Span[UInt8]) -> List[UInt8]

Compress to a raw DEFLATE stream (one fixed-Huffman block).