file-format

Build Crates.io Docs Rust License

File format library for Rust.

This crate is for determining binary-based file formats.

Example

Determines from a file:

```rust use file_format::FileFormat;

let format = FileFormat::fromfile("fixtures/application/sample.zip").unwrap(); asserteq!(format, FileFormat::Zip); asserteq!(format.name(), "ZIP"); asserteq!(format.mediatype(), "application/zip"); asserteq!(format.extension(), "zip"); ```

Determines from bytes:

```rust use file_format::FileFormat;

let format = FileFormat::frombytes(&[0xFF, 0xD8, 0xFF, 0xEE]); asserteq!(format, FileFormat::JointPhotographicExpertsGroup); asserteq!(format.name(), "Joint Photographic Experts Group"); asserteq!(format.mediatype(), "image/jpeg"); asserteq!(format.extension(), "jpg"); ```

License

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