Skip to main content

Module zstd_codec

Module zstd_codec 

Source
Expand description

Zstd compression codec for cold/archived partitions.

Higher compression ratio than LZ4 (~5-10x for structured data), slower decompression. Best for sealed partitions that are read infrequently.

Platform strategy:

  • Native: zstd crate (C libzstd, fastest)
  • WASM: ruzstd crate (pure Rust decoder, no C dependency)

Wire format:

[4 bytes] uncompressed size (LE u32)
[1 byte]  compression level used
[N bytes] Zstd frame (standard format, decodable by any Zstd implementation)

The 5-byte header prepended to the standard Zstd frame allows us to pre-allocate the output buffer on decode and store the level for metadata.

Structs§

ZstdDecoder
Zstd decoder wrapper.
ZstdEncoder
Streaming Zstd encoder. Accumulates data and compresses on finish().

Constants§

DEFAULT_LEVEL
Default Zstd compression level (3 = good balance of speed and ratio).
HIGH_LEVEL
High compression level for cold storage (19 = near-maximum ratio).

Functions§

compression_level
Get the compression level from the header.
decode
Decompress Zstd-compressed bytes.
encode
Compress raw bytes using Zstd at the default level (3).
encode_with_level
Compress raw bytes using Zstd at a specific level (1-22).
uncompressed_size
Get the uncompressed size from the header without decompressing.