use std::fs;
use std::io::{self, Read};
use std::path::{Path, PathBuf};
use flate2::{Compression, write::GzEncoder};
pub fn compress_to_svgz(filepath: &Path) -> io::Result<PathBuf> {
let file = fs::File::open(filepath)?;
let reader = io::BufReader::new(file);
let svgz_filepath = filepath.with_extension("svgz");
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(svgz_filepath)
}