Skip to main content

Crate zrip

Crate zrip 

Source
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

LevelStrategyNotes
-7..=-1FastFastest encode, lowest ratio
1..=2FastGood balance for network transfers
3..=4DFastBetter 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): enables alloc and standard library support.
  • alloc: no_std with heap allocation (Vec, etc.).
  • frame (default): frame header parsing/writing; implies std.
  • dict_builder: COVER/FastCOVER dictionary training.
  • nightly: #[optimize] attributes for hot paths.

Re-exports§

pub use error::CompressError;
pub use error::DecompressError;
pub use error::ZstdError;
pub use dict::Dictionary;
pub use encode::strategy::LevelParams;
pub use decode::context::DecompressContext;
pub use decode::streaming::FrameDecoder;
pub use encode::context::CompressContext;
pub use encode::streaming::FrameEncoder;

Modules§

decode
dict
encode
error
frame
Zstd frame format constants.

Constants§

DEFAULT_DECOMPRESS_LIMIT
Default safety limit for decompressed output.

Functions§

compress
Compresses input into a zstd frame at the given level (-7..=4).
compress_bound
Returns the maximum compressed size for a given input length.
compress_into
Compresses input into a caller-provided buffer, returning bytes written.
compress_with_dict
Compresses input at the given level using a pre-trained dictionary.
compress_with_params
Compresses input using explicit LevelParams.
decompress
Decompresses a zstd-compressed frame (or concatenated frames).
decompress_into
Decompresses into an existing Vec, appending the output. Returns bytes written.
decompress_with_dict
Decompresses a zstd frame compressed with a dictionary.