1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
//! Pure Rust Zstandard (zstd, RFC 8878) decompression and compression,
//! built to match or beat C libzstd 1.6.0 in speed. No C code, `no_std` +
//! `alloc` capable.
//!
//! # One-shot
//!
//! ```
//! // A frame holding "hello" as a raw block.
//! let compressed = [0x28, 0xb5, 0x2f, 0xfd, 0x20, 0x05, 0x29, 0x00, 0x00, b'h', b'e', b'l', b'l', b'o'];
//! assert_eq!(zstd_native::decompress(&compressed)?, b"hello");
//! # Ok::<(), zstd_native::Error>(())
//! ```
//!
//! [`Decompressor`] keeps its tables and buffers between calls (and can
//! hold a [`Dictionary`]); [`decompress_to_slice`] writes into a buffer
//! you provide.
//!
//! # Streaming
//!
//! [`Decoder`] reads a zstd stream from any `std::io::Read` (frame after
//! frame); [`StreamDecoder`] is the push API underneath (input and output
//! in pieces of any size, no `std` needed).
//!
//! ```
//! use std::io::Read;
//! # let compressed: &[u8] = &[0x28, 0xb5, 0x2f, 0xfd, 0x20, 0x05, 0x29, 0x00, 0x00, b'h', b'e', b'l', b'l', b'o'];
//! let mut text = String::new();
//! zstd_native::Decoder::new(compressed).read_to_string(&mut text)?;
//! # assert_eq!(text, "hello");
//! # Ok::<(), std::io::Error>(())
//! ```
//!
//! # Compression
//!
//! [`compress`] (and [`Compressor`], [`compress_to_slice`]) produce the
//! same bytes as libzstd 1.6.0 at every level. [`Encoder`] compresses into
//! any `std::io::Write`; [`StreamEncoder`] is the push API underneath
//! (libzstd's `ZSTD_compressStream2`, byte-identical for the same calls).
//! All of them take dictionaries too ([`compress_with_dictionary`],
//! [`Compressor::with_dictionary`], or an [`EncoderDictionary`] prepared
//! once), with libzstd's output. With `std`, [`Compressor`],
//! [`StreamEncoder`] and [`Encoder`] also compress with worker threads
//! (`set_workers`, libzstd's `ZSTD_c_nbWorkers`), with libzstd's
//! multithreaded output. Their `set_checksum` ends frames with a content
//! checksum (`ZSTD_c_checksumFlag`, off by default).
//!
//! ```
//! use std::io::Write;
//! let mut enc = zstd_native::Encoder::new(Vec::new(), 3);
//! enc.write_all(b"hello, hello, hello")?;
//! let compressed = enc.finish()?;
//! assert_eq!(zstd_native::decompress(&compressed).unwrap(), b"hello, hello, hello");
//! # Ok::<(), std::io::Error>(())
//! ```
//!
//! # Speed
//!
//! The hot loops (4-stream Huffman decoding, sequence decoding and
//! execution) are compiled twice, generic and with BMI2, and the CPU picks
//! one at run time (with `std`; without it the compile-time target
//! features decide). The `portable` feature forces the generic code.
extern crate alloc;
extern crate std;
/// Aligns the code that follows to a 64-byte boundary plus `$pad` bytes
/// of `nop`, for the top of a hot loop (libzstd does the same before its
/// sequence loop). The hot loops' speed swings by a few percent with where
/// the linker puts them; this pins their placement to the function instead
/// of the whole binary. `$pad` is tuned per loop so that the loop's first
/// instruction (after the compiler's own preheader tail) lands where it
/// measured fastest. The padding runs once per loop entry.
pub
pub use ;
pub use Dictionary;
pub use ;
pub use Error;
pub use FrameHeader;
pub use ;
pub use ;
pub use xxh64;