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

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.

74 releases

0.4.40 Aug 7, 2023
0.4.39 Jul 13, 2023
0.4.38 Dec 14, 2021
0.4.37 Aug 12, 2021
0.1.0 Nov 27, 2014

#2 in Compression

Download history 394927/week @ 2023-11-26 406253/week @ 2023-12-03 376200/week @ 2023-12-10 336894/week @ 2023-12-17 187714/week @ 2023-12-24 289780/week @ 2023-12-31 372599/week @ 2024-01-07 401245/week @ 2024-01-14 426249/week @ 2024-01-21 423749/week @ 2024-01-28 434087/week @ 2024-02-04 421135/week @ 2024-02-11 455915/week @ 2024-02-18 501409/week @ 2024-02-25 484634/week @ 2024-03-03 190383/week @ 2024-03-10

1,661,782 downloads per month
Used in 2,071 crates (792 directly)

MIT/Apache

155KB
3K SLoC

tar-rs

Documentation

A tar archive reading/writing library for Rust.

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

Reading an archive

extern crate tar;

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

~2–11MB
~115K SLoC