File Type is a library that uses file signatures and file extensions to determine the type of file.
Signature, extension and media type data are provided by:
If you need a format that is not supported, please provide your submission to the PRONOM database and include the reference id when opening a feature request for this project.
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? |
---|---|---|
custom |
Enables custom file types | Yes |
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 |
These crates use #![forbid(unsafe_code)]
to ensure everything is implemented in 100% safe Rust.
Licensed under either of
- Apache License, Version 2.0, (LICENSE-APACHE or https://www.apache.org/licenses/LICENSE-2.0)
- MIT license (LICENSE-MIT or https://opensource.org/licenses/MIT)
Data is licensed under the following licenses:
- The HTTPD definitions are provided by the Apache Software Foundation under the Apache License 2.0.
- The IANA definitions are provided by the Internet Assigned Numbers Authority under the Creative Commons Zero (CC0) license.
- The PRONOM definitions are provided by The National Archives (UK) under the Open Government Licence.
- The Wikidata definitions are provided by the Wikidata project under the Creative Commons Zero (CC0) license.
If this crate does not meet your requirements, you may want to consider the following alternatives:
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.