Skip to content

Commit

Permalink
Merge pull request #77 from axodotdev/zstd
Browse files Browse the repository at this point in the history
fix: actually compress zstd with zstd
  • Loading branch information
Gankra authored Jan 23, 2024
2 parents a23d52e + f34b9f1 commit 5d309ad
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
3 changes: 2 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ json-serde = ["serde_json", "serde"]
toml-edit = ["toml_edit"]
remote = ["reqwest"]
compression = ["compression-tar", "compression-zip"]
compression-tar = ["flate2", "tar", "xz2"]
compression-tar = ["flate2", "tar", "xz2", "zstd"]
compression-zip = ["zip"]

[dependencies]
Expand All @@ -32,6 +32,7 @@ tar = { version = "0.4.38", optional = true }
zip = { version = "0.6.4", optional = true }
flate2 = { version = "1.0.25", optional = true }
xz2 = { version = "0.1.7", optional = true, features = ["static"] }
zstd = { version = "0.13.0", optional = true }
toml_edit = { version = "0.21.0", optional = true }
walkdir = "2.3.3"

Expand Down
10 changes: 8 additions & 2 deletions src/compression.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,10 @@ pub(crate) fn tar_dir(
compression: &CompressionImpl,
) -> crate::error::Result<()> {
use crate::error::*;
use flate2::{write::ZlibEncoder, Compression, GzBuilder};
use flate2::{Compression, GzBuilder};
use std::fs;
use xz2::write::XzEncoder;
use zstd::stream::Encoder as ZstdEncoder;

// Set up the archive/compression
// dir_name here is a prefix directory/path that the src dir's contents will be stored
Expand Down Expand Up @@ -117,7 +118,12 @@ pub(crate) fn tar_dir(
}
CompressionImpl::Zstd => {
// Wrap our file in compression
let zip_output = ZlibEncoder::new(final_zip_file, Compression::default());
let zip_output = ZstdEncoder::new(final_zip_file, 0).map_err(|details| {
AxoassetError::LocalAssetArchive {
reason: format!("failed to create zstd encoder"),
details,
}
})?;

// Write the tar to the compression stream
let mut tar = tar::Builder::new(zip_output);
Expand Down

0 comments on commit 5d309ad

Please sign in to comment.