Crates.io | mimetype |
lib.rs | mimetype |
version | 0.1.6 |
source | src |
created_at | 2024-08-05 09:44:07.646498 |
updated_at | 2024-08-11 03:09:48.142042 |
description | detech mime type from file bytes |
homepage | |
repository | https://github.com/hoslo/mimetype |
max_upload_size | |
id | 1325760 |
size | 108,397 |
Rust version of mimetype
Add this to your Cargo.toml
:
[dependencies]
mimetype = "0.1.6"
Then you can use it like this:
fn main() {
let file = std::fs::read("test.jpg").unwrap();
let mime = mimetype::detect(&file);
println!("{:?}", mime);
}
or use reader
fn main() {
let file = std::fs::File::open("Cargo.toml").unwrap();
let mime = mimetype::detect(&file);
println!("{:?}", mime);
}
Add this to your Cargo.toml
:
[dependencies]
mimetype = { version = "0.1.6", features = ["async"] }
Then you can use it like this:
#[tokio::main]
async fn main() {
let file = tokio::fs::read("test.jpg").await.unwrap();
let mime = mimetype::detect_async(&file).await;
println!("{:?}", mime);
}
or use reader
#[tokio::main]
async fn main() {
let file = tokio::fs::File::open("test.jpg").await.unwrap();
let mime = mimetype::detect_async(&file).await;
println!("{:?}", mime);
}
The output will be like:
Mime { mime: "image/jpeg", aliases: [], extension: ".jpg" }