28 lines
1.1 KiB
Rust
28 lines
1.1 KiB
Rust
// use xdg_mime::SharedMimeInfo;
|
|
// use std::path::Path;
|
|
// use std::io;
|
|
// use mime_guess::Mime;
|
|
// use std::fs::File;
|
|
// use std::io::Read;
|
|
|
|
// pub fn mime_type(db: &SharedMimeInfo, filepath: &Path) -> io::Result<Option<Mime>, > {
|
|
// // attempt to read up to the 256 bytes of the file
|
|
// let mut buffer = [0; 256];
|
|
// let mut file = File::open(filepath)?;
|
|
//
|
|
// file.read(&mut buffer)?;
|
|
//
|
|
// Ok(db.get_mime_type_for_data(&buffer).map(|m| m.0))
|
|
// }
|
|
|
|
// pub fn get_ext_from_mime(mime: &Mime) -> Option<String> {
|
|
// match mime_guess::get_mime_extensions(mime) // get a list of possible extensions for this mime type
|
|
// .map(|g| g[0]) { // take the first option in the list and return it as a string
|
|
// // jpeg files are given the primary extension "jpe", due to the extension list being stored in alphabetical order.
|
|
// // to handle this particular case, swap "jpe" out for "jpg", and leave everything else the same, making sure we
|
|
// // convert the &strs to Strings.
|
|
// Some("jpe") => Some(String::from("jpg")),
|
|
// Some(ext) => Some(String::from(ext)),
|
|
// None => None
|
|
// }
|
|
// }
|