ebassi / xdg-mime-rs

Rust crate for querying the shared-mime-info database
Apache License 2.0
14 stars 5 forks source link

Read the MIME cache binary blob #14

Open ebassi opened 4 years ago

ebassi commented 4 years ago

The shared-mime-info database has two representations:

We should add a parser for the mime.cache file, and use it whenever it's available, instead of loading all the other files.

federicomenaquintero commented 4 years ago

You may find the scroll crate useful. It lets you parse a byte buffer with primitives like "read me a big-endian u32 at a given offset", and will return an error if the offset is past the bounds of the byte buffer.

federicomenaquintero commented 4 years ago

Also just found the bytemuck crate to cast between &[u8] and "plain old data" structs. This may allow easy casting to a struct that represents the whole header of a section, and later endian-flipping the fields as appropriate.

sdroege commented 4 years ago

There's also https://github.com/rust-lang/rfcs/pull/2981, which would allow directly casting byte blobs, safely, to structs at some point in the future.

And of course nom if you want to go the normal parsing approach, which can also work zero-copy/zero-heap-allocation.