Crate file_format[][src]

Expand description


Build Docs Rust License

File format library for Rust.

This crate is for recognizing the format of a file by checking its signature.


Determines from a file:

use file_format::FileFormat;

let format = FileFormat::from_file("fixtures/image/sample.jpg").unwrap();
assert_eq!(format, FileFormat::Jpeg);
assert_eq!(format.media_type(), "image/jpeg");
assert_eq!(format.preferred_extension(), "jpg");

Determines from bytes:

use file_format::FileFormat;

let format = FileFormat::from_bytes("Hello 😊!".as_bytes());
assert_eq!(format, FileFormat::Text);
assert_eq!(format.media_type(), "text/plain");
assert_eq!(format.preferred_extension(), "txt");

Determines from an extension:

use file_format::FileFormat;

let format = FileFormat::from_extension("vcf");
assert_eq!(format, Some(FileFormat::VCard));

Determines from a media type:

use file_format::FileFormat;

let format = FileFormat::from_media_type("image/vnd.adobe.photoshop");
assert_eq!(format, Some(FileFormat::PhotoshopDocument));



This project is licensed under either of Apache License, Version 2.0 or MIT license at your option.


Represents a file format.