A lightweight Rust library and CLI tool to detect archive types based on magic signatures and file extensions.
Standard tools like file are excellent for general purpose identification, but they often lack:
- Programmatic simplicity: Easily checking if a file is an archive and getting a structured result.
- Granular archive details: Specificity for niche game data archives, compression streams, and container formats.
- Comprehensive category mapping: Distinguishing between a "package" (like
.deb), a "compressed archive" (like.7z), and a "stream" (like.zst).
isarchive was born from the need for a tool that answers one simple question reliably: "Is this an archive, and if so, exactly what kind?"
- Signature-First Detection: Validates files using a database of over 360 magic number signatures.
- Intelligent Fallback: Uses extension matching when magic signatures are missing or the file is empty.
- Structured Categories: Maps results to MIME-like categories (e.g.,
archive/storage,archive/package). - Zero-Dependency Core: The library is extremely lightweight and compiles quickly.
Install and run the tool to identify files:
# Basic usage
isarchive my_file.zip
# Brief output (just the category)
isarchive --brief my_file.zip
# MIME style output
isarchive --mime my_file.zipmy_file.zip: ZIP compressed archive
Type: archive/compressed-archive
Add isarchive to your Cargo.toml:
[dependencies]
isarchive = { git = "https://github.com/wallentx/isarchive.git" }Use the analyze function in your code:
use isarchive::analyze;
use std::path::Path;
fn main() {
let path = Path::new("backup.tar.gz");
if let Some(info) = analyze(path) {
println!("Detected: {}", info.description);
println!("Category: {}", info.category);
} else {
println!("Not a recognized archive format.");
}
}The project uses a build.rs script to compile the archive_signatures.yaml into highly efficient, hard-coded matching logic at compile time. This ensures that lookups are nearly instantaneous and the resulting binary is self-contained.
MIT