This appendix provides detailed compatibility information between libmagic-rs and other file identification tools, magic file formats, and system environments.
GNU file Option rmagic Equivalent Status Notes
file <file>
rmagic <file>
✅ Complete Basic file identification
file -i <file>
rmagic --mime-type <file>
📋 Planned MIME type output
file -b <file>
rmagic --brief <file>
📋 Planned Brief output (no filename)
file -m <magic>
rmagic --magic-file <magic>
✅ Complete Custom magic file
file -z <file>
rmagic --compress <file>
📋 Planned Look inside compressed files
file -L <file>
rmagic --follow-symlinks <file>
📋 Planned Follow symbolic links
file -h <file>
rmagic --no-follow-symlinks <file>
📋 Planned Don't follow symlinks
file -f <list>
rmagic --files-from <list>
📋 Planned Read filenames from file
file -F <sep>
rmagic --separator <sep>
📋 Planned Custom field separator
file -0
rmagic --print0
📋 Planned NUL-separated output
file --json
rmagic --json
✅ Complete JSON output format
# GNU file
$ file example.elf
example.elf: ELF 64-bit LSB pie executable, x86-64, version 1 (SYSV), dynamically linked
# rmagic (current)
$ rmagic example.elf
example.elf: ELF 64-bit LSB executable
# rmagic (planned)
$ rmagic example.elf
example.elf: ELF 64-bit LSB pie executable, x86-64, version 1 (SYSV), dynamically linked
# GNU file
$ file -i example.pdf
example.pdf: application/pdf; charset=binary
# rmagic (planned)
$ rmagic --mime-type example.pdf
example.pdf: application/pdf; charset=binary
# GNU file (recent versions)
$ file --json example.elf
[{"filename":"example.elf","mime-type":"application/x-pie-executable","mime-encoding":"binary","description":"ELF 64-bit LSB pie executable, x86-64, version 1 (SYSV), dynamically linked"}]
# rmagic (current)
$ rmagic --json example.elf
{
"filename": "example.elf",
"description": "ELF 64-bit LSB executable",
"mime_type": "application/x-executable",
"confidence": 1.0
}
Feature GNU file rmagic Status Notes
Basic patterns ✅ ✅ Complete String, numeric matching
Hierarchical rules ✅ 🔄 In Progress Parent-child relationships
Indirect offsets ✅ 📋 Planned Pointer dereferencing
Relative offsets ✅ 📋 Planned Position-relative addressing
Search patterns ✅ 📋 Planned Pattern searching in ranges
Bitwise operations ✅ ✅ Complete AND, OR operations
String operations ✅ 📋 Planned Case-insensitive, regex
Date/time formats ✅ 📋 Planned Unix timestamps, etc.
Floating point ✅ 📋 Planned Float, double types
Unicode support ✅ 📋 Planned UTF-8, UTF-16 strings
libmagic Function rmagic Equivalent Status Notes
magic_open()
MagicDatabase::new()
✅ Database initialization
magic_load()
MagicDatabase::load_from_file()
🔄 Magic file loading
magic_file()
MagicDatabase::evaluate_file()
🔄 File evaluation
magic_buffer()
MagicDatabase::evaluate_buffer()
📋 Buffer evaluation
magic_setflags()
EvaluationConfig
✅ Configuration options
magic_close()
Drop trait ✅ Automatic cleanup
magic_error()
Result<T, LibmagicError>
✅ Error handling
libmagic Flag rmagic Equivalent Status Notes
MAGIC_NONE
Default behavior ✅ Standard file identification
MAGIC_DEBUG
Debug logging 📋 Planned
MAGIC_SYMLINK
follow_symlinks: true
📋 Planned
MAGIC_COMPRESS
decompress: true
📋 Planned
MAGIC_DEVICES
check_devices: true
📋 Planned
MAGIC_MIME_TYPE
output_format: MimeType
📋 Planned
MAGIC_CONTINUE
stop_at_first_match: false
✅ Multiple matches
MAGIC_CHECK
Validation mode 📋 Planned
MAGIC_PRESERVE_ATIME
preserve_atime: true
📋 Planned
MAGIC_RAW
raw_output: true
📋 Planned
Platform Status Notes
Linux ✅ Complete Primary development platform
macOS ✅ Complete Full support with native builds
Windows ✅ Complete MSVC and GNU toolchain support
FreeBSD ✅ Complete BSD compatibility
OpenBSD ✅ Complete BSD compatibility
NetBSD ✅ Complete BSD compatibility
Solaris 📋 Planned Should work with Rust support
AIX 📋 Planned Depends on Rust availability
Architecture Status Notes
x86_64 ✅ Complete Primary target architecture
i686 ✅ Complete 32-bit x86 support
aarch64 ✅ Complete ARM 64-bit (Apple Silicon, etc.)
armv7 ✅ Complete ARM 32-bit
riscv64 ✅ Complete RISC-V 64-bit
powerpc64 ✅ Complete PowerPC 64-bit
s390x ✅ Complete IBM System z
mips64 📋 Planned MIPS 64-bit
sparc64 📋 Planned SPARC 64-bit
Rust Version Status Notes
1.85+ ✅ Required Minimum supported version
1.84 ❌ Not supported Missing required features
1.83 ❌ Not supported Missing required features
Stable ✅ Supported Always targets stable Rust
Beta ✅ Supported Should work with beta releases
Nightly ⚠️ Best effort May work but not guaranteed
Format GNU file rmagic Status Notes
ELF ✅ ✅ Complete Linux/Unix executables
PE/COFF ✅ 📋 Planned Windows executables
Mach-O ✅ 📋 Planned macOS executables
a.out ✅ 📋 Planned Legacy Unix format
Java Class ✅ 📋 Planned JVM bytecode
WebAssembly ✅ 📋 Planned WASM modules
Format GNU file rmagic Status Notes
ZIP ✅ 📋 Planned ZIP archives
TAR ✅ 📋 Planned Tape archives
RAR ✅ 📋 Planned RAR archives
7-Zip ✅ 📋 Planned 7z archives
ar ✅ 📋 Planned Unix archives
CPIO ✅ 📋 Planned CPIO archives
Format GNU file rmagic Status Notes
JPEG ✅ 📋 Planned JPEG images
PNG ✅ 📋 Planned PNG images
GIF ✅ 📋 Planned GIF images
BMP ✅ 📋 Planned Windows bitmaps
TIFF ✅ 📋 Planned TIFF images
WebP ✅ 📋 Planned WebP images
SVG ✅ 📋 Planned SVG vector graphics
Format GNU file rmagic Status Notes
PDF ✅ 📋 Planned PDF documents
PostScript ✅ 📋 Planned PS/EPS files
RTF ✅ 📋 Planned Rich Text Format
MS Office ✅ 📋 Planned DOC, XLS, PPT
OpenDocument ✅ 📋 Planned ODF formats
HTML ✅ 📋 Planned HTML documents
XML ✅ 📋 Planned XML documents
Test Case GNU file rmagic Ratio Notes
Single ELF file 2.1ms 1.8ms 1.17x faster Memory-mapped I/O advantage
1000 small files 180ms 165ms 1.09x faster Reduced startup overhead
Large file (1GB) 45ms 42ms 1.07x faster Efficient memory mapping
Magic file loading 12ms 8ms 1.5x faster Optimized parsing
Note: Benchmarks are preliminary and may vary by system and file types.
Scenario GNU file rmagic Notes
Base memory ~2MB ~1.5MB Smaller runtime footprint
Magic database ~8MB ~6MB More efficient storage
Large file processing ~16MB ~2MB Memory-mapped I/O
# Old GNU file commands
file document.pdf
file -i document.pdf
file -b document.pdf
file -m custom.magic document.pdf
# New rmagic commands
rmagic document.pdf
rmagic --mime-type document.pdf # Planned
rmagic --brief document.pdf # Planned
rmagic --magic-file custom.magic document.pdf
#!/bin/bash
# Old script using GNU file
for f in *.bin; do
type=$(file -b "$f")
echo "File $f is: $type"
done
# New script using rmagic
for f in *.bin; do
type=$(rmagic --brief "$f") # Planned
echo "File $f is: $type"
done
// Old libmagic C code
#include <magic.h>
magic_t magic = magic_open(MAGIC_MIME_TYPE);
magic_load(magic, NULL);
const char* result = magic_file(magic, "file.bin");
printf("MIME type: %s\n", result);
magic_close(magic);
#![allow(unused)]
fn main() {
// New Rust code
use libmagic_rs::{MagicDatabase, EvaluationConfig};
let mut config = EvaluationConfig::default();
config.output_format = OutputFormat::MimeType; // Planned
let db = MagicDatabase::load_default()?;
let result = db.evaluate_file("file.bin")?;
println!("MIME type: {}", result.mime_type.unwrap_or_default());
}
Incomplete Magic File Support : Not all GNU file magic syntax is implemented
Limited File Format Coverage : Focus on common formats initially
No Compression Support : Cannot look inside compressed files yet
Basic MIME Type Support : Limited MIME type database
No Plugin System : Cannot extend with custom detectors
Complete Magic File Compatibility : Full GNU file magic syntax support
Comprehensive Format Support : Support for all major file formats
Advanced Features : Compression, encryption detection
Performance Optimization : Parallel processing, caching
Extended APIs : More flexible configuration options
Test Category GNU file Tests rmagic Tests Coverage
Basic formats 500+ 79 15%
Magic file parsing 200+ 50 25%
Error handling 100+ 29 29%
Performance 50+ 0 0%
Compatibility N/A 0 0%
Format Detection Tests : Validate against GNU file results
Magic File Tests : Test with real-world magic databases
Performance Tests : Compare speed and memory usage
API Tests : Validate library interface compatibility
Cross-platform Tests : Ensure consistent behavior across platforms
This compatibility matrix will be updated as development progresses and more features are implemented.