A rust binding for the zstd compression library.
当前项目代码仓暂无内容
以下内容由 AI 翻译,如有问题请 点此提交 issue 反馈
zstd
本库是 zstd 压缩库 的 Rust 绑定。
文档
1 - 添加到 cargo.toml
$ cargo add zstd
# Cargo.toml
[dependencies]
zstd = "0.13"
2 - 使用方法
该库提供 Read 和 Write 包装器来处理(解)压缩,同时提供便捷函数以简化常见任务。
例如,stream::copy_encode 和 stream::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 库的构建并与之链接。
构建时绑定生成
本库包含一个预生成的 bindings.rs 文件。
您也可以使用 bindgen 功能在构建时生成新的绑定:
cargo build --features bindgen
待办事项
- 基准测试、优化等
免责声明
本实现很大程度上受 bozaro 的 lz4-rs 启发。
许可协议
- zstd C 库采用 BSD/GPLv2 双许可协议。
- 本 zstd-rs 绑定库采用 BSD-3-Clause 许可协议。