use flate2::read::GzDecoder;
use std::{fs::File, path::Path};
use tar::Archive;
use zip::ZipArchive;
pub(crate) enum ArchiveFormat {
TarGz,
Zip,
}
pub(crate) fn extract_archive(
archive_path: &Path,
target_path: &Path,
archive_format: ArchiveFormat,
) -> anyhow::Result<()> {
let file = File::open(archive_path)?;
match archive_format {
ArchiveFormat::TarGz => {
let gz_decoder = GzDecoder::new(file);
let mut archive = Archive::new(gz_decoder);
archive.unpack(target_path)?;
}
ArchiveFormat::Zip => {
let mut archive = ZipArchive::new(file)?;
archive.extract(target_path)?;
}
}
Ok(())
}