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, flags}; fn main() { // Create a new configuration with no special flags let cookie = Cookie::open(flags::NONE).ok().unwrap(); // Load a specific magic database let magic_db = vec!["data/tests/db-images-png"]; assert!(cookie.load(&magic_db).is_ok()); // Recognize the magic of a test file let test_file = "data/tests/rust-logo-128x128-blk.png"; let expected = "PNG image data, 128 x 128, 8-bit/color RGBA, non-interlaced"; assert_eq!(cookie.file(&test_file).ok().unwrap(), expected); }
Modules
flags |
Bitmask flags which control |
Structs
Cookie | |
MagicError |
Represents a magic error.
For the most part you should be using the |
Functions
version |
Returns the version of this crate in the format |