mithril_common/entities/
compression_algorithm.rs

1use serde::{Deserialize, Serialize};
2use strum::{Display, EnumIter, IntoEnumIterator};
3
4/// Compression algorithm for the snapshot archive artifacts.
5#[derive(
6    Debug,
7    Clone,
8    Copy,
9    Serialize,
10    Deserialize,
11    PartialEq,
12    Eq,
13    PartialOrd,
14    Ord,
15    Default,
16    EnumIter,
17    Display,
18)]
19#[serde(rename_all = "lowercase")]
20pub enum CompressionAlgorithm {
21    /// Gzip compression format
22    #[default]
23    Gzip,
24    /// Zstandard compression format
25    Zstandard,
26}
27
28impl CompressionAlgorithm {
29    /// Get the extension associated to tar archive using the current algorithm.
30    pub fn tar_file_extension(&self) -> String {
31        match self {
32            CompressionAlgorithm::Gzip => "tar.gz".to_owned(),
33            CompressionAlgorithm::Zstandard => "tar.zst".to_owned(),
34        }
35    }
36
37    /// List all the available [algorithms][CompressionAlgorithm].
38    pub fn list() -> Vec<Self> {
39        Self::iter().collect()
40    }
41
42    /// Those ratio will be multiplied by the snapshot size to check if the available
43    /// disk space is sufficient to store the archive plus the extracted files.
44    /// If the available space is lower than that, a warning is raised.
45    /// Those ratio have been experimentally established.
46    pub fn free_space_snapshot_ratio(&self) -> f64 {
47        match self {
48            CompressionAlgorithm::Gzip => 2.5,
49            CompressionAlgorithm::Zstandard => 4.0,
50        }
51    }
52}