#lz4 #decompression #lz4f #lz4-hc

lzzzz

Full-featured liblz4 binding for Rust

27 releases (5 stable)

1.0.4 Oct 26, 2022
1.0.3 Mar 23, 2022
1.0.2 Jan 30, 2022
0.8.0 Nov 21, 2020
0.4.1 Jul 31, 2020

#23 in Compression

Download history 6058/week @ 2023-08-18 7375/week @ 2023-08-25 3874/week @ 2023-09-01 3376/week @ 2023-09-08 3277/week @ 2023-09-15 3192/week @ 2023-09-22 3344/week @ 2023-09-29 3029/week @ 2023-10-06 3371/week @ 2023-10-13 3666/week @ 2023-10-20 3531/week @ 2023-10-27 3908/week @ 2023-11-03 4522/week @ 2023-11-10 4708/week @ 2023-11-17 4906/week @ 2023-11-24 5546/week @ 2023-12-01

20,373 downloads per month
Used in 14 crates (9 directly)

MIT license

435KB
8K SLoC

C 5.5K SLoC // 0.2% comments Rust 2.5K SLoC Visual Studio Project 182 SLoC Visual Studio Solution 25 SLoC
lzzzz

Full-featured liblz4 binding for Rust

Crates.io GitHub license Rustdoc Rust


About

Rust APIs for the LZ4 compression algorithm.

  • Supports almost all liblz4 features
  • Zero dependencies except liblz4
  • Tested on Windows / macOS / Linux

Usage

Add this to your Cargo.toml:

[dependencies]
lzzzz = "1.0.3"

API Documentation

Features

  • LZ4
    • Compression (Block / Streaming)
    • Decompression (Block / Streaming)
    • Partial Decompression
    • Custom Dictionary
  • LZ4_HC
    • Compression (Block / Streaming)
    • Partial Compression
    • Custom Dictionary
  • LZ4F
    • Compression
    • Decompression
    • Custom Dictionary
    • Streaming I/O (Read / BufRead / Write)

Examples

Block Mode

use lzzzz::{lz4, lz4_hc, lz4f};

let data = b"The quick brown fox jumps over the lazy dog.";

// LZ4 compression
let mut comp = Vec::new();
lz4::compress_to_vec(data, &mut comp, lz4::ACC_LEVEL_DEFAULT)?;

// LZ4_HC compression
let mut comp = Vec::new();
lz4_hc::compress_to_vec(data, &mut comp, lz4_hc::CLEVEL_DEFAULT)?;

// LZ4/LZ4_HC decompression
let mut decomp = vec![0; data.len()];
lz4::decompress(&comp, &mut decomp)?;

// LZ4F compression
let prefs = lz4f::Preferences::default();
let mut comp = Vec::new();
lz4f::compress_to_vec(data, &mut comp, &prefs)?;

// LZ4F decompression
let mut decomp = Vec::new();
lz4f::decompress_to_vec(&comp, &mut decomp)?;

Streaming Mode

use lzzzz::{lz4, lz4_hc};

let data = b"The quick brown fox jumps over the lazy dog.";

// LZ4 compression
let mut comp = lz4::Compressor::new()?;
let mut buf = Vec::new();
comp.next_to_vec(data, &mut buf, lz4::ACC_LEVEL_DEFAULT)?;

// LZ4_HC compression
let mut comp = lz4_hc::Compressor::new()?;
let mut buf = Vec::new();
comp.next_to_vec(data, &mut buf)?;

// LZ4/LZ4_HC decompression
let mut decomp = lz4::Decompressor::new()?;
let result = decomp.next(&data, data.len())?;
use lzzzz::lz4f::{WriteCompressor, ReadDecompressor, Preferences};
use std::{fs::File, io::prelude::*};

// LZ4F Write-based compression
let mut f = File::create("foo.lz4")?;
let mut w = WriteCompressor::new(&mut f, Preferences::default())?;
w.write_all(b"Hello world!")?;

// LZ4F Read-based decompression
let mut f = File::open("foo.lz4")?;
let mut r = ReadDecompressor::new(&mut f)?;
let mut buf = Vec::new();
r.read_to_end(&mut buf)?;

No runtime deps