]>
git.proxmox.com Git - proxmox-backup.git/blob - src/tools/compression.rs
1 use anyhow
::{bail, Error}
;
4 /// Possible Compression Methods, order determines preference (later is preferred)
5 #[derive(Eq, Ord, PartialEq, PartialOrd, Debug)]
6 pub enum CompressionMethod
{
12 impl CompressionMethod
{
13 pub fn content_encoding(&self) -> header
::HeaderValue
{
14 header
::HeaderValue
::from_static(self.extension())
17 pub fn extension(&self) -> &'
static str {
19 // CompressionMethod::Brotli => "br",
20 // CompressionMethod::Gzip => "gzip",
21 CompressionMethod
::Deflate
=> "deflate",
26 impl std
::str::FromStr
for CompressionMethod
{
29 fn from_str(s
: &str) -> Result
<Self, Self::Err
> {
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"),