1pub mod read;
4mod text;
5pub mod write;
6
7use crate::array::npy;
8
9#[derive(Clone, Copy, Debug, Eq, PartialEq)]
11pub enum Format {
12 Npy,
14 Text,
16}
17
18impl Format {
19 fn detect(bytes: &[u8]) -> Option<Self> {
20 Self::detect_npy(bytes).xor(Self::detect_plain_text(bytes))
21 }
22
23 fn detect_npy(bytes: &[u8]) -> Option<Self> {
24 (bytes[..npy::MAGIC.len()] == npy::MAGIC).then_some(Self::Npy)
25 }
26
27 fn detect_plain_text(bytes: &[u8]) -> Option<Self> {
28 (bytes[..text::START.len()] == text::START).then_some(Self::Text)
29 }
30}