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

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.

77 releases

new 0.4.43 Nov 2, 2024
0.4.41 Jun 4, 2024
0.4.40 Aug 7, 2023
0.4.39 Jul 13, 2023
0.1.0 Nov 27, 2014

#3 in Filesystem

Download history 588399/week @ 2024-07-18 596426/week @ 2024-07-25 589070/week @ 2024-08-01 645329/week @ 2024-08-08 625532/week @ 2024-08-15 640086/week @ 2024-08-22 607514/week @ 2024-08-29 684214/week @ 2024-09-05 646382/week @ 2024-09-12 629767/week @ 2024-09-19 695186/week @ 2024-09-26 721885/week @ 2024-10-03 715256/week @ 2024-10-10 732342/week @ 2024-10-17 759396/week @ 2024-10-24 721909/week @ 2024-10-31

3,074,899 downloads per month
Used in 2,594 crates (961 directly)

MIT/Apache

180KB
3.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

~1.6–9.5MB
~115K SLoC