lz4_decompress 0.13.0

Pure Rust implementation of lz4 decompression.
Documentation

Docs Crates.io

lz4_decompress

Pure Rust implementation of lz4 decompression.

Fork of the awesome lz4_flex, modified to support decompressing data without providing the minimal uncompressed size.

Features

  • LZ4 Block format
  • LZ4 Frame format
  • Decompress without providing the minimal uncompressed size

Block Format

The block format is only valid for smaller data chunks as block is decompressed in memory. For larger data use the frame format, which consists of multiple blocks.

use lz4_decompress::block::{decompress_safe, decompress};
use lz4_flex::block::compress_prepend_size;

fn main(){
    let input: &[u8] = b"Hello people, what's up?";
     // we use lz4_flex to compress
    let compressed = compress_prepend_size(input);
    let uncompressed = decompress_size_prepended(&compressed).unwrap();
    assert_eq!(input, uncompressed);
    // remove size prefix
    let compressed_without_size = &compressed[4..];
    // decompress without providing min uncompressed size
    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);
}