use std::path::Path;
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum Format {
Pes,
Dst,
Exp,
Jef,
Vp3,
Pec,
Xxx,
Sew,
}
pub fn detect_from_bytes(data: &[u8]) -> Option<Format> {
if data.len() >= 4 && &data[0..4] == b"#PES" {
return Some(Format::Pes);
}
if data.len() >= 5 && &data[0..5] == b"%vsm%" {
return Some(Format::Vp3);
}
if data.len() >= 8 && &data[0..8] == b"#PEC0001" {
return Some(Format::Pec);
}
None
}
pub fn detect_from_extension(path: &Path) -> Option<Format> {
let ext = path.extension()?.to_str()?;
match ext.to_ascii_lowercase().as_str() {
"pes" => Some(Format::Pes),
"dst" => Some(Format::Dst),
"exp" => Some(Format::Exp),
"jef" => Some(Format::Jef),
"vp3" => Some(Format::Vp3),
"pec" => Some(Format::Pec),
"xxx" => Some(Format::Xxx),
"sew" => Some(Format::Sew),
_ => None,
}
}