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.
Raw DEFLATE, raw LZ4 blocks and raw LZO1X blocks (decompression only) are
also available; raw blocks don’t record their size, so decode them with
decompress_with_capacity.
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;pub use stream::IntoPartsError;
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 decoded straight into one right-sized allocation; otherwise the C core decodes into a buffer it grows (bounded by the same cap as the sized path) and the result is copied out of it once. Raw LZ4 can use this growing decode without a capacity hint. - decompress_
with_ capacity - Decompress
datainto at mostcapacitybytes. The capacity is an upper bound on the output, allocated up front; the result holds only the bytes written. Skips the size probe and the growing decode for every algorithm. - set_
max_ decompressed_ size - Set a global cap on the output size
decompressanddecompress_with_capacitywill accept, for every algorithm. Defaults to 1 GiB;0disables the cap. ADecompressorhas no limit unless set withDecompressor::set_max_output. - version
- The linked library version string (
"MAJOR.MINOR.PATCH").