2个版本
0.4.38 | 2021年11月20日 |
---|---|
0.4.37 | 2021年11月19日 |
#492 in WebAssembly
151 每月下载量
145KB
2.5K SLoC
tar-rs
支持wasm32-wasi目标的Rust tar存档读写库
# Cargo.toml
[dependencies]
tar-wasi = "0.4"
读取存档
extern crate tar_wasi;
use std::io::prelude::*;
use std::fs::File;
use tar_wasi::Archive;
fn main() {
let file = File::open("foo.tar").unwrap();
let mut a = Archive::new(file);
for file in a.entries().unwrap() {
// Make sure there wasn't an I/O error
let mut file = file.unwrap();
// Inspect metadata about the file
println!("{:?}", file.header().path().unwrap());
println!("{}", file.header().size().unwrap());
// files implement the Read trait
let mut s = String::new();
file.read_to_string(&mut s).unwrap();
println!("{}", s);
}
}
写入存档
extern crate tar_wasi;
use std::io::prelude::*;
use std::fs::File;
use tar_wasi::Builder;
fn main() {
let file = File::create("foo.tar").unwrap();
let mut a = Builder::new(file);
a.append_path("file1.txt").unwrap();
a.append_file("file2.txt", &mut File::open("file3.txt").unwrap()).unwrap();
}
许可证
本项目许可协议为以下之一
- Apache License, Version 2.0, (LICENSE-APACHE 或 https://apache.ac.cn/licenses/LICENSE-2.0)
- MIT license (LICENSE-MIT 或 http://opensource.org/licenses/MIT)
任选其一。
贡献
除非你明确声明,否则根据Apache-2.0许可证定义,任何提交给本项目并由你有意包含的贡献,将如上所述双重许可,不附加任何额外条款或条件。
依赖
~0–7.5MB
~44K SLoC