From 5b6634def6d53f2f439cefcb9bd0005fc474ba32 Mon Sep 17 00:00:00 2001 From: Jiahao XU Date: Tue, 31 May 2022 16:50:55 +1000 Subject: [PATCH] Add new variant `PkgFmt::Tzstd` and update `helpers::extract` Signed-off-by: Jiahao XU --- src/helpers.rs | 20 ++++++++++++++++++++ src/lib.rs | 2 ++ 2 files changed, 22 insertions(+) diff --git a/src/helpers.rs b/src/helpers.rs index 3b6c7505..64647f18 100644 --- a/src/helpers.rs +++ b/src/helpers.rs @@ -9,6 +9,7 @@ use tar::Archive; use tinytemplate::TinyTemplate; use xz2::read::XzDecoder; use zip::read::ZipArchive; +use zstd::stream::Decoder as ZstdDecoder; use crate::Meta; @@ -102,6 +103,25 @@ pub fn extract, P: AsRef>( txz.unpack(path)?; } + PkgFmt::Tzstd => { + // Extract to install dir + debug!( + "Decompressing from tzstd archive '{:?}' to `{:?}`", + source.as_ref(), + path.as_ref() + ); + + let dat = std::fs::File::open(source)?; + + // The error can only come from raw::Decoder::with_dictionary + // as of zstd 0.10.2 and 0.11.2, which is specified + // as &[] by ZstdDecoder::new, thus ZstdDecoder::new + // should not return any error. + let tar = ZstdDecoder::new(dat)?; + let mut txz = Archive::new(tar); + + txz.unpack(path)?; + } PkgFmt::Zip => { // Extract to install dir debug!( diff --git a/src/lib.rs b/src/lib.rs index a5389054..dc7e4569 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -35,6 +35,8 @@ pub enum PkgFmt { Tgz, /// Download format is TAR + XZ Txz, + /// Download format is TAR + Zstd + Tzstd, /// Download format is Zip Zip, /// Download format is raw / binary