72个发布版本

0.13.2 2024年7月5日
0.13.1 2024年3月27日
0.13.0 2023年10月11日
0.12.4 2023年7月19日
0.1.3 2016年3月2日

#5 in 压缩

Download history • Rust 包仓库 995905/week @ 2024-05-04 • Rust 包仓库 1101279/week @ 2024-05-11 • Rust 包仓库 1089584/week @ 2024-05-18 • Rust 包仓库 972542/week @ 2024-05-25 • Rust 包仓库 1093571/week @ 2024-06-01 • Rust 包仓库 1079394/week @ 2024-06-08 • Rust 包仓库 1058357/week @ 2024-06-15 • Rust 包仓库 1084694/week @ 2024-06-22 • Rust 包仓库 1016811/week @ 2024-06-29 • Rust 包仓库 1076064/week @ 2024-07-06 • Rust 包仓库 1075780/week @ 2024-07-13 • Rust 包仓库 1147717/week @ 2024-07-20 • Rust 包仓库 1127778/week @ 2024-07-27 • Rust 包仓库 1136876/week @ 2024-08-03 • Rust 包仓库 1197929/week @ 2024-08-10 • Rust 包仓库 978977/week @ 2024-08-17 • Rust 包仓库

4,641,377 monthly downloads
用于 3,018 个crates (480直接使用)

MIT 许可证

190KB
3.5K SLoC

zstd

crates.io MIT licensed

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

这个库是zstd压缩库的Rust绑定。

文档

1 - 添加到 cargo.toml

$ cargo add zstd
# Cargo.toml

[dependencies]
zstd = "0.13"

2 - 使用方法

该库提供了ReadWrite包装器来处理压缩和解压缩,以及方便的函数来简化常见任务。

例如,stream::copy_encodestream::copy_decode是围绕std::io::copy的易于使用的包装器。请查看stream示例

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

异步支持

async-compression crate提供了包括zstd-rs在内的各种压缩算法的异步集成。

自行编译

zstd作为子模块包含在内。要在克隆时获取所有内容,请使用

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

或者,如果您没有使用--recursive标志克隆,请从仓库内部调用此命令

git submodule update --init

然后,运行cargo build应该会处理构建C库并将其链接到库中。

编译时bindgen

此库包含一个预生成的bindings.rs文件。您还可以使用bindgen功能在编译时生成新的绑定。

cargo build --features bindgen

待办事项

  • 基准测试,优化...

免责声明

此实现主要受bozaro的lz4-rs的启发。

许可证

  • zstd C库采用双重BSD/GPLv2许可证。
  • 此zstd-rs绑定库采用MIT许可证。

依赖项

~2.5–3.5MB
~57K SLoC