use flate2::write::GzEncoder;
use flate2::Compression;
use std::io;
use std::io::Write;

pub fn compress_to_gzip(data: &[u8]) -> io::Result<Vec<u8>> {
    let mut encoder = GzEncoder::new(Vec::new(), Compression::default());
    encoder.write_all(data)?;
    encoder.finish()
}
#[derive(Clone, Debug)]
pub enum Encoding {
    Gzip,
    Deflate,
    Br,
    Bzip2,
    None,
}
impl Encoding {
    pub fn from(s: &str) -> Encoding {
        match s.to_lowercase().as_str() {
            x if x.contains("gzip") => Encoding::Gzip,
            x if x.contains("deflate") => Encoding::Deflate,
            x if x.contains("br") => Encoding::Br,
            x if x.contains("bzip2") => Encoding::Bzip2,
            _ => Encoding::None,
        }
    }
    pub fn str(&mut self) -> &str {
        match self {
            Encoding::Gzip => "gzip",
            Encoding::Deflate => "deflate",
            Encoding::Br => "br",
            Encoding::None => "",
            Encoding::Bzip2 => "bzip2",
        }
    }
}
