7 stable releases

Uses old Rust 2015

1.9.2 Jun 7, 2020
1.8.3 Nov 28, 2018
1.8.2 Sep 11, 2018
1.8.0 Nov 12, 2017
1.0.1+1.7.3 Nov 26, 2016

#36 in Compression

Download history 13508/week @ 2021-04-08 14620/week @ 2021-04-15 16033/week @ 2021-04-22 17248/week @ 2021-04-29 17936/week @ 2021-05-06 21173/week @ 2021-05-13 24731/week @ 2021-05-20 21870/week @ 2021-05-27 19710/week @ 2021-06-03 18860/week @ 2021-06-10 20777/week @ 2021-06-17 20192/week @ 2021-06-24 19038/week @ 2021-07-01 19716/week @ 2021-07-08 20237/week @ 2021-07-15 19939/week @ 2021-07-22

64,518 downloads per month
Used in 108 crates (4 directly)

MIT license

1MB
17K SLoC

C 13K SLoC // 0.2% comments Visual Studio Project 3K SLoC Python 693 SLoC // 0.1% comments Visual Studio Solution 216 SLoC Rust 202 SLoC // 0.5% comments C++ 173 SLoC // 0.2% comments Shell 110 SLoC // 0.1% comments

lz4

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

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