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

Support LZMA compression method #41

Merged
merged 15 commits into from
Jan 26, 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
1 change: 1 addition & 0 deletions .direnv/flake-profile
1 change: 1 addition & 0 deletions .direnv/flake-profile-1-link
1 change: 1 addition & 0 deletions .envrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
use flake
3 changes: 3 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"rust-analyzer.cargo.features": ["default", "lzma"]
}
143 changes: 136 additions & 7 deletions Cargo.lock

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

5 changes: 5 additions & 0 deletions crates/jean/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,8 @@ humansize = "2.1.3"
positioned-io.workspace = true
indicatif = "0.17.7"
tracing-subscriber = "0.3.18"

[features]
default = ["lzma"]
deflate = ["rc-zip/deflate"]
lzma = ["rc-zip/lzma"]
7 changes: 7 additions & 0 deletions crates/rc-zip/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,16 @@ thiserror = "1.0.56"
chardetng = "0.1.17"
flate2 = { version = "1.0.28", optional = true }
num_enum = "0.7.2"
byteorder = "1.5.0"
cfg-if = "1.0.0"
lzma-rs = { version = "0.3.0", features = ["stream"], optional = true }

[features]
default = ["sync", "file", "deflate"]
sync = []
file = ["positioned-io"]
deflate = ["flate2"]
lzma = ["lzma-rs"]

[dev-dependencies]
tracing-test = "0.2.4"
29 changes: 26 additions & 3 deletions crates/rc-zip/src/error.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
use crate::Method;

use super::encoding;

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

impl Error {
#[allow(unused)]
pub(crate) fn method_not_supported(method: Method) -> Self {
Self::Unsupported(UnsupportedError::MethodNotSupported(method))
}

#[allow(unused)]
pub(crate) fn method_not_enabled(method: Method) -> Self {
Self::Unsupported(UnsupportedError::MethodNotEnabled(method))
}
}

#[derive(Debug, thiserror::Error)]
pub enum UnsupportedError {
#[error("unsupported compression method: {0:?}")]
UnsupportedCompressionMethod(crate::format::Method),
#[error("compression method not supported: {0:?}")]
MethodNotSupported(crate::format::Method),

#[error("compression method supported, but not enabled in this build: {0:?}")]
CompressionMethodNotEnabled(crate::format::Method),
MethodNotEnabled(crate::format::Method),

#[error("only LZMA2.0 is supported, found LZMA{minor}.{major}")]
LzmaVersionUnsupported { minor: u8, major: u8 },
#[error("LZMA properties header wrong size: expected {expected} bytes, got {actual} bytes")]
LzmaPropertiesHeaderWrongSize { expected: u16, actual: u16 },
}

/// Specific zip format errors, mostly due to invalid zip archives but that could also stem from
Expand Down Expand Up @@ -93,6 +113,9 @@ pub enum FormatError {
/// The CRC-32 checksum didn't match.
#[error("checksum didn't match: expected {expected:x?}, got {actual:x?}")]
WrongChecksum { expected: u32, actual: u32 },

#[error("lzma properties larger than max")]
LzmaPropertiesLargerThanMax,
}

impl From<Error> for std::io::Error {
Expand Down
4 changes: 3 additions & 1 deletion crates/rc-zip/src/format/archive.rs
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,9 @@ pub struct StoredEntry {
///
/// In the zip format, the most noteworthy flag (bit 11) is for UTF-8 names.
/// Other flags can indicate: encryption (unsupported), various compression
/// settings (depending on the [Method][] used).
/// settings (depending on the [Method] used).
///
/// For LZMA, general-purpose bit 1 denotes the EOS marker.
pub flags: u16,

/// Unix user ID
Expand Down
17 changes: 0 additions & 17 deletions crates/rc-zip/src/reader/sync/decoder.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
#[cfg(feature = "deflate")]
use flate2::read::DeflateDecoder;

use std::{cmp, io};

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

#[cfg(feature = "deflate")]
impl<R> Decoder<R> for DeflateDecoder<R>
where
R: io::Read,
{
fn into_inner(self: Box<Self>) -> R {
DeflateDecoder::into_inner(*self)
}

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

pub struct StoreDecoder<R>
where
R: io::Read,
Expand Down
Loading
Loading