Crate magic [−] [src]
About
This crate provides bindings for libmagic
, which recognizes the
type of data contained in a file (or buffer).
You might be similar with libmagic
's CLI file
:
$ file data/tests/rust-logo-128x128-blk.png
data/tests/rust-logo-128x128-blk.png: PNG image data, 128 x 128, 8-bit/color RGBA, non-interlaced
Usage example
Here's an example of using this crate:
extern crate magic; use magic::{Cookie, CookieFlags}; fn main() { // Create a new default configuration let cookie = Cookie::open(CookieFlags::default()).unwrap(); // Load one specific magic database let databases = vec!["data/tests/db-images-png"]; assert!(cookie.load(&databases).is_ok()); // Recognize the magic of a test file let test_file_path = "data/tests/rust-logo-128x128-blk.png"; let expected_magic = "PNG image data, 128 x 128, 8-bit/color RGBA, non-interlaced"; assert_eq!(cookie.file(&test_file_path).unwrap(), expected_magic); }
Reexports
pub use self::flags::CookieFlags; |
Modules
flags |
Bitmask flags which control |
Structs
Cookie |
Configuration of which |
MagicError |
The error type used in this crate |
Functions
version |
Returns the version of this crate in the format |