#tar #tarfile #encoding


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.

1 unstable release

0.4.39 Sep 10, 2022

#203 in Compression

Download history 3072/week @ 2023-02-08 2561/week @ 2023-02-15 2513/week @ 2023-02-22 2518/week @ 2023-03-01 3521/week @ 2023-03-08 1622/week @ 2023-03-15 2073/week @ 2023-03-22 1127/week @ 2023-03-29 822/week @ 2023-04-05 555/week @ 2023-04-12 1849/week @ 2023-04-19 2469/week @ 2023-04-26 3255/week @ 2023-05-03 1797/week @ 2023-05-10 2658/week @ 2023-05-17 2962/week @ 2023-05-24

10,718 downloads per month
Used in 4 crates (via binstalk-downloader)





A tar archive reading/writing library for Rust.

# Cargo.toml
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_file("file2.txt", &mut File::open("file3.txt").unwrap()).unwrap();


This project is licensed under either of

at your option.


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.


~63K SLoC