Easy Archive
A cross-platform Rust library and CLI tool for working with various archive formats. Supports TAR, ZIP, and their compressed variants with a simple, unified API.
Features
- 🗜️ Multiple Formats: TAR, TAR.GZ, TAR.XZ, TAR.BZ2, TAR.ZSTD, ZIP
- 🎯 Modular: Enable only the formats you need via Cargo features
- ⚡ Operation-Specific: Separate
encodeanddecodefeatures for minimal binaries - 🚀 Performance: Optimized with buffered I/O and efficient compression
- 🔒 Type-Safe: Comprehensive error handling with structured error types
- 🌐 Cross-Platform: Works on Windows, macOS, and Linux
- 📦 Small Binaries: Optional dependencies keep your binary size minimal
- 🔧 CLI Tool: Command-line interface for quick archive operations
Installation
As a Library
Add to your Cargo.toml:
[]
= "0.2"
With Specific Features Only
To minimize binary size, enable only the formats you need:
[]
= { = "0.2", = false, = ["tar", "tar-gz", "zip"] }
As a CLI Tool
Using Cargo:
Using cargo-binstall:
Using npm/pnpm:
Quick Start
Library Usage
use ;
// Decode an archive
let data = read?;
let files = TarGz.decode?;
for file in &files
// Encode files into an archive
let files = vec!;
let archive = Zip.encode?;
write?;
CLI Usage
The CLI supports multiple inputs and optional output paths. If the output path (-o) is omitted, the tool automatically infers the default output name and prevents overwriting by appending incremental numbers (e.g., (1)).
Decompress an archive to a specific directory:
Decompress an archive to an automatically named directory (./archive/):
Compress multiple input queries to a specific archive:
Compress a single directory using an auto-inferred path (./input_dir.zip).
Note: Single directory compression strips the root folder from the zip structure.
Compress multiple directories/files using an auto-inferred path (the zip is named after the first item's parent directory):
Supported Formats
| Format | Extensions | Feature Flag | Compression |
|---|---|---|---|
| TAR | .tar |
tar |
None |
| TAR + Gzip | .tar.gz, .tgz |
tar-gz |
Gzip |
| TAR + XZ | .tar.xz, .txz |
tar-xz |
LZMA2 |
| TAR + Bzip2 | .tar.bz2, .tbz2 |
tar-bz |
Bzip2 |
| TAR + Zstd | .tar.zst, .tzst, .tzstd |
tar-zstd |
Zstandard |
| ZIP | .zip |
zip |
Deflate (decode also supports Bzip2/LZMA/XZ/Zstd) |
Feature Flags
The library uses Cargo features to enable/disable format support and operations:
Operation Features
encode- Enable archive creation (encoding)decode- Enable archive extraction (decoding)default- Enables bothencodeanddecodewith all formats
Usage Pattern: Combine operation features with format features to enable specific functionality.
- Use
["encode", "tar-xz"]to enable only TAR.XZ encoding - Use
["decode", "zip"]to enable only ZIP decoding - Use
["encode", "decode", "tar-gz"]to enable both operations for TAR.GZ
Format Features
tar- Plain TAR formattar-gz- Gzip-compressed TAR (requirestar)tar-xz- XZ-compressed TAR (requirestar)tar-bz- Bzip2-compressed TAR (requirestar)tar-zstd- Zstd-compressed TAR (requirestar)zip- ZIP format
Other Features
cli- Enables CLI binary (includes all formats and operations)wasm- WebAssembly supportrc-zip- Alternative ZIP implementation (optional)
Examples
Only ZIP decoding (smallest binary for extraction-only use case):
= { = "0.2", = false, = ["decode", "zip"] }
Only TAR.GZ encoding (for creating archives only):
= { = "0.2", = false, = ["encode", "tar-gz"] }
Only TAR.XZ decoding (specific format extraction):
= { = "0.2", = false, = ["decode", "tar-xz"] }
Multiple formats with decode only:
= { = "0.2", = false, = ["decode", "tar-gz", "zip"] }
TAR with Gzip and Zstd (both encode and decode):
= { = "0.2", = false, = ["encode", "decode", "tar-gz", "tar-zstd"] }
All formats, decode only:
= { = "0.2", = false, = ["decode", "tar", "tar-gz", "tar-xz", "tar-bz", "tar-zstd", "zip"] }
API Documentation
Core Types
Fmt Enum
Represents archive formats:
Methods:
decode(buffer: Vec<u8>) -> Result<Vec<File>>- Decode an archiveencode(files: Vec<File>) -> Result<Vec<u8>>- Encode files into an archiveguess(name: &str) -> Option<Fmt>- Guess format from filenameextensions() -> &[&str]- Get file extensions for this format
File Struct
Represents a file or directory in an archive:
ArchiveError Enum
Structured error types:
Error Handling
The library uses Result<T, ArchiveError> for all fallible operations:
use ;
match TarGz.decode
Examples
Automatic Format Detection
use Fmt;
let filename = "archive.tar.gz";
if let Some = guess
Creating a ZIP Archive
use ;
let files = vec!;
let archive = Zip.encode?;
write?;
Extracting with Metadata
use Fmt;
let data = read?;
let files = TarGz.decode?;
for file in files
Converting Between Formats
use Fmt;
// Read TAR.GZ
let data = read?;
let files = TarGz.decode?;
// Convert to ZIP
let zip_data = Zip.encode?;
write?;
Binary Size Optimization
The library is designed to minimize binary size through granular feature flags:
Size Comparison Examples
| Configuration | Approximate Binary Size | Use Case |
|---|---|---|
default |
~2-3 MB | Full functionality |
["decode", "zip"] |
~500 KB | ZIP extraction only |
["encode", "tar-gz"] |
~400 KB | TAR.GZ creation only |
["decode", "tar-xz"] |
~600 KB | TAR.XZ extraction only |
["encode", "decode", "zip"] |
~800 KB | ZIP only (both operations) |
Optimization Strategies
- Enable only needed operations: Use
encodeORdecode, not both - Select specific formats: Don't enable all formats if you only need one
- Combine wisely:
["decode", "tar-gz"]is much smaller than["default"]
Example: Minimal Extraction Tool
For a tool that only extracts ZIP files:
[]
= { = "0.2", = false, = ["decode", "zip"] }
This removes:
- All encoding logic
- All other format support (TAR, XZ, BZ2, ZSTD)
- Unused compression libraries
Performance Tips
-
Choose the Right Format:
- ZIP (Deflate): Widely compatible — every extractor (Android/iOS, Windows, macOS, web) can open it
- TAR.GZ: Good compression, widely compatible
- TAR.XZ: Best compression, slower
- TAR.ZSTD: Fast compression, good ratio
- Plain TAR: No compression, fastest
-
Pre-allocate Vectors: When creating many files, use
Vec::with_capacity() -
Avoid Duplicate Checks: The library automatically checks for duplicates during encoding
-
Streaming: For very large archives, consider processing files in batches
-
Feature Selection: Only enable the formats you need to reduce binary size and compilation time
Error Handling Best Practices
use ;
Duplicate File Detection
The library automatically detects duplicate file paths during encoding:
use ;
let files = vec!;
match Zip.encode
Platform-Specific Notes
Unix Permissions
On Unix systems, file permissions are preserved:
let file = File ;
Windows
On Windows, Unix permissions are ignored but the library still works correctly.
Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
Development Setup
Running Tests
# Run all tests
# Run tests for specific features
License
MIT License - see LICENSE file for details
Links
Changelog
Version 0.2.3
- ✨ Added feature-based format selection
- 🔧 Improved error handling with structured error types
- 🚀 Performance optimizations with buffered I/O
- 📝 Comprehensive documentation
- 🔍 Automatic duplicate file detection
- 🎯 Result-based API (breaking change from Option)