#tar-archive #tar #file-reader #reader-writer #file-io #file-writer

binstall-tar

A Rust implementation of a TAR file reader and writer. This library does not currently handle compression, but it is abstract over all I/O readers and writers. Additionally, great lengths are taken to ensure that the entire contents are never required to be entirely resident in memory all at once.

2 releases

0.4.42 Jun 7, 2024
0.4.39 Sep 10, 2022

#28 in Compression

Download history 4351/week @ 2024-08-15 4815/week @ 2024-08-22 4777/week @ 2024-08-29 6394/week @ 2024-09-05 5751/week @ 2024-09-12 4313/week @ 2024-09-19 4288/week @ 2024-09-26 4930/week @ 2024-10-03 4776/week @ 2024-10-10 4693/week @ 2024-10-17 4823/week @ 2024-10-24 4247/week @ 2024-10-31 3864/week @ 2024-11-07 4676/week @ 2024-11-14 5197/week @ 2024-11-21 4426/week @ 2024-11-28

18,825 downloads per month
Used in 14 crates (4 directly)

MIT/Apache

160KB
3K SLoC

tar-rs

Documentation

A tar archive reading/writing library for Rust.

# Cargo.toml
[dependencies]
binstall_tar = "0.4"

Reading an archive

extern crate binstall_tar;

use std::io::prelude::*;
use std::fs::File;
use binstall_tar::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);
    }
}

Writing an archive

extern crate binstall_tar;

use std::io::prelude::*;
use std::fs::File;
use tar::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();
}

License

This project is licensed under either of

at your option.

Contribution

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in this project by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.

Dependencies

~1.6–9.5MB
~112K SLoC