mimeMIME type detection.
Determine the MIME content type of a file by its path or extension.
Useful for HTTP servers that need to set Content-Type headers.
import std::mime;
fn main() {
let ct = mime.from_path("index.html");
println(ct); // "text/html"
if mime.is_text(ct) {
println("text file");
}
}
from_pathDetect the MIME type from a file path.
Uses the file extension to determine the type. Returns
"application/octet-stream" for unknown extensions.
mime.from_path("photo.jpg") // "image/jpeg"
mime.from_path("style.css") // "text/css"
mime.from_path("data.json") // "application/json"
from_extDetect the MIME type from a file extension (without the dot).
mime.from_ext("html") // "text/html"
mime.from_ext("png") // "image/png"
is_textTest whether a MIME type is a text type (e.g. text/*, application/json).
is_imageTest whether a MIME type is an image type (e.g. image/*).
is_audioTest whether a MIME type is an audio type (e.g. audio/*).
is_videoTest whether a MIME type is a video type (e.g. video/*).