packkit/lz4

LZ4 frame format codec.

Decodes LZ4 frames (magic 0x184D2204) as specified in the LZ4 Frame Format Description. The encoder runs a greedy 4-byte hash- chain match-finder over each block and emits the LZ77 sequences in the canonical block layout (token byte + optional length extensions + literals + 16-bit little-endian offset + optional match-length extensions). Blocks that don’t shrink are emitted in the uncompressed form to guarantee the frame never grows beyond 1 + ceil(input_size / block_max) * (4 + block_max).

Values

pub fn codec() -> codec.Codec

LZ4 frame codec smart constructor.

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

Decode an LZ4 frame using the default resource limits.

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

Decode an LZ4 frame using explicit resource limits.

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

Encode bytes as an LZ4 frame. The frame descriptor uses independent blocks, the v1 frame version, and a 4 MiB block maximum; no content size, block checksum, content checksum, or dictionary id is written.

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

Encode bytes as an LZ4 frame and store the uncompressed content size in the frame descriptor. Strict LZ4 decoders use the value to pre-allocate the output buffer and reject any frame whose payload disagrees with the declared length; our own decoder simply skips the field today, so encoding it does not change encode -> decode round trips.

Search Document