Crate zlib_rs
A pure-rust implementation of zlib.
This is a low-level implementation crate for use in libraries like flate2 and rustls. For a more high-level interface, use flate2.
For a zlib -compatible rust api of this crate, see libz-rs-sys. For instructions on integrating zlib-rs into a C library, see libz-rs-sys-cdylib.
Example
use zlib_rs::ReturnCode;
use zlib_rs::{DeflateConfig, compress_bound, compress_slice};
use zlib_rs::{InflateConfig, decompress_slice};
let input = b"Hello World";
// --- compress ---
let mut compressed_buf = vec![0u8; compress_bound(input.len())];
let (compressed, rc) =
compress_slice(&mut compressed_buf, input, DeflateConfig::default());
assert_eq!(rc, ReturnCode::Ok);
// --- decompress ---
let mut decompressed_buf = vec![0u8; input.len()];
let (decompressed, rc) =
decompress_slice(&mut decompressed_buf, compressed, InflateConfig::default());
assert_eq!(rc, ReturnCode::Ok);
assert_eq!(decompressed, input);
Modules
Structs
- Deflate The state that is used to compress an input.
- DeflateConfig Configuration for compression.
- Inflate The state that is used to decompress an input.
- InflateConfig Configuration for decompresssion.
Enums
- DeflateError Errors that can occur when compressing.
- DeflateFlush
- InflateError Errors that can occur when decompressing.
- InflateFlush
- Method
- ReturnCode
- Status Possible status results of compressing some data or successfully decompressing a block of data.
- Strategy
Functions
-
compress_bound
Returns the upper bound on the compressed size for an input of
source_lenbytes. -
compress_slice
Compresses
inputinto the providedoutputbuffer. -
decompress_slice
Decompresses
inputinto the providedoutputbuffer.