Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Catalog · How the catalog works

Random project

file-type

File type detector

View on GitHub

Anyone may press Interesting, signed in or not. It helps others find this project.

Member rating

No ratings yet.

Sign in to rate this project.

README

File Type

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 Wikidata and include the reference when opening a feature request for this project.

Getting Started

Detect the file type from bytes:

rust
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:

rust
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:

rust
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"]);

Feature flags

Name Description Default?
httpd Enables Apache HTTPD file types No
iana Enables IANA file types No
linguist Enables Linguist file types No
std Enables support for the Rust standard library Yes
wikidata Enables Wikidata file types Yes

Supported File Types

List of supported file types

Safety

These crates use #![forbid(unsafe_code)] to ensure everything is implemented in 100% safe Rust.

Performance

Comparative performance determining file type from bytes

https://bencher.dev/perf/theseus-rs-file-type?lower_value=false&upper_value=false&lower_boundary=false&upper_boundary=false&x_axis=date_time&branches=e6bda651-ab44-4c6b-8db6-5b495b43ea40&testbeds=4927da7e-2d56-48e6-a579-d78b3787c104&benchmarks=bdf821ff-e1df-478f-923c-6dd28c4509e1%2C709db97a-d220-48b7-996a-2ee7cf2944bd%2Cfa2bef70-dfd4-4834-bbc9-eb3e30af67e5%2C2dc8c116-c6dc-4337-a12e-358b218f67ba&measures=670fcc74-764a-40b6-8cd2-93076b6cc17d&start_time=1736272317659&end_time=1743529917659&tab=plots&plots_search=5c1412b7-4e16-42c0-acb7-9d8c899f6e05&key=true&reports_per_page=4&branches_per_page=8&testbeds_per_page=8&benchmarks_per_page=8&plots_per_page=8&reports_page=1&branches_page=1&testbeds_page=1&benchmarks_page=1&plots_page=1&utm_medium=share&utm_source=bencher&utm_content=img&utm_campaign=perf%2Bimg&utm_term=theseus-rs-file-type

Comparative performance determining file type from extension

https://bencher.dev/perf/theseus-rs-file-type?lower_value=false&upper_value=false&lower_boundary=false&upper_boundary=false&x_axis=date_time&branches=e6bda651-ab44-4c6b-8db6-5b495b43ea40&testbeds=4927da7e-2d56-48e6-a579-d78b3787c104&benchmarks=5ea43253-b368-4799-b6bd-a08556196456%2C2328df4a-c516-403c-bc84-2b7c7ee0a0fa&measures=670fcc74-764a-40b6-8cd2-93076b6cc17d&start_time=1736357094393&tab=plots&plots_search=f1500077-7e42-4ded-b658-8dd1f35205d1&key=true&reports_per_page=4&branches_per_page=8&testbeds_per_page=8&benchmarks_per_page=8&plots_per_page=8&reports_page=1&branches_page=1&testbeds_page=1&benchmarks_page=1&plots_page=1&utm_medium=share&utm_source=bencher&utm_content=img&utm_campaign=perf%2Bimg&utm_term=theseus-rs-file-type

Comparative performance determining file type from media type

https://bencher.dev/perf/theseus-rs-file-type?lower_value=false&upper_value=false&lower_boundary=false&upper_boundary=false&x_axis=date_time&branches=e6bda651-ab44-4c6b-8db6-5b495b43ea40&testbeds=4927da7e-2d56-48e6-a579-d78b3787c104&benchmarks=65468a2b-b06d-4c15-9491-694934dbd036%2C7d89adc9-2bf0-4449-9923-73e1ea4eabd8&measures=670fcc74-764a-40b6-8cd2-93076b6cc17d&start_time=1736357094389&tab=plots&plots_search=f564a523-53a7-491f-a650-7097249dc2cb&key=true&reports_per_page=4&branches_per_page=8&testbeds_per_page=8&benchmarks_per_page=8&plots_per_page=8&reports_page=1&branches_page=1&testbeds_page=1&benchmarks_page=1&plots_page=1&utm_medium=share&utm_source=bencher&utm_content=img&utm_campaign=perf%2Bimg&utm_term=theseus-rs-file-type

License

Licensed under either of

Data is licensed under the following licenses:

Alternatives

If this crate does not meet your requirements, you may want to consider the following alternatives:

Contribution

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.