Rust

mime

Module

MIME type detection from a file's first bytes.

Contents

use utopia_storage::mime::detect;
Rust
pub fn detect(head: &[u8]) -> &'static str

The MIME type of content starting with head (at least its first SNIFF_LENGTH bytes, or all of it when shorter).

Rust
assert_eq!(utopia_storage::mime::detect(b"\x89PNG\r\n\x1a\n...."), "image/png");
assert_eq!(utopia_storage::mime::detect(b"Hello World\n"), "text/plain");
assert_eq!(utopia_storage::mime::detect(b""), "application/x-empty");
Rust
pub const SNIFF_LENGTH: usize = 8192

How many leading bytes detect looks at.