mirror of
https://codeberg.org/unspeaker/perch.git
synced 2025-12-06 09:36:42 +01:00
refactor: extract constants
This commit is contained in:
parent
84f183ab84
commit
36423fc994
7 changed files with 65 additions and 52 deletions
|
|
@ -20,11 +20,6 @@ pub struct Entry {
|
|||
}
|
||||
|
||||
impl Entry {
|
||||
pub const ICON_DIRECTORY: &'static str = "";
|
||||
pub const ICON_IMAGE: &'static str = "";
|
||||
pub const ICON_MUSIC: &'static str = "";
|
||||
pub const ICON_MUSIC_NO_META: &'static str = "";
|
||||
pub const ICON_UNKNOWN: &'static str = "";
|
||||
pub fn new (root: &impl AsRef<Path>, path: &impl AsRef<Path>, depth: usize) -> Perhaps<Self> {
|
||||
let path = path.as_ref();
|
||||
if path.is_dir() {
|
||||
|
|
@ -71,13 +66,13 @@ impl Entry {
|
|||
}
|
||||
fn icon (&self) -> &'static str {
|
||||
if self.is_directory() {
|
||||
Self::ICON_DIRECTORY
|
||||
ICON_DIRECTORY
|
||||
} else if self.is_image() {
|
||||
Self::ICON_IMAGE
|
||||
ICON_IMAGE
|
||||
} else if self.is_music() {
|
||||
Self::ICON_MUSIC
|
||||
ICON_MUSIC
|
||||
} else {
|
||||
Self::ICON_UNKNOWN
|
||||
ICON_UNKNOWN
|
||||
}
|
||||
}
|
||||
pub fn is_modified (&self) -> bool {
|
||||
|
|
@ -156,7 +151,7 @@ impl Metadata {
|
|||
let mut bytes = vec![0;16];
|
||||
reader.read(&mut bytes)?;
|
||||
// PNG
|
||||
if bytes.starts_with(&[0x89, b'P', b'N', b'G', 0x0D, 0x0A, 0x1A, 0x0A]) {
|
||||
if bytes.starts_with(MAGIC_PNG) {
|
||||
let mut bytes = vec![];
|
||||
BufReader::new(File::open(path)?).read(&mut bytes)?;
|
||||
return Ok(Self::Image {
|
||||
|
|
@ -168,12 +163,10 @@ impl Metadata {
|
|||
})
|
||||
}
|
||||
// JPG
|
||||
if bytes.starts_with(&[0xFF, 0xD8, 0xFF, 0xDB])
|
||||
|| bytes.starts_with(&[0xFF, 0xD8, 0xFF, 0xE0,
|
||||
0x00, 0x10, 0x4A, 0x46,
|
||||
0x49, 0x46, 0x00, 0x01])
|
||||
|| bytes.starts_with(&[0xFF, 0xD8, 0xFF, 0xEE])
|
||||
|| (bytes.starts_with(&[0xFF, 0xD8, 0xFF, 0xE1]) &&
|
||||
if bytes.starts_with(MAGIC_JPG_1)
|
||||
|| bytes.starts_with(MAGIC_JPG_2)
|
||||
|| bytes.starts_with(MAGIC_JPG_3)
|
||||
|| (bytes.starts_with(MAGIC_JPG_4A) &&
|
||||
bytes.get(6) == Some(&0x45) && bytes.get(7) == Some(&0x78) &&
|
||||
bytes.get(8) == Some(&0x69) && bytes.get(9) == Some(&0x66) &&
|
||||
bytes.get(10) == Some(&0x00) && bytes.get(11) == Some(&0x00))
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue