Add new variant PkgFmt::Tzstd and update helpers::extract

Signed-off-by: Jiahao XU <Jiahao_XU@outlook.com>
This commit is contained in:
Jiahao XU 2022-05-31 16:50:55 +10:00
parent f555c75e23
commit 5b6634def6
No known key found for this signature in database
GPG key ID: 591C0B03040416D6
2 changed files with 22 additions and 0 deletions

View file

@ -9,6 +9,7 @@ use tar::Archive;
use tinytemplate::TinyTemplate; use tinytemplate::TinyTemplate;
use xz2::read::XzDecoder; use xz2::read::XzDecoder;
use zip::read::ZipArchive; use zip::read::ZipArchive;
use zstd::stream::Decoder as ZstdDecoder;
use crate::Meta; use crate::Meta;
@ -102,6 +103,25 @@ pub fn extract<S: AsRef<Path>, P: AsRef<Path>>(
txz.unpack(path)?; 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 => { PkgFmt::Zip => {
// Extract to install dir // Extract to install dir
debug!( debug!(

View file

@ -35,6 +35,8 @@ pub enum PkgFmt {
Tgz, Tgz,
/// Download format is TAR + XZ /// Download format is TAR + XZ
Txz, Txz,
/// Download format is TAR + Zstd
Tzstd,
/// Download format is Zip /// Download format is Zip
Zip, Zip,
/// Download format is raw / binary /// Download format is raw / binary