molframe_core/io/input/compression.rs
1//! Compression-container recognition by magic bytes.
2
3/// How a stream of bytes was compressed.
4#[derive(Clone, Copy, PartialEq, Eq, Debug)]
5#[non_exhaustive]
6pub enum Compression {
7 /// Not compressed.
8 None,
9 /// Gzip.
10 Gzip,
11 /// Zstandard.
12 Zstd,
13}
14
15impl Compression {
16 /// Recognises a container without consulting its file name.
17 #[must_use]
18 #[inline]
19 pub fn sniff(bytes: &[u8]) -> Self {
20 match bytes {
21 [0x1f, 0x8b, ..] => Self::Gzip,
22 [0x28, 0xb5, 0x2f, 0xfd, ..] => Self::Zstd,
23 _ => Self::None,
24 }
25 }
26}