Crates.io | mime-sniffer |
lib.rs | mime-sniffer |
version | |
source | src |
created_at | 2017-01-04 07:37:36.1385 |
updated_at | 2024-12-01 09:03:29.584068 |
description | Detecting mime types base on content sniffer. |
homepage | https://github.com/flier/rust-mime-sniffer |
repository | https://github.com/flier/rust-mime-sniffer.git |
max_upload_size | |
id | 7916 |
Cargo.toml error: | TOML parse error at line 18, column 1 | 18 | autolib = false | ^^^^^^^ unknown field `autolib`, expected one of `name`, `version`, `edition`, `authors`, `description`, `readme`, `license`, `repository`, `homepage`, `documentation`, `build`, `resolver`, `links`, `default-run`, `default_dash_run`, `rust-version`, `rust_dash_version`, `rust_version`, `license-file`, `license_dash_file`, `license_file`, `licenseFile`, `license_capital_file`, `forced-target`, `forced_dash_target`, `autobins`, `autotests`, `autoexamples`, `autobenches`, `publish`, `metadata`, `keywords`, `categories`, `exclude`, `include` |
size | 0 |
Detecting mime types base on content sniffer.
The detection workflow was copied from Chromium
For more detail, please read How Mozilla determines MIME Types.
To use mime-sniffer
, first add this to your Cargo.toml
:
[dependencies]
mime-sniffer = "^0.1"
Then, add this to your crate root:
extern crate mime_sniffer;
use mime_sniffer::MimeTypeSniffer;
And then, use hash function with module or hasher
use mime_sniffer::MimeTypeSniffer;
assert_eq!(Some("application/pdf"), b"%PDF-1.5".sniff_mime_type());
extern crate url;
#[macro_use]
extern crate mime;
extern crate mime_sniffer;
use url::Url;
use mime_sniffer::{HttpRequest, MimeTypeSniffer, MimeTypeSniffable, MimeTypeSnifferExt};
let url = Url::parse("http://localhost/notes.ppt").unwrap();
let req = HttpRequest {
content: b"\xD0\xCF\x11\xE0\xA1\xB1\x1A\xE1",
url: &url,
type_hint: "text/plain",
};
assert!(req.should_sniff_mime_type());
assert_eq!(req.sniff_mime_type(), Some("application/vnd.ms-powerpoint"));
assert_eq!(req.sniff_mime_type_ext().unwrap().type_(), mime::APPLICATION);