Skip to content

Commit

Permalink
feat: add zstd support
Browse files Browse the repository at this point in the history
  • Loading branch information
eatradish committed Jul 24, 2024
1 parent 3ee44c9 commit b1e9b90
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 0 deletions.
29 changes: 29 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ flate2 = "1.0"
tabwriter = { version = "^1", features = ["ansi_formatting"] }
unsquashfs-wrapper = "0.2"
inotify = "0.10"
zstd = "0.13.2"

[build-dependencies]
clap = { version = "^4", features = ["string", "env"] }
Expand Down
4 changes: 4 additions & 0 deletions src/repo/scan.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ use xz2::read::XzDecoder;
enum TarFormat {
Xzip,
Gzip,
Zstd,
}

fn collect_control<R: Read>(reader: R) -> Result<Vec<u8>> {
Expand All @@ -40,6 +41,7 @@ fn open_compressed_control<R: Read>(reader: R, format: &TarFormat) -> Result<Vec
match format {
TarFormat::Xzip => collect_control(XzDecoder::new(reader)),
TarFormat::Gzip => collect_control(GzDecoder::new(reader)),
TarFormat::Zstd => collect_control(zstd::stream::read::Decoder::new(reader)?),
}
}

Expand All @@ -48,6 +50,8 @@ fn determine_format(format: &[u8]) -> Result<TarFormat> {
Ok(TarFormat::Xzip)
} else if format.ends_with(b".gz") {
Ok(TarFormat::Gzip)
} else if format.ends_with(b".zst") {
Ok(TarFormat::Zstd)
} else {
Err(anyhow!("Unknown format: {:?}", format))
}
Expand Down

0 comments on commit b1e9b90

Please sign in to comment.