30 stable releases

1.23.2 Jun 8, 2020
1.23.1 Nov 28, 2018
1.23.0 Sep 11, 2018
1.22.0 Nov 12, 2017
1.2.127 Mar 20, 2015
Download history 11240/week @ 2021-01-15 12776/week @ 2021-01-22 13113/week @ 2021-01-29 12147/week @ 2021-02-05 13510/week @ 2021-02-12 13126/week @ 2021-02-19 11595/week @ 2021-02-26 12815/week @ 2021-03-05 12671/week @ 2021-03-12 12220/week @ 2021-03-19 14783/week @ 2021-03-26 11641/week @ 2021-04-02 11276/week @ 2021-04-09 12964/week @ 2021-04-16 15011/week @ 2021-04-23 15068/week @ 2021-04-30

49,686 downloads per month
Used in 97 crates (45 directly)

MIT license

32KB
772 lines

lz4

Build Status Crates.io GitHub license 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

~1MB
~20K SLoC