49 releases

0.5.3+zstd.1.4.5 Jun 14, 2020
0.5.1+zstd.1.4.4 Nov 5, 2019
0.4.27+zstd.1.4.2 Jul 25, 2019
0.4.22+zstd.1.3.8 Dec 27, 2018
0.1.3 Mar 2, 2016

#5 in Compression

Download history 13779/week @ 2020-06-01 15453/week @ 2020-06-08 16269/week @ 2020-06-15 17058/week @ 2020-06-22 15639/week @ 2020-06-29 15925/week @ 2020-07-06 16497/week @ 2020-07-13 16343/week @ 2020-07-20 17040/week @ 2020-07-27 18189/week @ 2020-08-03 17110/week @ 2020-08-10 19010/week @ 2020-08-17 18650/week @ 2020-08-24 18011/week @ 2020-08-31 19854/week @ 2020-09-07 20158/week @ 2020-09-14

53,823 downloads per month
Used in 154 crates (52 directly)

MIT license

2.5K SLoC


Build Status crates.io MIT licensed

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


1 - Add to cargo.toml

Using cargo-edit

$ cargo add zstd


# Cargo.toml

zstd = "0.5"

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:

extern crate zstd;

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

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

Asynchronous support

You can use this library to wrap non-blocking writer/readers: add the tokio feature, and stream::Encoder and stream::Decoder will implement AsyncWrite and AsyncRead, respectively.

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


  • Benchmarks, optimizations, ...


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


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


~103K SLoC