magic-db: Precompiled Magic Rules Database
A precompiled database of file type detection rules based on the original libmagic project,
optimized and adapted for use with pure-magic.
This crate provides ready-to-use file type detection capabilities without requiring external rule files.
Features
- Precompiled Rules: Optimized database embedded directly in your binary
- No External Dependencies: All rules are included in the compiled crate
- Enhanced Rules: Improved and extended versions of the original
libmagicrules - Easy Integration: Simple one-line access to the compiled database
Installation
Add magic-db to your Cargo.toml:
[]
= "0.1" # Replace with the latest version
= "0.1" # Required peer dependency
Usage
use CompiledDb;
use File;
use current_exe;
About the Rules
This database contains slightly modified versions of the original libmagic rules that are available
in the src/magdir directory of this repository.
Some of the rules have been:
- Adapted: Modified to work with the
pure-magicparser - Optimized: Performance improvements for common file types
- Extended: Additional rules were created
- Fixed: Corrections to inaccurate or problematic original rules
Rule Exclusions
The database intentionally excludes the der rules (ASN.1/DER encoding rules) because:
- The
pure-magicparser doesn't support (yet) the specific DER test types implemented in the originallibmagic
Source Rules
The source magic rules are available in the repository at:
src/magdir
You can:
- Browse the rules to understand how file types are detected
- Suggest improvements by opening issues or pull requests
- Use these rules as a reference for creating your own custom rules
License
This project is licensed under the GPL-3.0 License.
See Also
pure-magic: The core file type detection librarymagic-embed: The macro used to create this databasemagic: Expected magic rule format