tar_light for Rust
A simple and lightweight tar archive reader and writer library in Rust.
Features
- 📦 Pack and unpack TAR archives (
.tar) - 🗜️ Support for gzip compression (
.tar.gz,.tgz) - 📋 List files in archives
- 🚀 Simple and intuitive API
- 🔧 Command-line tool included
Usage
Packing files into a TAR archive
use pack;
// List of files to include in the archive
let files = vec!;
// Create plain TAR archive
pack;
// Create gzip-compressed TAR archive
pack;
Unpacking files from a TAR archive
use unpack;
// Extract plain TAR archive
unpack;
// Extract gzip-compressed TAR archive
unpack;
Listing files in a TAR archive
use list;
// Works with both .tar and .tar.gz
match list
Advanced usage with low-level API
use ;
use fs;
// Read tar archives
let bin_bytes = read.unwrap;
let entries = read_tar;
// List entries
for entry in &entries
// Write entries
let tar_bytes = write_tar;
write.unwrap;
// Create tar archive from scratch
let mut tar = new;
tar.add_str_entry;
tar.add_str_entry;
let tar_bytes = tar.to_bytes;
write.unwrap;
Supported Formats
.tar- Plain TAR archives.tar.gz- Gzip-compressed TAR archives.tgz- Gzip-compressed TAR archives (alternative extension)
Installation
Add to your Cargo.toml:
[]
= "0.1"
Or use cargo:
The format is automatically detected based on the file extension.
Command Line Tool
The library includes a command-line tool for basic tar operations:
# Pack files into TAR archive
# Pack files into gzip-compressed TAR archive
# Unpack archive
# Unpack gzip-compressed archive
# List files in archive
Easy Building with just
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
# Build in release mode
# Pack files into TAR archive
# Unpack TAR archive
# List files in archive
# Clean up generated files
If you don't have just installed, you can install it with:
# macOS
# Other platforms
License
MIT