Skip to content

akosthekiss/tar-rs

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

48 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

tar-rs

Build Status

Documentation

A tar archive reading/writing library for Rust.

# Cargo.toml
[dependencies.tar]
git = "https://github.com/alexcrichton/tar-rs"

Reading an archive

# #![allow(unused_must_use)]
extern crate tar;

use tar::Archive;
use std::io::{File, SeekSet};

fn main() {
    let file = File::open(&Path::new("foo.tar")).unwrap();
    let a = Archive::new(file);

    for file in a.files().unwrap() {
        // Make sure there wasn't an I/O error
        let mut file = file.unwrap();

        // Inspect metadata about the file
        println!("{}", file.filename());
        println!("{}", file.size());

        // files implement the Reader trait
        println!("{}", file.read_to_string());

        // files also implement the Seek trait
        file.seek(0, SeekSet);
    }
}

Writing an archive

# #![allow(unused_must_use)]
extern crate tar;

use tar::Archive;
use std::io::File;

fn main() {
    let file = File::create(&Path::new("foo.tar")).unwrap();
    let a = Archive::new(file);

    a.append("file1.txt", &mut File::open(&Path::new("file1.txt")).unwrap());
    a.append("file2.txt", &mut File::open(&Path::new("file2.txt")).unwrap());
    a.finish();
}

License

tar-rs is primarily distributed under the terms of both the MIT license and the Apache License (Version 2.0), with portions covered by various BSD-like licenses.

See LICENSE-APACHE, and LICENSE-MIT for details.

About

Tar file reading/writing for Rust

Resources

License

Apache-2.0, MIT licenses found

Licenses found

Apache-2.0
LICENSE-APACHE
MIT
LICENSE-MIT

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Rust 100.0%