Skip to content

Commit 51cd57a

Browse files
feat: LZMA compression method (#41)
Using lzma-rs, a pure Rust LZMA implementation, because nothing else worked.
1 parent 9ed7f63 commit 51cd57a

19 files changed

+1781
-41
lines changed

.direnv/flake-profile

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
flake-profile-1-link

.direnv/flake-profile-1-link

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/nix/store/bdw4nizg6fg6i13gyi43skk3clwg7fjs-nix-shell-env

.envrc

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
use flake

.vscode/settings.json

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"rust-analyzer.cargo.features": ["default", "lzma"]
3+
}

Cargo.lock

+136-7
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crates/jean/Cargo.toml

+5
Original file line numberDiff line numberDiff line change
@@ -14,3 +14,8 @@ humansize = "2.1.3"
1414
positioned-io.workspace = true
1515
indicatif = "0.17.7"
1616
tracing-subscriber = "0.3.18"
17+
18+
[features]
19+
default = ["lzma"]
20+
deflate = ["rc-zip/deflate"]
21+
lzma = ["rc-zip/lzma"]

crates/rc-zip/Cargo.toml

+7
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,16 @@ thiserror = "1.0.56"
2525
chardetng = "0.1.17"
2626
flate2 = { version = "1.0.28", optional = true }
2727
num_enum = "0.7.2"
28+
byteorder = "1.5.0"
29+
cfg-if = "1.0.0"
30+
lzma-rs = { version = "0.3.0", features = ["stream"], optional = true }
2831

2932
[features]
3033
default = ["sync", "file", "deflate"]
3134
sync = []
3235
file = ["positioned-io"]
3336
deflate = ["flate2"]
37+
lzma = ["lzma-rs"]
38+
39+
[dev-dependencies]
40+
tracing-test = "0.2.4"

crates/rc-zip/src/error.rs

+26-3
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
use crate::Method;
2+
13
use super::encoding;
24

35
/// Any zip-related error, from invalid archives to encoding problems.
@@ -24,12 +26,30 @@ pub enum Error {
2426
UnknownSize,
2527
}
2628

29+
impl Error {
30+
#[allow(unused)]
31+
pub(crate) fn method_not_supported(method: Method) -> Self {
32+
Self::Unsupported(UnsupportedError::MethodNotSupported(method))
33+
}
34+
35+
#[allow(unused)]
36+
pub(crate) fn method_not_enabled(method: Method) -> Self {
37+
Self::Unsupported(UnsupportedError::MethodNotEnabled(method))
38+
}
39+
}
40+
2741
#[derive(Debug, thiserror::Error)]
2842
pub enum UnsupportedError {
29-
#[error("unsupported compression method: {0:?}")]
30-
UnsupportedCompressionMethod(crate::format::Method),
43+
#[error("compression method not supported: {0:?}")]
44+
MethodNotSupported(crate::format::Method),
45+
3146
#[error("compression method supported, but not enabled in this build: {0:?}")]
32-
CompressionMethodNotEnabled(crate::format::Method),
47+
MethodNotEnabled(crate::format::Method),
48+
49+
#[error("only LZMA2.0 is supported, found LZMA{minor}.{major}")]
50+
LzmaVersionUnsupported { minor: u8, major: u8 },
51+
#[error("LZMA properties header wrong size: expected {expected} bytes, got {actual} bytes")]
52+
LzmaPropertiesHeaderWrongSize { expected: u16, actual: u16 },
3353
}
3454

3555
/// Specific zip format errors, mostly due to invalid zip archives but that could also stem from
@@ -93,6 +113,9 @@ pub enum FormatError {
93113
/// The CRC-32 checksum didn't match.
94114
#[error("checksum didn't match: expected {expected:x?}, got {actual:x?}")]
95115
WrongChecksum { expected: u32, actual: u32 },
116+
117+
#[error("lzma properties larger than max")]
118+
LzmaPropertiesLargerThanMax,
96119
}
97120

98121
impl From<Error> for std::io::Error {

crates/rc-zip/src/format/archive.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,9 @@ pub struct StoredEntry {
116116
///
117117
/// In the zip format, the most noteworthy flag (bit 11) is for UTF-8 names.
118118
/// Other flags can indicate: encryption (unsupported), various compression
119-
/// settings (depending on the [Method][] used).
119+
/// settings (depending on the [Method] used).
120+
///
121+
/// For LZMA, general-purpose bit 1 denotes the EOS marker.
120122
pub flags: u16,
121123

122124
/// Unix user ID

crates/rc-zip/src/reader/sync/decoder.rs

-17
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
1-
#[cfg(feature = "deflate")]
2-
use flate2::read::DeflateDecoder;
3-
41
use std::{cmp, io};
52

63
pub trait Decoder<R>: io::Read
@@ -15,20 +12,6 @@ where
1512
fn get_mut(&mut self) -> &mut R;
1613
}
1714

18-
#[cfg(feature = "deflate")]
19-
impl<R> Decoder<R> for DeflateDecoder<R>
20-
where
21-
R: io::Read,
22-
{
23-
fn into_inner(self: Box<Self>) -> R {
24-
DeflateDecoder::into_inner(*self)
25-
}
26-
27-
fn get_mut(&mut self) -> &mut R {
28-
DeflateDecoder::get_mut(self)
29-
}
30-
}
31-
3215
pub struct StoreDecoder<R>
3316
where
3417
R: io::Read,

0 commit comments

Comments
 (0)