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.5 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;
47// Retained for parity with the 1.5.7 line; zstd 1.5.5 has no pre-block
48// splitter (`zstd_preSplit.c` is new in 1.5.6), so nothing calls it here.
49#[allow(dead_code)]
50mod pre_split;
51mod sequences_encode;
52mod stream;
53mod stream_encode;
54mod xxhash;
55
56pub use compress::{
57    compress, compress_mt, compress_mt_with_dict, compress_with_cdict, compress_with_dict,
58};
59#[doc(hidden)]
60pub use compress::{cparams_create_cdict_for_testing, cparams_for_testing};
61pub use decompress::{DecodeOptions, WINDOW_LOG_MAX, decompress, decompress_with_limit};
62pub use dictionary::Dictionary;
63pub use error::Error;
64pub use stream::StreamDecoder;
65pub use stream_encode::StreamEncoder;