Skip to main content

Crate compress_utils

Crate compress_utils 

Source
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§

stream
Streaming compression and decompression as standard std::io adapters.

Structs§

Error
An error returned by the library: a Status code 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 Error so callers can match on the exact failure. Values match the CU_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 data with algo at level (1 fastest ..= 10 smallest).
decompress
Decompress data produced by algo. 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 data into at most capacity bytes. 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 decompress and decompress_with_capacity will accept, for every algorithm. Defaults to 1 GiB; 0 disables the cap. A Decompressor has no limit unless set with Decompressor::set_max_output.
version
The linked library version string ("MAJOR.MINOR.PATCH").