#tar #tarfile #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.

63 releases

✓ Uses Rust 2018 edition

0.4.29 Jun 16, 2020
0.4.26 May 17, 2019
0.4.22 Mar 14, 2019
0.4.20 Nov 14, 2018
0.1.0 Nov 27, 2014

#16 in Encoding

Download history 36313/week @ 2020-03-16 41065/week @ 2020-03-23 41545/week @ 2020-03-30 39223/week @ 2020-04-06 38070/week @ 2020-04-13 39910/week @ 2020-04-20 38039/week @ 2020-04-27 43779/week @ 2020-05-04 44868/week @ 2020-05-11 41725/week @ 2020-05-18 43125/week @ 2020-05-25 45136/week @ 2020-06-01 48181/week @ 2020-06-08 48417/week @ 2020-06-15 44490/week @ 2020-06-22 40986/week @ 2020-06-29

178,112 downloads per month
Used in 544 crates (198 directly)

MIT/Apache

135KB
2.5K 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

~100KB