packkit/brotli

Brotli codec — pure-Gleam decoder.

Decodes RFC 7932 brotli streams, including:

Encode side:

The SHIFT_FIRST / SHIFT_ALL transforms used by the shared-dictionary extension (RFC 8478) are deliberately omitted because the basic RFC 7932 transform set never selects them and this decoder does not accept a custom shared dictionary in the first place. Implementing them in isolation would create dead code; they will be added together with full shared-dictionary support if and when that feature lands.

Values

pub fn codec() -> codec.Codec

Brotli codec smart constructor.

pub fn decode(
  bytes bytes: BitArray,
) -> Result(BitArray, error.CodecError)

Decode a Brotli stream using default limits.

pub fn decode_with_limits(
  bytes bytes: BitArray,
  limits limits: limit.Limits,
) -> Result(BitArray, error.CodecError)

Decode a Brotli stream using explicit limits.

pub fn encode(
  bytes bytes: BitArray,
) -> Result(BitArray, error.CodecError)

Encode bytes as a Brotli stream made up of uncompressed metablocks (RFC 7932 §9.2 ISUNCOMPRESSED form) followed by a final empty ISLAST marker. The output is a valid Brotli stream that any conforming decoder accepts; it does no actual LZ77 or Huffman compression yet, but it does let packkit.compress(..., with: codec.brotli()) round-trip with the matching decoder.

Note: RFC 7932 §9.2 mandates that ISLAST=1 metablocks are compressed (there is no ISUNCOMPRESSED bit in that branch), so uncompressed payload bytes are emitted as one or more ISLAST=0 metablocks and the stream is terminated with a separate empty ISLAST=1, ISLASTEMPTY=1 marker.

Search Document