]> git.proxmox.com Git - proxmox-backup.git/blob - src/tools/compression.rs
move client to pbs-client subcrate
[proxmox-backup.git] / src / tools / compression.rs
1 use anyhow::{bail, Error};
2 use hyper::header;
3
4 /// Possible Compression Methods, order determines preference (later is preferred)
5 #[derive(Eq, Ord, PartialEq, PartialOrd, Debug)]
6 pub enum CompressionMethod {
7 Deflate,
8 // Gzip,
9 // Brotli,
10 }
11
12 impl CompressionMethod {
13 pub fn content_encoding(&self) -> header::HeaderValue {
14 header::HeaderValue::from_static(self.extension())
15 }
16
17 pub fn extension(&self) -> &'static str {
18 match *self {
19 // CompressionMethod::Brotli => "br",
20 // CompressionMethod::Gzip => "gzip",
21 CompressionMethod::Deflate => "deflate",
22 }
23 }
24 }
25
26 impl std::str::FromStr for CompressionMethod {
27 type Err = Error;
28
29 fn from_str(s: &str) -> Result<Self, Self::Err> {
30 match s {
31 // "br" => Ok(CompressionMethod::Brotli),
32 // "gzip" => Ok(CompressionMethod::Gzip),
33 "deflate" => Ok(CompressionMethod::Deflate),
34 // http accept-encoding allows to give weights with ';q='
35 other if other.starts_with("deflate;q=") => Ok(CompressionMethod::Deflate),
36 _ => bail!("unknown compression format"),
37 }
38 }
39 }