Expand description
Fast, pure-Rust zstd compression.
zrip implements zstd compression levels -7 through 4 (Fast and DFast strategies),
targeting high-speed compression for data transfers. It produces standard zstd
frames decompressible by any compliant decoder.
§Quick start
let data = b"hello world, hello zstd compression!";
// Compress at level 1 (fast)
let compressed = zrip::compress(data, 1).unwrap();
// Decompress
let decompressed = zrip::decompress(&compressed).unwrap();
assert_eq!(&decompressed, data);§Compression levels
| Level | Strategy | Notes |
|---|---|---|
| -7..=-1 | Fast | Fastest encode, lowest ratio |
| 0 | Library default (currently level 1) | |
| 1..=2 | Fast | Good balance for network transfers |
| 3..=4 | DFast | Better ratio, still fast |
§Streaming
FrameEncoder and FrameDecoder implement std::io::Write and
std::io::Read for streaming compression and decompression.
use std::io::{Write, Read};
let mut encoder = zrip::FrameEncoder::new(Vec::new(), 1).unwrap();
encoder.write_all(b"streaming data").unwrap();
let compressed = encoder.finish().unwrap();
let mut decoder = zrip::FrameDecoder::new(&compressed[..]);
let mut output = Vec::new();
decoder.read_to_end(&mut output).unwrap();
assert_eq!(&output, b"streaming data");§Buffer reuse
For repeated compression/decompression, CompressContext and
DecompressContext reuse internal buffers across calls, reducing allocation
overhead in hot loops.
§Feature flags
std(default): enablesallocand standard library support.alloc:no_stdwith heap allocation (Vec, etc.).frame(default): frame header parsing/writing; impliesstd.dict_builder: COVER/FastCOVER dictionary training.nightly:#[optimize]attributes for hot paths.
Re-exports§
pub use zrip_decode as decode;pub use zrip_encode as encode;
Modules§
Structs§
- Compress
Context - Reusable compression context that amortizes hash table and buffer allocations.
- Decompress
Context - Reusable decompression context that amortizes buffer allocations.
- Dictionary
- A pre-trained zstd dictionary for improved compression of small data.
- Frame
Decoder - Streaming zstd decompressor implementing
Read. - Frame
Encoder - Streaming zstd compressor implementing
Write. - Level
Params - Compression parameters for a specific level.
Enums§
- Compress
Error - Error returned by compression functions.
- Decompress
Error - Error returned by decompression functions.
- Zstd
Error - Unified error type wrapping both compression and decompression errors.
Constants§
- DEFAULT_
DECOMPRESS_ LIMIT - DEFAULT_
LEVEL - Default compression level used when level 0 is requested.