rustc/vendor/tar
2019-04-29 16:16:11 -07:00
..
examples New upstream version 1.32.0~beta.2+dfsg1 2018-12-16 10:13:16 -08:00
src New upstream version 1.32.0+dfsg1 2019-01-27 21:51:14 -08:00
tests New upstream version 1.32.0+dfsg1 2019-01-27 21:51:14 -08:00
.cargo-checksum.json New upstream version 1.33.0+dfsg1 2019-04-29 16:16:11 -07:00
appveyor.yml New upstream version 1.32.0~beta.2+dfsg1 2018-12-16 10:13:16 -08:00
Cargo.toml New upstream version 1.32.0+dfsg1 2019-01-27 21:51:14 -08:00
LICENSE-APACHE New upstream version 1.32.0~beta.2+dfsg1 2018-12-16 10:13:16 -08:00
LICENSE-MIT New upstream version 1.32.0~beta.2+dfsg1 2018-12-16 10:13:16 -08:00
README.md New upstream version 1.32.0~beta.2+dfsg1 2018-12-16 10:13:16 -08:00

tar-rs

Build Status Build status Coverage Status

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 Serde by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.