packkit/xz

xz codec — decoder for .xz streams.

The decoder validates the xz magic, parses stream and block headers, walks the LZMA2 chunk sequence (uncompressed and LZMA-compressed chunks), validates the index plus stream footer, and emits the concatenated block payloads. The LZMA range coder itself lives in packkit/internal/lzma.

Values

pub fn codec() -> codec.Codec

xz codec smart constructor.

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

Decode an xz stream using default limits.

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

Decode an xz stream using explicit limits.

Handles multi-stream files (per xz-file-format.txt §1: a .xz file is a concatenation of one or more independent streams, each optionally followed by stream padding aligned to 4 bytes). The concatenated payloads are returned as a single BitArray.

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

Encode bytes as an xz stream. The encoder produces a single block whose LZMA2 filter chain contains real LZMA1-compressed chunks — each chunk routes through the literal-only LZMA1 encoder in packkit/internal/lzma, so the output is a fully conforming .xz file that any decoder accepts. Compression ratio is bounded by the literal-only LZMA1 encoder (no LZ77 match search yet); plugging in a hash-chain match finder is the next obvious incremental improvement.

Search Document