• Stars
    star
    168
  • Rank 225,507 (Top 5 %)
  • Language
    Rust
  • License
    MIT License
  • Created over 9 years ago
  • Updated about 4 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Rust LZ4 bindins library

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(())
}

More Repositories

1

git-lfs-migrate

Simple project for convert old repository for using git-lfs feature
Java
220
star
2

octobuild

Simple distributed compile system for C++
Rust
70
star
3

daemon-rs

Wrapper for linux demon/windows service for Rust
Rust
66
star
4

tech-db-lectures

Лекции по СУБД для Технопарка
HTML
47
star
5

UE4GitDepsPacker

Utility to create .gitdeps.xml files for Unreal Engine
C#
25
star
6

tech-db-forum

Тестовое задание по курсу СУБД для Технопарка
Go
24
star
7

tech-db-hello

Примеры работы с базой данных на различных языках программирования
JavaScript
12
star
8

example-annotation-processor

Examples for the presentation of a Java Annotation Processors.
Java
10
star
9

local-encoding-rs

Rust library for encoding/decoding string with local charset. It usefull for work with ANSI strings on Windows.
Rust
7
star
10

tech-template

Hugo тема для презентаций Технопарка
HTML
4
star
11

go-porter

Lite tool for build docker images without docker daemon
Go
4
star
12

bozaro.ru

My blog source
Python
2
star
13

rust-msvcdll

Simple example for function export name issue
Rust
1
star
14

bazel-stamping

Bazel stamping remote cache issue
Starlark
1
star
15

buildkit-2279

https://github.com/moby/buildkit/issues/2279
Shell
1
star
16

p4proto-java

Pure Java P4 client/server protocol implementation
Java
1
star
17

moss-wrapper

Perl wrapper for MOSS plagiarism detection system
Perl
1
star
18

about-docker

Slides for docker introduce presentation
JavaScript
1
star