Expand description
The compression layer of the embark toolkit: one interface over
DEFLATE, LZ4, Snappy, Zstandard and LZMA1, keyed by the
CodecId that embark-format writes into
every entry header.
There are two ways in. compress and decompress take a CodecId
and dispatch at runtime, which is what a decoder reading an untrusted
entry needs. The unit structs — Store, Deflate, Lz4,
Snappy, Zstd, Lzma — are the direct-call form for a caller
that already knows its codec, and compress_best_in runs the auto
family’s codec selection: compress with one AutoTier’s worth of
candidates and keep the smallest output.
Every codec is pure Rust with no C dependency, so the whole crate builds
for no_std targets with only alloc.
§Features
Each codec has its own feature and none are on by default, so a build
links only the formats it names. enc compiles the compressing half and
dec the decompressing half; a consumer that only reads embedded files
needs dec plus the codecs its entries actually use.
parallel-encode is separate from all of those: it does not change what
is compiled, only how fast enc runs, by letting the encoder use more
than one thread. See parallel.
A codec that was not compiled in is not an error at the format level:
decompress reports Error::UnknownCodec
for it, and compress falls back to CodecId::Store
so encoding never fails.
§Example
use embark_format::CodecId;
let data = b"embark embark embark embark".repeat(8);
let packed = embark_codec::compress(CodecId::Deflate, &data);
assert!(packed.len() < data.len());
let back = embark_codec::decompress(CodecId::Deflate, &packed, data.len())?;
assert_eq!(back, data);Modules§
- parallel
enc - The build-time encoder’s thread budget.
Structs§
- Deflate
deflate - The DEFLATE codec (via
miniz_oxide). - Lz4
lz4 - The LZ4 codec (via
lz4_flex). - Lzma
lzma - The LZMA1 codec (self-implemented
.lzmaalone format). - Snappy
snappy - The Snappy codec (self-implemented).
- Store
- The identity codec: stores bytes unchanged.
- Zstd
zstd - The Zstd codec: a self-written encoder, decoding via
ruzstd.
Enums§
- Auto
Tier enc - Which codecs a selection pass is allowed to try.
Traits§
Functions§
- compress
enc - Compress with
id, falling back toCodecId::Storewhen that codec’s feature is off, so encoding never fails. - compress_
best enc - Compress
inputwith every codec compiled into this build and return the smallest result. - compress_
best_ in enc - Compress
inputwith each oftier’s candidates compiled into this build and return the smallest result. - decompress
dec - Decompress with
id, which must name a codec compiled into this build.