rusty_zstd
A ground-up, pure-Rust Zstandard (RFC 8878) compressor and decompressor.
#![deny(unsafe_code)]everywhere but one audited SIMD island, zero dependencies, no C, no*-syscrate, no FFI. Every frame it emits decompresses in facebook/zstd v1.5.7 and every frame that emits decompresses here — dual-gated on the Silesia corpus every commit.
Part of Remade With Rust by Mata Network. Full README, benchmark boards and methodology: the repository.
Install
[]
= "0.1"
# …or for embedded / wasm targets with no `std`:
= { = "0.1", = false, = ["alloc"] }
The minimum supported configuration is no_std + alloc — every entry point
returns or fills a Vec, so alloc is required. MSRV is 1.85.
| Feature | Default | What it adds |
|---|---|---|
std |
✅ | std::io-shaped streaming, multi-threading, the trainer, runtime ISA dispatch |
alloc |
✅ | implied by std; the minimum supported configuration |
profile |
the in-process stage profiler and its counters (off = zero overhead) |
Quick start
use ;
let data = b"the quick brown fox jumps over the lazy dog ".repeat;
let packed = compress?; // level 3, as libzstd defaults
assert!;
assert_eq!; // lossless, always
# Ok::
Levels run −7…22 with all nine libzstd strategies behind them.
compress_with takes a CompressOptions for the checksum flag, content size and
dictionary ID; compress_with_advanced exposes the full AdvancedOptions —
window log, strategy, LDM, workers, job size, overlap.
Streaming, for data that does not fit in memory. The pump is libzstd-shaped: hand it an input slice and an output buffer, and it reports what it consumed and produced.
use ;
let mut enc = new?;
let mut out = Vecnew;
let mut buf = vec!;
for chunk in
loop
assert_eq!;
# Ok::
Dictionaries, trained from your own samples — the win that matters for many small records:
use ;
let samples: =
.map
.collect;
let refs: = samples.iter.map.collect;
let raw = train?; // fastcover, d=8 steps=4
let dict = from_bytes?;
let packed = compress_using_dict?;
assert_eq!;
# Ok::
What is in here
| Area | Surface |
|---|---|
| One-shot | compress, decompress, decompress_into, compress_bound, content_size, find_frame_compressed_size |
| Options | CompressOptions, AdvancedOptions, DecompressOptions, CompressionParameters, Strategy |
| Streaming | Compressor, Decompressor, Flush, StreamStatus, and the four recommended-buffer-size helpers |
| Dictionaries | Dictionary, compress_using_dict, decompress_using_dict, compress_using_prefix (patch-from), train + TrainOptions / TrainAlgo |
| Long-range | LdmParams, DEFAULT_LONG_WINDOW_LOG |
| Seekable | compress_seekable, decompress_frame_at, parse_seek_table, SeekTable, SeekEntry |
| Multi-thread | compress_mt, default_nb_workers, resolve_job_size, overlap_size |
| Inspection | get_frame_header, FrameHeader, FrameKind, inspect_frames, ListedFrame |
| Checksum | xxh64 — the frame content hash, usable on its own |
Items marked #[doc(hidden)] are campaign instrumentation for the repository's
own benchmark harness. They carry no semver promise and may be renamed or
removed in any release.
Correctness
Gated against facebook/zstd v1.5.7 as an external process, in both
directions, every commit: C compresses → this decompresses bit-exact, and this
compresses → C's zstd -t and zstd -d accept it. The XXH64 checksum is gated
against the published vectors, and every SIMD kernel against its scalar twin.
License
MIT OR Apache-2.0, at your option. No GPL/LGPL and no C anywhere in the
dependency tree — CI-enforced with cargo-deny.