| Crates.io | tar_light |
| lib.rs | tar_light |
| version | 0.1.9 |
| created_at | 2025-11-27 02:15:08.627927+00 |
| updated_at | 2025-11-28 07:29:32.698268+00 |
| description | Simple tar archive reader and writer library |
| homepage | |
| repository | https://github.com/kujirahand/rust-tar_light |
| max_upload_size | |
| id | 1952944 |
| size | 103,504 |
A simple and lightweight tar archive reader and writer library in Rust.
.tar).tar.gz, .tgz)use tar_light::pack;
// List of files to include in the archive
let files = vec!["file1.txt", "file2.txt", "dir/file3.txt"];
// Create plain TAR archive
pack("archive.tar", &files);
// Create gzip-compressed TAR archive
pack("archive.tar.gz", &files);
use tar_light::unpack;
// Extract plain TAR archive
unpack("archive.tar", "output_directory");
// Extract gzip-compressed TAR archive
unpack("archive.tar.gz", "output_directory");
use tar_light::list;
// Works with both .tar and .tar.gz
match list("archive.tar.gz") {
Ok(headers) => {
println!("Files in archive:");
for header in headers {
println!(" {} ({} bytes)", header.name, header.size);
}
}
Err(e) => eprintln!("Error: {}", e),
}
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();
.tar - Plain TAR archives.tar.gz - Gzip-compressed TAR archives.tgz - Gzip-compressed TAR archives (alternative extension)Add to your Cargo.toml:
[dependencies]
tar_light = "0.1"
Or use cargo:
cargo add tar_light
The format is automatically detected based on the file extension.
The library includes a command-line tool for basic tar operations:
# Pack files into TAR archive
cargo run -- pack archive.tar file1.txt file2.txt
# Pack files into gzip-compressed TAR archive
cargo run -- pack archive.tar.gz file1.txt file2.txt
# Unpack archive
cargo run -- unpack archive.tar output_dir
# Unpack gzip-compressed archive
cargo run -- unpack archive.tar.gz output_dir
# List files in archive
cargo run -- list archive.tar.gz
This project uses just as a task runner, making it easy to build and test the project with simple commands. A justfile is provided for common tasks:
# Build the project
just build
# Build in release mode
just build-release
# Pack files into TAR archive
just pack archive.tar file1.txt file2.txt
# Unpack TAR archive
just unpack archive.tar output_dir
# List files in archive
just list archive.tar
# Clean up generated files
just clean
If you don't have just installed, you can install it with:
# macOS
brew install just
# Other platforms
cargo install just
MIT