Find a file
2024-09-25 12:49:44 -04:00
.github Fix wasm32-unknown-unknown support (#274) 2024-05-24 14:01:57 -04:00
assets Replace lorem ipsup test file with public domain text 2021-03-23 08:42:12 -07:00
examples chore: fix some comments (#287) 2024-06-21 09:03:01 -04:00
src Add zio::Writer::with_output_buffer 2024-09-03 11:31:15 -04:00
tests Implement raw::Decoder::flush using an empty run step 2023-01-11 10:31:13 -05:00
zstd-safe follow SPDX for short license text (#305) 2024-09-25 12:49:44 -04:00
.gitattributes Fix git attributes 2018-10-19 16:12:22 -07:00
.gitignore Update gitignore 2017-12-21 10:44:36 +01:00
.gitmodules Add zstd-safe intermediate crate 2017-06-04 18:19:53 -07:00
Cargo.toml Bump zstd to 0.13.2 2024-07-05 18:17:32 -04:00
LICENSE Add License file 2016-02-22 19:49:47 -08:00
Readme.md Bump zstd to 0.13.0 2023-10-11 11:45:24 -04:00
rustfmt.toml Rustfmt 2017-08-16 15:53:17 -07:00

zstd

crates.io MIT licensed

Build on Linux Build on Windows Build on macOS Build on wasm

This library is a rust binding for the zstd compression library.

Documentation

1 - Add to cargo.toml

$ cargo add zstd
# Cargo.toml

[dependencies]
zstd = "0.13"

2 - Usage

This library provides Read and Write wrappers to handle (de)compression, along with convenience functions to made common tasks easier.

For instance, stream::copy_encode and stream::copy_decode are easy-to-use wrappers around std::io::copy. Check the stream example:

use std::io;

// This function use the convenient `copy_encode` method
fn compress(level: i32) {
    zstd::stream::copy_encode(io::stdin(), io::stdout(), level).unwrap();
}

// This function does the same thing, directly using an `Encoder`:
fn compress_manually(level: i32) {
    let mut encoder = zstd::stream::Encoder::new(io::stdout(), level).unwrap();
    io::copy(&mut io::stdin(), &mut encoder).unwrap();
    encoder.finish().unwrap();
}

fn decompress() {
    zstd::stream::copy_decode(io::stdin(), io::stdout()).unwrap();
}

Asynchronous support

The async-compression crate provides an async-ready integration of various compression algorithms, including zstd-rs.

Compile it yourself

zstd is included as a submodule. To get everything during your clone, use:

git clone https://github.com/gyscos/zstd-rs --recursive

Or, if you cloned it without the --recursive flag, call this from inside the repository:

git submodule update --init

Then, running cargo build should take care of building the C library and linking to it.

Build-time bindgen

This library includes a pre-generated bindings.rs file. You can also generate new bindings at build-time, using the bindgen feature:

cargo build --features bindgen

TODO

  • Benchmarks, optimizations, ...

Disclaimer

This implementation is largely inspired by bozaro's lz4-rs.

License

  • The zstd C library is under a dual BSD/GPLv2 license.
  • This zstd-rs binding library is under a MIT license.