mirror of
https://github.com/bobwen-dev/hunter
synced 2025-04-12 00:55:41 +02:00
improved mime detection for extension-less files
This commit is contained in:
parent
2a2fc2bc6d
commit
be7cae5875
@ -6,6 +6,7 @@ use std::path::{Path, PathBuf};
|
|||||||
use std::sync::{Arc, Mutex, RwLock};
|
use std::sync::{Arc, Mutex, RwLock};
|
||||||
use std::sync::mpsc::Sender;
|
use std::sync::mpsc::Sender;
|
||||||
use std::hash::{Hash, Hasher};
|
use std::hash::{Hash, Hasher};
|
||||||
|
use std::str::FromStr;
|
||||||
|
|
||||||
use lscolors::LsColors;
|
use lscolors::LsColors;
|
||||||
use tree_magic;
|
use tree_magic;
|
||||||
@ -836,11 +837,14 @@ impl File {
|
|||||||
if let Some(ext) = self.path.extension() {
|
if let Some(ext) = self.path.extension() {
|
||||||
let mime = mime_guess::get_mime_type(&ext.to_string_lossy());
|
let mime = mime_guess::get_mime_type(&ext.to_string_lossy());
|
||||||
Some(mime)
|
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 {
|
pub fn is_text(&self) -> bool {
|
||||||
tree_magic::match_filepath("text/plain", &self.path)
|
tree_magic::match_filepath("text/plain", &self.path)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user