#tar-archive #tar #wasi #reader-writer #file-reader

tar-wasi

这是一个Rust实现的TAR文件读写库。该库目前不处理压缩,但它抽象了所有的I/O读取器和写入器。此外,还采取了极大措施以确保整个内容不需要一次性完全驻留在内存中。此分支包括通过target wasm32-wasi运行库的完整支持。

2个版本

0.4.38 2021年11月20日
0.4.37 2021年11月19日

#492 in WebAssembly

Download history 2/week @ 2024-03-15 2/week @ 2024-03-22 23/week @ 2024-03-29 4/week @ 2024-04-05 53/week @ 2024-06-07 69/week @ 2024-06-14 27/week @ 2024-06-21 2/week @ 2024-06-28

151 每月下载量

MIT/Apache

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-2.0许可证定义,任何提交给本项目并由你有意包含的贡献,将如上所述双重许可,不附加任何额外条款或条件。

依赖

~0–7.5MB
~44K SLoC