Skip to content

Commit

Permalink
Use a multi-threaded xz encoder
Browse files Browse the repository at this point in the history
  • Loading branch information
alexcrichton committed Jun 26, 2019
1 parent 5ba3d18 commit d12ad87
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ rayon = "1.0"
tar = "0.4.13"
walkdir = "2"
xz2 = "0.1.4"
num_cpus = "1"

[dependencies.clap]
features = ["yaml"]
Expand Down
6 changes: 5 additions & 1 deletion src/tarballer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,11 @@ impl Tarballer {
let gz = GzEncoder::new(create_new_file(tar_gz)?, flate2::Compression::best());

// Prepare the `.tar.xz` file.
let xz = XzEncoder::new(create_new_file(tar_xz)?, 6);
let stream = xz2::stream::MtStreamBuilder::new()
.threads(num_cpus::get() as u32)
.preset(6)
.encoder()?;
let xz = XzEncoder::new_stream(create_new_file(tar_xz)?, stream);

// Write the tar into both encoded files. We write all directories
// first, so files may be directly created. (See rust-lang/rustup.rs#1092.)
Expand Down

0 comments on commit d12ad87

Please sign in to comment.