Expand description
Pure Rust, high performance implementation of LZ4 decompression.
A detailed explanation of the algorithm can be found here.
§Overview
This crate provides two ways to use lz4. The first way is through the
frame::FrameDecoder
which implement the std::io::Read and std::io::Write traits with the
lz4 frame format. Unless you have a specific reason to the contrary, you
should only use the lz4 frame format. Specifically, the lz4 frame format
permits streaming decompression.
The second way is through the
decompress_size_prepended
function. The function provides access to the lz4 block format, and
don’t support a streaming interface directly. You should only use these types
if you know you specifically need the lz4 block format.
§Example: decompress data on stdin with frame format
This program reads data from stdin, decompresses it and emits it to stdout.
This example can be found in examples/decompress.rs:
use std::io;
let stdin = io::stdin();
let stdout = io::stdout();
// Wrap the stdin reader in a LZ4 FrameDecoder.
let mut rdr = lz4_decompress::frame::FrameDecoder::new(stdin.lock());
let mut wtr = stdout.lock();
io::copy(&mut rdr, &mut wtr).expect("I/O operation failed");§Example: block format roundtrip
use lz4_decompress::block::decompress_size_prepended;
use lz4_flex::block::compress_prepend_size;
let input: &[u8] = b"Hello people, what's up?";
let compressed = compress_prepend_size(input); // we use lz4_flex to compress
let uncompressed = decompress_size_prepended(&compressed).unwrap();
assert_eq!(input, uncompressed);§Example: block format roundtrip without known uncompressed size
use lz4_decompress::block::{decompress_safe, decompress};
use lz4_flex::block::compress_prepend_size;
let input: &[u8] = b"Hello people, what's up?";
let compressed = compress_prepend_size(input); // we use lz4_flex to compress
let compressed_without_size = &compressed[4..]; // remove size prefix
let uncompressed = decompress_safe(&compressed_without_size, None).unwrap();
assert_eq!(input, uncompressed);
let uncompressed = decompress(&compressed_without_size, 24).unwrap();
assert_eq!(input, uncompressed);