Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Add bzip2 support #48

Merged
merged 2 commits into from
Jan 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ jobs:
- name: Install Rust specified toolchain
run: rustup show
- name: Run sccache-cache
uses: mozilla-actions/[email protected].3
uses: mozilla-actions/[email protected].4
- name: Install just, nextest, cargo-llvm-cov, and cargo-hack
uses: taiki-e/install-action@v2
with:
Expand Down Expand Up @@ -58,7 +58,7 @@ jobs:
- name: Install Rust specified toolchain
run: rustup show
- name: Run sccache-cache
uses: mozilla-actions/[email protected].3
uses: mozilla-actions/[email protected].4
- name: Install cargo-nextest
uses: taiki-e/install-action@v2
with:
Expand All @@ -81,7 +81,7 @@ jobs:
- name: Install Rust specified toolchain
run: rustup show
- name: Run sccache-cache
uses: mozilla-actions/[email protected].3
uses: mozilla-actions/[email protected].4
- name: Install cargo-nextest
uses: taiki-e/install-action@v2
with:
Expand Down
2 changes: 1 addition & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{
"rust-analyzer.cargo.features": ["default", "lzma", "deflate64"]
"rust-analyzer.cargo.features": ["default", "lzma", "deflate64", "bzip2"]
}
28 changes: 28 additions & 0 deletions Cargo.lock

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

2 changes: 2 additions & 0 deletions crates/rc-zip/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ byteorder = "1.5.0"
cfg-if = "1.0.0"
lzma-rs = { version = "0.3.0", features = ["stream"], optional = true }
deflate64 = { version = "0.1.7", optional = true }
bzip2 = { version = "0.4.4", optional = true }

[features]
default = ["sync", "file", "deflate"]
Expand All @@ -37,6 +38,7 @@ file = ["positioned-io"]
deflate = ["dep:flate2"]
deflate64 = ["dep:deflate64"]
lzma = ["dep:lzma-rs"]
bzip2 = ["dep:bzip2"]

[dev-dependencies]
tracing-test = "0.2.4"
22 changes: 22 additions & 0 deletions crates/rc-zip/src/reader/sync/entry_reader/bzip2_dec.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
use std::io::Read;

use bzip2::read::BzDecoder;

use crate::reader::sync::{Decoder, LimitedReader};

impl<R> Decoder<R> for BzDecoder<R>
where
R: Read,
{
fn into_inner(self: Box<Self>) -> R {
Self::into_inner(*self)
}

fn get_mut(&mut self) -> &mut R {
Self::get_mut(self)
}
}

pub(crate) fn mk_decoder(r: LimitedReader) -> impl Decoder<LimitedReader> {
BzDecoder::new(r)
}
12 changes: 12 additions & 0 deletions crates/rc-zip/src/reader/sync/entry_reader/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ mod deflate_dec;
#[cfg(feature = "deflate64")]
mod deflate64_dec;

#[cfg(feature = "bzip2")]
mod bzip2_dec;

use cfg_if::cfg_if;
use nom::Offset;
use oval::Buffer;
Expand Down Expand Up @@ -297,6 +300,15 @@ where
}
}
}
Method::Bzip2 => {
cfg_if! {
if #[cfg(feature = "bzip2")] {
Box::new(bzip2_dec::mk_decoder(limited_reader))
} else {
return Err(Error::method_not_enabled(self.method));
}
}
}
method => {
return Err(Error::method_not_supported(method));
}
Expand Down
13 changes: 13 additions & 0 deletions crates/rc-zip/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -296,6 +296,19 @@ fn test_cases() -> Vec<ZipTest> {
}],
..Default::default()
},
// same with bzip2
#[cfg(feature = "bzip2")]
ZipTest {
source: ZipSource::File("found-me-bzip2.zip"),
expected_encoding: Some(Encoding::Utf8),
files: vec![ZipTestFile {
name: "found-me.txt",
content: FileContent::Bytes("Oh no, you found me\n".repeat(5000).into()),
modified: Some(date((2024, 1, 26), (17, 14, 36), 0, time_zone(0)).unwrap()),
..Default::default()
}],
..Default::default()
},
]
}

Expand Down