Read metadata from a binary file

I am receiving a file in this format
file_content: Vec<u8> = [104, 111, 108, 97, 10 ....]

I want to save the files that meet a rule in the mime/type
The solutions I found is to save first and then extract the mime/type.

Is it possible to extract the mime type before saving it?

Can you show some of the solutions that extract the mime/type from a file?

You might find the magic crate useful. It contains Rust bindings to libmagic, the library behind the file command.

The Cookie::buffer() method will do file type detection based on the contents of a buffer in memory.

1 Like

I found this lib that does what I am looking for https://crates.io/crates/infer

Thank you