Crate tar_light

Crate tar_light 

Source
Expand description

Simple tar archive reader and writer library

§Usage

§Packing files into a TAR archive

use tar_light::pack;

let files = vec!["testdata/file1.txt", "testdata/file2.txt"];
 
pack("archive.tar", &files);
// Creates archive.tar containing file1.txt and file2.txt
pack("archive.tar.gz", &files);
// Creates archive.tar.gz that is gzip-compressed

§Unpacking files from a TAR archive

use tar_light::unpack;

unpack("testdata/simple.tar", "output_directory");
// Extracts all files from simple.tar to output_directory/
unpack("testdata/simple.tar.gz", "output_directory");
// Extracts all files from simple.tar.gz that is gzip-compressed

§Listing files in a TAR archive header

use tar_light::list;

match list("archive.tar") {
    Ok(headers) => {
        println!("Files in archive:");
        for header in headers {
            println!("  {} ({} bytes)", header.name, header.size);
        }
    }
    Err(e) => eprintln!("Error: {}", e),
}

§Listing files in a TAR entry

use tar_light::list_entry;

match list_entry("archive.tar") {
    Ok(entries) => {
        println!("Files in archive:");
        for entry in entries {
            println!("  {} ({} bytes)", entry.header.name, entry.header.size);
        }
    }
    Err(e) => eprintln!("Error: {}", e),
}

§Advanced usage with low-level API

use tar_light::{read_tar, write_tar, Tar, TarEntry, TarHeader};
use std::fs;

// Read tar archives
let bin_bytes = fs::read("testdata/simple.tar").unwrap();
let entries = read_tar(&bin_bytes);

// List entries
for entry in &entries {
    println!("{}: {} bytes", entry.header.name, entry.header.size);
}
 
// Write entries
let tar_bytes = write_tar(&entries);
fs::write("archive.tar", tar_bytes).unwrap();
 
// Create tar archive from scratch
let mut tar = Tar::new();
tar.add_str_entry("file1.txt", "Hello, World!");
tar.add_str_entry("file2.txt", "This is a test.");
let tar_bytes = tar.to_bytes();
fs::write("archive.tar", tar_bytes).unwrap();

Re-exports§

pub use tar::read_tar;
pub use tar::write_tar;
pub use tar::Tar;
pub use tar::TarEntry;
pub use tar::TarHeader;

Modules§

tar
Simple tar archive reader and writer library

Functions§

list
Lists TarHeader in a tar archive (supports .tar and .tar.gz)
list_entry
Lists TarEntry in a tar archive (supports .tar and .tar.gz)
pack
Packs files into a tar archive (supports .tar and .tar.gz)
unpack
Unpacks files from a tar archive (supports .tar and .tar.gz)
unpack_with_options
Unpacks a tar archive with options