11 stable releases

Uses old Rust 2015

new 1.10.0 Jul 22, 2024
1.9.4 Aug 26, 2022
1.9.3 Mar 6, 2022
1.9.2 Jun 7, 2020
1.0.1+1.7.3 Nov 26, 2016

#93 in Compression

Download history 230655/week @ 2024-04-05 239131/week @ 2024-04-12 251100/week @ 2024-04-19 233231/week @ 2024-04-26 229579/week @ 2024-05-03 250189/week @ 2024-05-10 238151/week @ 2024-05-17 250972/week @ 2024-05-24 269125/week @ 2024-05-31 268780/week @ 2024-06-07 257365/week @ 2024-06-14 264220/week @ 2024-06-21 258474/week @ 2024-06-28 267772/week @ 2024-07-05 265867/week @ 2024-07-12 232818/week @ 2024-07-19

1,084,097 downloads per month
Used in 876 crates (16 directly)

MIT license

1MB
21K SLoC

C 15K SLoC // 0.2% comments Visual Studio Project 4.5K SLoC Python 793 SLoC // 0.1% comments Visual Studio Solution 329 SLoC Rust 261 SLoC // 0.4% comments C++ 173 SLoC // 0.2% comments Shell 157 SLoC // 0.1% comments 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