use std::fs;
use std::io::{self, Read};
use std::path::{Path, PathBuf};
use flate2::{Compression, write::GzEncoder};
fn compress_file_to_svgz(filepath: &Path) -> io::Result<()> {
let svgz_filepath = format!("{}z", filepath.display());
let file = fs::File::open(filepath)?;
let reader = io::BufReader::new(file);
let file = fs::File::create(&svgz_filepath)?;
let mut encoder = GzEncoder::new(file, Compression::best());
io::copy(&mut reader.take(u64::MAX), &mut encoder)?;
encoder.finish()?;
fs::remove_file(filepath)?;
Ok(())
}
pub fn compress_to_svgz(files: &[PathBuf]) -> io::Result<()> {
for file in files {
compress_file_to_svgz(file)?
}
Ok(())
}