Skip to content

Commit 1190714

Browse files
committed
compression: Add support for ZStd compression
If the manifest contains zst_tar and zst_hash then treat them as ZStd compressed data. Signed-off-by: Daniel Silverstone <dsilvers@digital-scurf.org>
1 parent 432379b commit 1190714

File tree

3 files changed

+51
-3
lines changed

3 files changed

+51
-3
lines changed

src/dist/component/package.rs

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -572,3 +572,39 @@ impl<'a> Package for TarXzPackage<'a> {
572572
self.0.components()
573573
}
574574
}
575+
576+
#[derive(Debug)]
577+
pub struct TarZStdPackage<'a>(TarPackage<'a>);
578+
579+
impl<'a> TarZStdPackage<'a> {
580+
pub fn new<R: Read>(
581+
stream: R,
582+
temp_cfg: &'a temp::Cfg,
583+
notify_handler: Option<&'a dyn Fn(Notification<'_>)>,
584+
) -> Result<Self> {
585+
let stream = zstd::stream::read::Decoder::new(stream)?;
586+
Ok(TarZStdPackage(TarPackage::new(
587+
stream,
588+
temp_cfg,
589+
notify_handler,
590+
)?))
591+
}
592+
}
593+
594+
impl<'a> Package for TarZStdPackage<'a> {
595+
fn contains(&self, component: &str, short_name: Option<&str>) -> bool {
596+
self.0.contains(component, short_name)
597+
}
598+
fn install<'b>(
599+
&self,
600+
target: &Components,
601+
component: &str,
602+
short_name: Option<&str>,
603+
tx: Transaction<'b>,
604+
) -> Result<Transaction<'b>> {
605+
self.0.install(target, component, short_name, tx)
606+
}
607+
fn components(&self) -> Vec<String> {
608+
self.0.components()
609+
}
610+
}

src/dist/manifest.rs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,18 +55,23 @@ pub struct TargetedPackage {
5555
pub enum CompressionKind {
5656
GZip,
5757
XZ,
58+
ZStd,
5859
}
5960

6061
/// Each compression kind, in order of preference for use, from most desirable
6162
/// to least desirable.
62-
static COMPRESSION_KIND_PREFERENCE_ORDER: &[CompressionKind] =
63-
&[CompressionKind::XZ, CompressionKind::GZip];
63+
static COMPRESSION_KIND_PREFERENCE_ORDER: &[CompressionKind] = &[
64+
CompressionKind::ZStd,
65+
CompressionKind::XZ,
66+
CompressionKind::GZip,
67+
];
6468

6569
impl CompressionKind {
6670
const fn key_prefix(self) -> &'static str {
6771
match self {
6872
Self::GZip => "",
6973
Self::XZ => "xz_",
74+
Self::ZStd => "zst_",
7075
}
7176
}
7277
}

src/dist/manifestation.rs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,9 @@ use retry::delay::NoDelay;
77
use retry::{retry, OperationResult};
88

99
use crate::config::PgpPublicKey;
10-
use crate::dist::component::{Components, Package, TarGzPackage, TarXzPackage, Transaction};
10+
use crate::dist::component::{
11+
Components, Package, TarGzPackage, TarXzPackage, TarZStdPackage, Transaction,
12+
};
1113
use crate::dist::config::Config;
1214
use crate::dist::dist::{Profile, TargetTriple, DEFAULT_DIST_SERVER};
1315
use crate::dist::download::{DownloadCfg, File};
@@ -238,6 +240,7 @@ impl Manifestation {
238240
};
239241
let gz;
240242
let xz;
243+
let zst;
241244
let reader =
242245
utils::FileReaderWithProgress::new_file(&installer_file, &notification_converter)?;
243246
let package: &dyn Package = match format {
@@ -249,6 +252,10 @@ impl Manifestation {
249252
xz = TarXzPackage::new(reader, temp_cfg, Some(&notification_converter))?;
250253
&xz
251254
}
255+
CompressionKind::ZStd => {
256+
zst = TarZStdPackage::new(reader, temp_cfg, Some(&notification_converter))?;
257+
&zst
258+
}
252259
};
253260

254261
// If the package doesn't contain the component that the

0 commit comments

Comments
 (0)