Expand description
§compress-utils
A unified, safe Rust interface to eight compression algorithms — Zstandard, Brotli, zlib, gzip, bzip2, LZ4, XZ/LZMA and Snappy — over a single C core. Every algorithm speaks the same API; switching codecs is a one-enum change.
use compress_utils::{compress, decompress, Algorithm};
let data = b"the quick brown fox jumps over the lazy dog";
let packed = compress(Algorithm::Zstd, data, 5)?;
let restored = decompress(Algorithm::Zstd, &packed)?;
assert_eq!(&restored, data);For large or incremental data, use the streaming adapters Compressor
(an std::io::Write) and Decompressor (an std::io::Read) in the
stream module.
Re-exports§
pub use stream::Compressor;pub use stream::Decompressor;
Modules§
Structs§
- Error
- An error returned by the library: a
Statuscode plus the human-readable message the C core reported.
Enums§
- Algorithm
- A compression algorithm. Values match the
CU_ALGO_*constants in the C ABI. - Status
- A C ABI status code, carried on
Errorso callers can match on the exact failure. Values match theCU_ERR_*constants.
Constants§
- DEFAULT_
LEVEL - A sensible middle-of-the-road compression level, matching the C++, Python and Go bindings. Levels run 1 (fastest) ..= 10 (smallest).
Functions§
- compress
- Compress
datawithalgoatlevel(1 fastest ..= 10 smallest). - decompress
- Decompress
dataproduced byalgo. When the wire format records the decompressed size it is recovered in a single pass; otherwise this falls back to the streaming decoder (as the C++/Python/Go bindings do). - set_
max_ decompressed_ size - Set a global cap on the output size one-shot
decompresswill accept. Defaults to 1 GiB;0disables the cap. Does not affect the streamingDecompressor, which should enforce its own limit. - version
- The linked library version string (
"MAJOR.MINOR.PATCH").