36 stable releases

1.28.0 Sep 26, 2024
1.26.0 Jul 22, 2024
1.24.0 Aug 26, 2022
1.23.3 Mar 6, 2022
1.2.127 Mar 20, 2015

#10 in Compression

Download history 257191/week @ 2024-08-08 256938/week @ 2024-08-15 249245/week @ 2024-08-22 228695/week @ 2024-08-29 264787/week @ 2024-09-05 242659/week @ 2024-09-12 252902/week @ 2024-09-19 252667/week @ 2024-09-26 286713/week @ 2024-10-03 279022/week @ 2024-10-10 290986/week @ 2024-10-17 315530/week @ 2024-10-24 283021/week @ 2024-10-31 313435/week @ 2024-11-07 292158/week @ 2024-11-14 222261/week @ 2024-11-21

1,173,458 downloads per month
Used in 861 crates (116 directly)

MIT license

1MB
22K SLoC

C 18K SLoC // 0.2% comments Visual Studio Project 1.5K SLoC Rust 1.5K SLoC // 0.1% comments Python 804 SLoC // 0.1% comments Shell 482 SLoC // 0.1% comments Batch 195 SLoC // 0.1% comments C++ 171 SLoC // 0.2% comments Visual Studio Solution 130 SLoC Bitbake 69 SLoC // 0.3% comments

lz4

Build Status Crates.io Join the chat at https://gitter.im/bozaro/lz4-rs Rustdoc

NOTE: 10xGenomics is the new official home of lz4-rs, replacing https://github.com/bozaro/lz4-rs

This repository contains binding for lz4 compression library (https://github.com/Cyan4973/lz4).

LZ4 is a very fast lossless compression algorithm, providing compression speed at 400 MB/s per core, with near-linear scalability for multi-threaded applications. It also features an extremely fast decoder, with speed in multiple GB/s per core, typically reaching RAM speed limits on multi-core systems.

Usage

Put this in your Cargo.toml:

[dependencies]
lz4 = "1.23.1"

Sample code for compression/decompression:

extern crate lz4;

use std::env;
use std::fs::File;
use std::io::{self, Result};
use std::path::{Path, PathBuf};

use lz4::{Decoder, EncoderBuilder};

fn main() {
    println!("LZ4 version: {}", lz4::version());

    for path in env::args().skip(1).map(PathBuf::from) {
        if let Some("lz4") = path.extension().and_then(|e| e.to_str()) {
            decompress(&path, &path.with_extension("")).unwrap();
        } else {
            compress(&path, &path.with_extension("lz4")).unwrap();
        }
    }
}

fn compress(source: &Path, destination: &Path) -> Result<()> {
    println!("Compressing: {} -> {}", source.display(), destination.display());

    let mut input_file = File::open(source)?;
    let output_file = File::create(destination)?;
    let mut encoder = EncoderBuilder::new()
        .level(4)
        .build(output_file)?;
    io::copy(&mut input_file, &mut encoder)?;
    let (_output, result) = encoder.finish();
    result
}

fn decompress(source: &Path, destination: &Path) -> Result<()> {
    println!("Decompressing: {} -> {}", source.display(), destination.display());

    let input_file = File::open(source)?;
    let mut decoder = Decoder::new(input_file)?;
    let mut output_file = File::create(destination)?;
    io::copy(&mut decoder, &mut output_file)?;

    Ok(())
}

Dependencies