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;
// Reading TAR archives
let tar_data = read.unwrap;
let entries = read_tar;
// list entries
for entry in entries
// Creating TAR archives
let mut entries = Vecnew;
let header = new;
let data = b"Hello, World".to_vec;
let header_bytes = header.to_bytes;
entries.push;
let tar_data = write_tar;
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
Security
This library handles untrusted TAR archives. Please review SECURITY.md for important security considerations, known vulnerabilities, and best practices when working with TAR archives from untrusted sources.
Key Security Concerns:
- Path traversal vulnerabilities in
unpack()function - File overwrites without confirmation
- Symbolic link handling
See SECURITY.md for detailed information and mitigation strategies.
License
MIT