qlty_cloud/format/
gz.rs

1use super::Formatter;
2use anyhow::Result;
3use flate2::write::GzEncoder;
4use flate2::Compression;
5use std::io::Write;
6
7pub struct GzFormatter {
8    formatter: Box<dyn Formatter>,
9}
10
11impl GzFormatter {
12    pub fn new(formatter: Box<dyn Formatter>) -> Box<dyn Formatter> {
13        Box::new(GzFormatter { formatter })
14    }
15}
16
17impl Formatter for GzFormatter {
18    fn write_to(&self, writer: &mut dyn Write) -> Result<()> {
19        let raw_data = self.formatter.read()?;
20        let mut encoder = GzEncoder::new(writer, Compression::default());
21        encoder.write_all(&raw_data)?;
22        encoder.finish()?;
23        Ok(())
24    }
25}