From 5a43ee2681ea1df7457bdd046eb9169f4ef320f0 Mon Sep 17 00:00:00 2001 From: Jiahao XU Date: Sat, 11 Jun 2022 20:16:41 +1000 Subject: [PATCH] Simplify `extract_compressed_from_readable` impl Signed-off-by: Jiahao XU --- src/helpers/async_extracter.rs | 4 ++-- src/helpers/extracter.rs | 16 ++++++++-------- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/src/helpers/async_extracter.rs b/src/helpers/async_extracter.rs index b592db02..ac84ab16 100644 --- a/src/helpers/async_extracter.rs +++ b/src/helpers/async_extracter.rs @@ -219,7 +219,7 @@ where extract_impl(stream, move |mut rx| { fs::create_dir_all(path.parent().unwrap())?; - extract_compressed_from_readable(ReadableRx::new(&mut rx), fmt.into(), &path, filter) + extract_compressed_from_readable(ReadableRx::new(&mut rx), fmt, &path, filter) }) .await } @@ -239,7 +239,7 @@ where extract_compressed_from_readable:: bool, _>( ReadableRx::new(&mut rx), - fmt.into(), + fmt, &path, None, ) diff --git a/src/helpers/extracter.rs b/src/helpers/extracter.rs index a393c935..cda13ef8 100644 --- a/src/helpers/extracter.rs +++ b/src/helpers/extracter.rs @@ -9,7 +9,7 @@ use xz2::bufread::XzDecoder; use zip::read::ZipArchive; use zstd::stream::Decoder as ZstdDecoder; -use crate::{BinstallError, PkgFmt}; +use crate::{BinstallError, TarBasedFmt}; /// * `filter` - If Some, then it will pass the path of the file to it /// and only extract ones which filter returns `true`. @@ -58,32 +58,34 @@ fn untar bool>( /// is not `PkgFmt::Bin` or `PkgFmt::Zip`. pub(crate) fn extract_compressed_from_readable bool, R: BufRead>( dat: R, - fmt: PkgFmt, + fmt: TarBasedFmt, path: &Path, filter: Option, ) -> Result<(), BinstallError> { + use TarBasedFmt::*; + match fmt { - PkgFmt::Tar => { + Tar => { // Extract to install dir debug!("Extracting from tar archive to `{path:?}`"); untar(dat, path, filter)? } - PkgFmt::Tgz => { + Tgz => { // Extract to install dir debug!("Decompressing from tgz archive to `{path:?}`"); let tar = GzDecoder::new(dat); untar(tar, path, filter)?; } - PkgFmt::Txz => { + Txz => { // Extract to install dir debug!("Decompressing from txz archive to `{path:?}`"); let tar = XzDecoder::new(dat); untar(tar, path, filter)?; } - PkgFmt::Tzstd => { + Tzstd => { // Extract to install dir debug!("Decompressing from tzstd archive to `{path:?}`"); @@ -94,8 +96,6 @@ pub(crate) fn extract_compressed_from_readable bool, R: let tar = ZstdDecoder::with_buffer(dat)?; untar(tar, path, filter)?; } - PkgFmt::Zip => panic!("Unexpected PkgFmt::Zip!"), - PkgFmt::Bin => panic!("Unexpected PkgFmt::Bin!"), }; Ok(())