Crates.io | file_type |
lib.rs | file_type |
version | 0.8.9 |
created_at | 2025-01-02 20:24:35.846982+00 |
updated_at | 2025-08-18 19:40:12.414725+00 |
description | File type detector |
homepage | |
repository | https://github.com/theseus-rs/file-type |
max_upload_size | |
id | 1501844 |
size | 23,016,312 |
File types are determined by examining a file or bytes against known file signatures and file extensions.
Signature, extension and media type data are provided by:
Detect the file type from bytes:
use file_type::FileType;
let file_type = FileType::from_bytes(b"\xCA\xFE\xBA\xBE");
assert_eq!(file_type.extensions(), vec!["class"]);
Retrieve a file type from an extension:
use file_type::FileType;
let file_types = FileType::from_extension("png");
let file_type = file_types.first().expect("file format");
assert_eq!(file_type.media_types(), vec!["image/png"]);
Retrieve a file type from a media type:
use file_type::FileType;
let file_types = FileType::from_media_type("image/png");
let file_type = file_types.first().expect("file format");
assert_eq!(file_type.extensions(), vec!["png"]);
Name | Description | Default? |
---|---|---|
httpd |
Enables Apache HTTPD file types | No |
iana |
Enables IANA file types | No |
linguist |
Enables Linguist file types | No |
pronom |
Enables PRONOM file types | No |
std |
Enables support for the Rust standard library | Yes |
wikidata |
Enables Wikidata file types | Yes |
This crate uses #![forbid(unsafe_code)]
to ensure everything is implemented in 100% safe Rust.
Licensed under either of
Data is licensed under the following licenses:
Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.