file-format

Build Crates.io Docs Rust License

File format library for Rust.

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

Examples

Determines from a file:

```rust use file_format::FileFormat;

let format = FileFormat::fromfile("fixtures/image/sample.jpg").unwrap(); asserteq!(format, FileFormat::Jpeg); asserteq!(format.mediatype(), "image/jpeg"); asserteq!(format.preferredextension(), "jpg"); ```

Determines from bytes:

```rust use file_format::FileFormat;

let format = FileFormat::frombytes("Hello 😊!".asbytes()); asserteq!(format, FileFormat::Text); asserteq!(format.mediatype(), "text/plain"); asserteq!(format.preferred_extension(), "txt"); ```

Determines from an extension:

```rust use file_format::FileFormat;

let format = FileFormat::fromextension("vcf"); asserteq!(format, Some(FileFormat::VCard)); ```

Determines from a media type:

```rust use file_format::FileFormat;

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

References

License

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