1use std::path::Path;
2
3use crate::reader::{is_modat_file, is_moflo_file};
4
5#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
7pub enum FileFormat {
8 Modat,
10 Dat,
12 Dax,
14 Modax,
16 Moflo,
18 Csv,
20 Json,
22}
23
24impl FileFormat {
25 pub fn from_path(path: &Path) -> Option<Self> {
26 if is_modat_file(path) {
27 Some(Self::Modat)
28 } else if is_moflo_file(path) {
29 Some(Self::Moflo)
30 } else {
31 path.extension().and_then(|ext| ext.to_str()).and_then(|ext| {
32 match ext.to_ascii_lowercase().as_str() {
33 "dat" => Some(Self::Dat),
34 "dax" => Some(Self::Dax),
35 "modax" => Some(Self::Modax),
36 "csv" => Some(Self::Csv),
37 "json" => Some(Self::Json),
38 _ => None,
39 }
40 })
41 }
42 }
43
44 pub fn extension(self) -> &'static str {
45 match self {
46 Self::Modat => "modat",
47 Self::Dat => "dat",
48 Self::Dax => "dax",
49 Self::Modax => "modax",
50 Self::Moflo => "moflo",
51 Self::Csv => "csv",
52 Self::Json => "json",
53 }
54 }
55
56 pub fn is_readable(self) -> bool {
57 matches!(self, Self::Modat | Self::Dat | Self::Dax | Self::Modax | Self::Moflo)
58 }
59
60 pub fn is_writable(self) -> bool {
61 matches!(self, Self::Modat | Self::Csv | Self::Json)
62 }
63
64 pub fn is_waveform(self) -> bool {
65 matches!(self, Self::Modat | Self::Dat | Self::Dax | Self::Modax)
66 }
67}