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 0 | 0 | 0 | 0 |
| 0.1.3 | 0 | 0 | 0 | 0 | 0 |
| 0.1.2 | 0 | 0 | 0 | 0 | 0 |
| 0.1.1 | 0 | 0 | 0 | 0 | 0 |
| 0.1.0 | 0 | 0 | 0 | 0 | 0 |
0.19.0 - This version is safe to use because it has no known security vulnerabilities at this time. Find out if your coding project uses this component and get notified of any reported security vulnerabilities with Meterian-X Open Source Security Platform
Maintain your licence declarations and avoid unwanted licences to protect your IP the way you intended.
MIT - MIT LicenseSmall 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).
This crate works with Cargo and is on crates.io.
Add it to your Cargo.toml like so:
[dependencies]
infer = "0.3"If you are not using the custom matcher or the file type from file path functionality you can make this crate even lighter by importing it with no default features, like so:
[dependencies]
infer = { version = "0.3", default-features = false }This crate supports no_std and no_alloc environments. std support is enabled by default,
but you can disable it by importing the crate with no default features, making it depend
only on the Rust core Library.
alloc has to be enabled to be able to use custom file matchers.
std has to be enabled to be able to get the file type from a file given the file path.
Most operations can be done via top level functions, but they are also available through the Infer
struct, which must be used when dealing custom matchers.
let buf = [0xFF, 0xD8, 0xFF, 0xAA];
let kind = infer::get(&buf).expect("file type is known");
assert_eq!(kind.mime_type(), "image/jpeg");
assert_eq!(kind.extension(), "jpg");let kind = infer::get_from_path("testdata/sample.jpg")
.expect("file read successfully")
.expect("file type is known");
assert_eq!(kind.mime_type(), "image/jpeg");
assert_eq!(kind.extension(), "jpg");let buf = [0xFF, 0xD8, 0xFF, 0xAA];
assert!(infer::image::is_jpeg(&buf));let buf = [0xFF, 0xD8, 0xFF, 0xAA];
assert!(infer::is_image(&buf));fn custom_matcher(buf: &[u8]) -> bool {
return buf.len() >= 3 && buf[0] == 0x10 && buf[1] == 0x11 && buf[2] == 0x12;
}
let mut info = infer::Infer::new();
info.add("custom/foo", "foo", custom_matcher);
let buf = [0x10, 0x11, 0x12, 0x13];
let kind = info.get(&buf).expect("file type is known");
assert_eq!(kind.mime_type(), "custom/foo");
assert_eq!(kind.extension(), "foo");image/jpeg
image/png
image/gif
image/webp
image/x-canon-cr2
image/tiff
image/bmp
image/heif
image/avif
image/vnd.ms-photo
image/vnd.adobe.photoshop
image/vnd.microsoft.icon
image/openraster
image/vnd.djvu
video/mp4
video/x-m4v
video/x-matroska
video/webm
video/quicktime
video/x-msvideo
video/x-ms-wmv
video/mpeg
video/x-flv
audio/midi
audio/mpeg
audio/m4a
audio/ogg
audio/x-flac
audio/x-wav
audio/amr
audio/aac
audio/x-aiff
audio/x-dsf
audio/x-ape
application/epub+zip
application/zip
application/x-tar
application/vnd.rar
application/gzip
application/x-bzip2
application/vnd.bzip3
application/x-7z-compressed
application/x-xz
application/pdf
application/x-shockwave-flash
application/rtf
application/octet-stream
application/postscript
application/vnd.sqlite3
application/x-nintendo-nes-rom
application/x-google-chrome-extension
application/vnd.ms-cab-compressed
application/vnd.debian.binary-package
application/x-unix-archive
application/x-compress
application/x-lzip
application/x-rpm
application/dicom
application/zstd
application/x-lz4
application/x-ole-storage
application/x-cpio
application/x-par2
application/epub+zip
application/x-mobipocket-ebook
application/msword
application/vnd.openxmlformats-officedocument.wordprocessingml.document
application/vnd.ms-excel
application/vnd.openxmlformats-officedocument.spreadsheetml.sheet
application/vnd.ms-powerpoint
application/vnd.openxmlformats-officedocument.presentationml.presentation
application/vnd.oasis.opendocument.text
application/vnd.oasis.opendocument.spreadsheet
application/vnd.oasis.opendocument.presentation
application/font-woff
application/font-woff
application/font-sfnt
application/font-sfnt
application/wasm
application/vnd.microsoft.portable-executable
application/vnd.microsoft.portable-executable
application/x-executable
application/llvm
application/x-mach-binary
application/java
application/vnd.android.dex
application/vnd.android.dey
application/x-x509-ca-cert
application/x-executable
application/x-qemu-disk
exe and dll have the same magic number so it's not possible to tell which one just based on the binary data. exe is returned for all.MIT