Skip to main content

libzstd_bitexact_rs/
lib.rs

1//! A pure-Rust reimplementation of [Zstandard](https://facebook.github.io/zstd/),
2//! built to be **bit-exact** with the reference C implementation.
3//!
4//! Decompression is complete: dictionaries (raw-content and trained/`ZDICT`),
5//! a configurable `windowLogMax`, and a [`Read`]-based [`StreamDecoder`] with
6//! a bounded sliding window. [`compress`] produces frames **byte-identical to
7//! C libzstd 1.5.7 at every level** (1–22 and the negative levels), and
8//! [`StreamEncoder`] mirrors `ZSTD_compressStream2` flush/end behavior (see
9//! its docs for the current streaming length scope). Every table and loop is
10//! a faithful port of its counterpart in the C sources, and the crate is
11//! continuously differential-tested against the real libzstd — see
12//! `ROADMAP.md` for what remains.
13//!
14//! [`decompress`] and [`decompress_with_limit`] cover the common one-shot
15//! cases; [`DecodeOptions`] composes an output limit, a maximum window log,
16//! and a [`Dictionary`]; [`StreamDecoder`] decodes incrementally from any
17//! reader.
18//!
19//! [`Read`]: std::io::Read
20//!
21//! ```
22//! // A tiny handcrafted frame: single-segment, content size 5, one RLE
23//! // block repeating `a` five times.
24//! let frame = [0x28, 0xB5, 0x2F, 0xFD, 0x20, 0x05, 0x2B, 0x00, 0x00, b'a'];
25//! assert_eq!(libzstd_bitexact_rs::decompress(&frame).unwrap(), b"aaaaa");
26//! ```
27
28#![forbid(unsafe_code)]
29
30mod bits;
31mod block;
32mod compress;
33mod decompress;
34mod dict_encode;
35mod dictionary;
36mod error;
37mod frame;
38mod fse;
39mod fse_encode;
40mod huffman;
41mod huffman_encode;
42mod lazy;
43mod ldm;
44mod literals_encode;
45mod opt;
46mod post_split;
47mod pre_split;
48mod sequences_encode;
49mod stream;
50mod stream_encode;
51mod xxhash;
52
53pub use compress::{
54    compress, compress_mt, compress_mt_with_dict, compress_with_cdict, compress_with_dict,
55};
56#[doc(hidden)]
57pub use compress::{cparams_create_cdict_for_testing, cparams_for_testing};
58pub use decompress::{DecodeOptions, WINDOW_LOG_MAX, decompress, decompress_with_limit};
59pub use dictionary::Dictionary;
60pub use error::Error;
61pub use stream::StreamDecoder;
62pub use stream_encode::StreamEncoder;