Skip to content

Commit 868b5bf

Browse files
authored
refactor: change miniz_oxide to flate2 with zlib-rs backend (#71)
Reason for change: * unify deflate usage across our tools * consistent behaviour * reduce compilation size * reason for switching from miniz_oxide to zlib-rs: * flate2 uses simd-adler32 https://github.com/rust-lang/flate2-rs/releases/tag/1.1.3 * simd-adler32 breaks on wasm: ``` error[E0433]: failed to resolve: use of unresolved module or unlinked crate `std` --> /home/runner/.cargo/registry/src/index.crates.io-1949cf8c6b5b557f/simd-adler32-0.3.7/src/imp/wasm.rs:146:34 | 146 | let arr: [u32; 4] = unsafe { std::mem::transmute(v) }; | ^^^ use of unresolved module or unlinked crate `std` | = help: if you wanted to use a crate named `std`, use `cargo add std` to add it to your `Cargo.toml` help: consider importing this module | 27 + use core::mem; | help: if you import `mem`, refer to it directly | 146 - let arr: [u32; 4] = unsafe { std::mem::transmute(v) }; 146 + let arr: [u32; 4] = unsafe { mem::transmute(v) }; | ```
1 parent 27b48fc commit 868b5bf

File tree

3 files changed

+50
-4
lines changed

3 files changed

+50
-4
lines changed

Cargo.lock

Lines changed: 43 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ repository = "https://github.com/yarnpkg/pnp-rs"
1111
byteorder = "1"
1212
concurrent_lru = "^0.2"
1313
fancy-regex = { version = "^0.16.2", default-features = false, features = ["std"] }
14-
miniz_oxide = "^0.8"
14+
flate2 = { version = "1.1", default-features = false, features = ["zlib-rs"] }
1515
mmap-rs = { version = "^0.7.0", optional = true }
1616
pathdiff = "^0.2"
1717
radix_trie = "0.3.0"

src/zip.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ use std::{
44
};
55

66
use byteorder::{LittleEndian, ReadBytesExt};
7+
use flate2::read::DeflateDecoder;
78
use rustc_hash::{FxHashMap, FxHashSet};
89

910
use crate::fs::FileType;
@@ -80,8 +81,11 @@ where
8081

8182
match entry.compression {
8283
Compression::Deflate => {
83-
let decompressed_data = miniz_oxide::inflate::decompress_to_vec(slice)
84-
.map_err(|_| std::io::Error::other("Error during decompression"))?;
84+
let mut decoder = DeflateDecoder::new(slice);
85+
let mut decompressed_data = Vec::new();
86+
decoder.read_to_end(&mut decompressed_data).map_err(|e| {
87+
std::io::Error::other(format!("Error during decompression: {e}"))
88+
})?;
8589

8690
Ok(decompressed_data)
8791
}

0 commit comments

Comments
 (0)