use std::{fs::File, io::Read};
use serde::{Deserialize, Serialize};
mod format_byte_checks;
pub use format_byte_checks::*;
#[derive(Debug, Clone, Copy, PartialEq, PartialOrd, Ord, Eq, Serialize, Deserialize)]
pub enum ContainerFormat {
Flac,
Mpa,
Ogg,
Wav,
Aiff,
Ape,
}
impl ContainerFormat {
pub fn from_file(handle: &mut File) -> Option<Self> {
let mut buf = [0_u8; 16];
handle.read_exact(&mut buf).ok()?;
let container = if is_flac(&buf) {
ContainerFormat::Flac
} else if is_ogg(&buf) {
ContainerFormat::Ogg
} else if is_mpa(&buf) {
ContainerFormat::Mpa
} else if is_wav(&buf) {
ContainerFormat::Wav
} else if is_aiff(&buf) {
ContainerFormat::Aiff
} else if is_ape(&buf) {
ContainerFormat::Ape
} else {
return None;
};
Some(container)
}
#[must_use]
pub fn format_name(&self) -> &str {
match self {
ContainerFormat::Aiff => "aiff",
ContainerFormat::Ape => "ape",
ContainerFormat::Flac => "flac",
ContainerFormat::Mpa => "mp3",
ContainerFormat::Ogg => "ogg",
ContainerFormat::Wav => "wav",
}
}
}