Crates.io | zlib_stream |
lib.rs | zlib_stream |
version | 0.1.0 |
source | src |
created_at | 2021-09-18 01:33:40.956848 |
updated_at | 2021-12-03 02:37:02.376612 |
description | An utility to decompress zlib-stream encoded WebSocket messages |
homepage | |
repository | https://github.com/ZeroTwo-Bot/zlib-stream-rs |
max_upload_size | |
id | 453143 |
size | 15,334 |
A simple utility crate to make decompressing from zlib-stream easier.
This crate is based of flate2 and their clouflare zlib backend.
stream
featureuse zlib_stream::stream::ZlibStream;
async fn setup<V: AsRef<[u8]> + Sized, T: Stream<Item=V> + Unpin>(stream: T) {
let mut stream = ZlibStream::new(stream);
loop {
let data: Option<Result<Vec<u8>, flate2::DecompressError>> = stream.next().await;
do_something(data);
}
}
use zlib_stream::{ZlibStreamDecompressor, ZlibDecompressionError};
fn worker_loop() {
let mut decompress: ZlibStreamDecompressor = ZlibStreamDecompressor::new();
loop {
let mut frame: Vec<u8> = get_compressed_frame();
match decompress.decompress(frame) {
Ok(vec) => process_data(vec),
Err(ZlibDecompressionError::NeedMoreData) => continue,
Err(_err) => panic!("Broken frame!"),
}
}
}