Expand description
A pure Rust implementation of the Zstandard compression format.
§Decompression
The decoding module contains the code for decompression.
Decompression can be achieved by using the decoding::StreamingDecoder
or the more low-level decoding::FrameDecoder
§Compression
The encoding module contains the code for compression.
Compression can be achieved by using the encoding::compress/encoding::compress_to_vec
functions or encoding::FrameCompressor
§zstd-complete
zstd-complete is a pure-Rust Zstandard compressor and decompressor. It works
with standard .zst data and provides Rust-friendly APIs for files, streams,
dictionaries, parallel compression, and memory-constrained applications.
The crate produces standards-compatible data rather than trying to reproduce the zstd C API or generate byte-identical output.
§Install
[dependencies]
zstd-complete = "0.2"Rust imports the package as zstd_complete.
§Quick start
use std::io::{Cursor, Read};
use zstd_complete::{
decoding::MultiFrameDecoder,
encoding::{encode_all, CompressionLevel, EncoderOptions},
};
let input = b"Zstandard compression from safe Rust";
let options = EncoderOptions::new(CompressionLevel::DEFAULT);
let compressed = encode_all(Cursor::new(input), options)?;
let mut decoder = MultiFrameDecoder::new(Cursor::new(compressed));
let mut decoded = Vec::new();
decoder.read_to_end(&mut decoded)?;
assert_eq!(decoded, input);For large inputs, Encoder<W> implements std::io::Write and keeps memory use
bounded. MultiFrameDecoder reads complete archives, including concatenated
frames. Lower-level interfaces are also available when an application needs
direct control over buffers or individual frames.
§Highlights
- Compression levels 1 through 22, negative fast levels, and uncompressed frames.
- Streaming compression and decompression with checksums and resource limits.
- Raw and formatted dictionaries, reusable prepared dictionaries, and optional
dictionary training through the
dict_builderfeature. - Optional ordered multithreaded compression through the
multithreadingfeature. The normal single-threaded path remains unchanged. no_stdsupport withalloc, including reusable workspaces and workspaces backed by caller-provided byte slices.- Portable scalar code plus runtime-selected acceleration on supported x86-64 systems.
- Safe public APIs with typed configuration and
Resulterrors.
Default features are std and hash. Disable default features for the
lower-level no_std compressor and decompressor.
§Compatibility and scope
Rust output is tested with zstd C, and this crate is tested against data produced by zstd C. Compression choices may differ, so compressed bytes and sizes are not guaranteed to match.
This is a native Rust library, not a drop-in replacement for zstd.h. It does
not expose the C ABI, deprecated C functions, experimental numeric parameters,
or internal sequence and entropy APIs. Rust workspaces replace C-style custom
allocators and static contexts.
The full comparison with zstd C 1.5.7 is in the support matrix.
§Performance and assurance
Compression ratio is close to zstd C on the Silesia corpus. zstd C is generally faster at levels 1, 3, and 8 in the current public-API benchmark, while results vary by level and input. See the release benchmarks for the measurements and their limitations.
The public API is safe Rust, although carefully bounded unsafe code is used
internally for performance. The project is tested on Linux, Windows, macOS,
AArch64, and wasm, with interoperability, forced-scalar, Miri,
AddressSanitizer, and fuzzing checks in the release process.
The translated compressor has received extensive automated and differential testing, but it has not received an independent human line-by-line source review. These checks support confidence in the implementation; they are not a formal proof or warranty.
§Origins and license
This project is a fork of
ruzstd. The compressor began as a
translation of zstd C 1.5.7 and has since been reworked around Rust ownership,
errors, streaming, and performance. It is maintained as an idiomatic Rust
implementation of the Zstandard format, not as an ongoing line-for-line port.
zstd-complete is distributed under BSD-3-Clause, using the BSD option
offered by the Zstandard reference implementation. The inherited ruzstd MIT
notice is preserved in LICENSES/ruzstd-MIT.txt; additional attribution and
provenance are in THIRD_PARTY_NOTICES.md.
Re-exports§
pub use io_std as io;std
Modules§
- decoding
- Structures and utilities used for decoding zstd formatted data
- dictionary
dict_builder - Code for creating a separate content dictionary.
- encoding
- Structures and utilities used for compressing/encoding data into the Zstd format.
- io_std
std - Re-exports of std traits or local reimplementations if std is not available