packkit/zlib

RFC 1950 zlib codec.

zlib wraps a DEFLATE stream in a two-byte header and a trailing Adler-32 checksum. The encoder delegates to the DEFLATE fixed-Huffman writer; the decoder enforces the CMF/FLG check bits and the trailing Adler-32, and can resolve the optional FDICT preset-dictionary path when the caller supplies the dictionary.

Values

pub fn codec() -> codec.Codec

Zlib codec smart constructor.

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

Decode a zlib byte stream using default limits.

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

Decode a zlib byte stream that uses the FDICT preset-dictionary path. Verifies the four-byte DICT_ID against the supplied bytes and returns CodecDictionaryMismatch when they do not agree. If bytes does not advertise FDICT this falls through to the regular decoder so callers can pass the dictionary defensively.

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

Like [decode_with_dictionary] but accepts an explicit Limits value.

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

Decode a zlib byte stream using explicit limits. Returns CodecDictionaryRequired when the stream sets the FDICT bit; use [decode_with_dictionary] in that case.

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

Encode data as a zlib byte stream. The DEFLATE body uses the dynamic-Huffman encoder (BTYPE=10) for better compression on typical inputs; pathologically-skewed payloads fall back to fixed Huffman (BTYPE=01) inside deflate.encode_dynamic.

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

Encode bytes as a zlib stream carrying the preset-dictionary adler ID for dictionary. The body is emitted by the dynamic-Huffman DEFLATE encoder over bytes alone; the receiver must already share dictionary to verify the four-byte DICT_ID. Callers that have the dictionary on both sides can use this to round-trip a stream they will later decode with decode_with_dictionary.

Search Document