diff options
author | rabite <rabite@posteo.de> | 2019-05-28 01:47:32 +0200 |
---|---|---|
committer | rabite <rabite@posteo.de> | 2019-05-28 01:50:02 +0200 |
commit | be7cae58755fe9df87e59c60dbffdfafb28c8a6c (patch) | |
tree | 4dff30e4653c44c9f642ab4500a150bbbeb33866 /src/files.rs | |
parent | 2a2fc2bc6df906554b8899641fd197d6354cf972 (diff) |
improved mime detection for extension-less files
Diffstat (limited to 'src/files.rs')
-rw-r--r-- | src/files.rs | 8 |
1 files changed, 6 insertions, 2 deletions
diff --git a/src/files.rs b/src/files.rs index 25e3393..80bbb7b 100644 --- a/src/files.rs +++ b/src/files.rs @@ -6,6 +6,7 @@ use std::path::{Path, PathBuf}; use std::sync::{Arc, Mutex, RwLock}; use std::sync::mpsc::Sender; use std::hash::{Hash, Hasher}; +use std::str::FromStr; use lscolors::LsColors; use tree_magic; @@ -836,11 +837,14 @@ impl File { if let Some(ext) = self.path.extension() { let mime = mime_guess::get_mime_type(&ext.to_string_lossy()); Some(mime) - } else { None } + } else { + let mime = tree_magic::from_filepath(&self.path); + mime::Mime::from_str(&mime).ok() + } } pub fn is_text(&self) -> bool { - tree_magic::match_filepath("text/plain", &self.path) + tree_magic::match_filepath("text/plain", &self.path) } |