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 file1 = "file1.txt".to_string();
let file2 = "file2.txt".to_string();
let files = vec![&file1, &file2];
 
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

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),
}

§Advanced usage with low-level API

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

// Reading TAR archives
let tar_data = fs::read("archive.tar").unwrap();
let entries = read_tar(&tar_data);

for entry in entries {
    println!("{}: {} bytes", entry.header.name, entry.header.size);
}

// Creating TAR archives
let mut entries = Vec::new();
let header = TarHeader::new("hello.txt".to_string(), 0o644, 12);
let data = b"Hello, World".to_vec();
let header_bytes = header.to_bytes();

entries.push(TarEntry { header, data, header_bytes });
let tar_data = write_tar(&entries);
fs::write("new_archive.tar", tar_data).unwrap();

Re-exports§

pub use tar::read_tar;
pub use tar::write_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)
pack
Packs files into a tar archive (supports .tar and .tar.gz)
unpack
Unpacks files from a tar archive (supports .tar and .tar.gz)