infer
Small crate to infer file and MIME type by checking the magic number signature.
Adaptation of filetype Go package ported to Rust.
Does not require magic file database (i.e. /etc/magic).
Features
- Supports a wide range of file types
- Provides file extension and MIME type
- File discovery by extension or MIME type
- File discovery by class (image, video, audio...)
- Supports custom new types and matchers
Documentation
Installation
This crate works with Cargo and is on
crates.io. Add it to your Cargo.toml
like so:
[]
= "0.1"
Examples
Get the type of a buffer
use Infer;
let v = vec!;
let info = new;
assert_eq!;
assert_eq!;
Check path
use Infer;
let info = new;
let res = info.get_from_path;
assert!;
let o = res.unwrap;
assert!;
let typ = o.unwrap;
assert_eq!;
assert_eq!;
Check for specific type
let v = vec!;
assert!;
Check for specific type class
Note individual matcher functions do not require init
let v = vec!;
let info = new;
assert!;
Adds a custom file type matcher
let mut info = new;
info.add;
let v = vec!;
let res = info.get.unwrap;
assert_eq!;
assert_eq!;
Supported types
Image
- jpg -
image/jpeg - png -
image/png - gif -
image/gif - webp -
image/webp - cr2 -
image/x-canon-cr2 - tif -
image/tiff - bmp -
image/bmp - heif -
image/heif - jxr -
image/vnd.ms-photo - psd -
image/vnd.adobe.photoshop - ico -
image/x-icon
Video
- mp4 -
video/mp4 - m4v -
video/x-m4v - mkv -
video/x-matroska - webm -
video/webm - mov -
video/quicktime - avi -
video/x-msvideo - wmv -
video/x-ms-wmv - mpg -
video/mpeg - flv -
video/x-flv
Audio
- mid -
audio/midi - mp3 -
audio/mpeg - m4a -
audio/m4a - ogg -
audio/ogg - flac -
audio/x-flac - wav -
audio/x-wav - amr -
audio/amr - aac -
audio/aac
Archive
- epub -
application/epub+zip - zip -
application/zip - tar -
application/x-tar - rar -
application/x-rar-compressed - gz -
application/gzip - bz2 -
application/x-bzip2 - 7z -
application/x-7z-compressed - xz -
application/x-xz - pdf -
application/pdf - swf -
application/x-shockwave-flash - rtf -
application/rtf - eot -
application/octet-stream - ps -
application/postscript - sqlite -
application/x-sqlite3 - nes -
application/x-nintendo-nes-rom - crx -
application/x-google-chrome-extension - cab -
application/vnd.ms-cab-compressed - deb -
application/x-deb - ar -
application/x-unix-archive - Z -
application/x-compress - lz -
application/x-lzip - rpm -
application/x-rpm - dcm -
application/dicom
Documents
- doc -
application/msword - docx -
application/vnd.openxmlformats-officedocument.wordprocessingml.document - xls -
application/vnd.ms-excel - xlsx -
application/vnd.openxmlformats-officedocument.spreadsheetml.sheet - ppt -
application/vnd.ms-powerpoint - pptx -
application/vnd.openxmlformats-officedocument.presentationml.presentation
Font
- woff -
application/font-woff - woff2 -
application/font-woff - ttf -
application/font-sfnt - otf -
application/font-sfnt
Application
- wasm -
application/wasm - exe -
application/x-msdownload - elf -
application/x-executable - bc -
application/llvm - class -
application/java
Known Issues
doc,ppt,xlsall have the same magic number so it's not possible to tell which one just based on the binary data.docis returned for all.
License
MIT