filemagic-rs
filemagic is a Rust wrapper for libmagic, the library that supports the file command on most Unix systems. The package provides a simple Rust API for identifying files using the extensive database of magic strings that ships with libmagic. It can also load a custom database of magic strings.
Requirements
Rust 1.40.0or above stable versionlibmagic- macOS:
brew install libmagic - Linux:
apt install libmagic1 libmagic-dev
- macOS:
Usage
Adding dependency to your Cargo.toml file
= "0.13.1"
vendored
The vendored feature uses the cc crate to compile and
static link a vendored version of libmagic, currently based on 5.45.
Adding dependency to your Cargo.toml file
= { = "0.13.1", = ["vendored"] }
Using Macros
- Using default libmagic database:
use magic;
- Using custom Magic database:
use magic;
Using the function
- Using the default libmagic database:
use Magic;
- Using custom Magic database:
use Magic;
To generate the docs
References:
- robo9k rust-magic & rust-magic-sys
- Aaron Iles