diff --git a/Cargo.lock b/Cargo.lock index fa95b94a6..00a2f9f75 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -337,15 +337,6 @@ version = "0.5.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7fb9b38af92608140b86b693604b9ffcc5824240a484d1ecd4795bacb2fe88f3" -[[package]] -name = "lz4_flex" -version = "0.9.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "177c079243f6867429aca5af5053747f57e329d44f0c58bebca078cd14873ec2" -dependencies = [ - "twox-hash", -] - [[package]] name = "lzma-sys" version = "0.1.17" @@ -357,6 +348,15 @@ dependencies = [ "pkg-config", ] +[[package]] +name = "lzzzz" +version = "0.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f6d891cedd3b1659c206a60ff8afd15bccd7c2754b157f8a164861989e042b88" +dependencies = [ + "cc", +] + [[package]] name = "memchr" version = "2.4.1" @@ -411,7 +411,7 @@ dependencies = [ "infer", "libc", "linked-hash-map", - "lz4_flex", + "lzzzz", "once_cell", "parse-display", "proptest", @@ -675,12 +675,6 @@ dependencies = [ "winapi-util", ] -[[package]] -name = "static_assertions" -version = "1.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a2eb9349b6444b326872e140eb1cf5e7c522154d69e7a0ffb0fb81c06b37543f" - [[package]] name = "strsim" version = "0.10.0" @@ -802,16 +796,6 @@ dependencies = [ "syn", ] -[[package]] -name = "twox-hash" -version = "1.6.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1f559b464de2e2bdabcac6a210d12e9b5a5973c251e102c44c585c71d51bd78e" -dependencies = [ - "cfg-if", - "static_assertions", -] - [[package]] name = "unicase" version = "2.6.0" diff --git a/Cargo.toml b/Cargo.toml index 0f28aef00..0e1287b1c 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -21,7 +21,7 @@ walkdir = "2.3.2" bzip2 = "0.4.3" libc = "0.2.103" tar = "0.4.37" -lz4_flex = "0.9.0" +lzzzz = "0.8.0" xz2 = "0.1.6" zip = { version = "0.5.13", default-features = false, features = ["deflate-miniz"] } flate2 = { version = "1.0.22", default-features = false, features = ["zlib"] } diff --git a/src/commands.rs b/src/commands.rs index 06f07362c..5d9e0df19 100644 --- a/src/commands.rs +++ b/src/commands.rs @@ -253,11 +253,11 @@ fn compress_files(files: Vec, formats: Vec, output_file: fs: let mut writer: Box = Box::new(file_writer); // Grab previous encoder and wrap it inside of a new one - let chain_writer_encoder = |format: &CompressionFormat, encoder: Box| { + let chain_writer_encoder = |format: &CompressionFormat, encoder: Box| -> crate::Result> { let encoder: Box = match format { Gzip => Box::new(flate2::write::GzEncoder::new(encoder, Default::default())), Bzip => Box::new(bzip2::write::BzEncoder::new(encoder, Default::default())), - Lz4 => Box::new(lz4_flex::frame::FrameEncoder::new(encoder)), + Lz4 => Box::new(lzzzz::lz4f::WriteCompressor::new(encoder, Default::default())?), Lzma => Box::new(xz2::write::XzEncoder::new(encoder, 6)), Zstd => { let zstd_encoder = zstd::stream::write::Encoder::new(encoder, Default::default()); @@ -268,16 +268,16 @@ fn compress_files(files: Vec, formats: Vec, output_file: fs: } Tar | Zip => unreachable!(), }; - encoder + Ok(encoder) }; for format in formats.iter().flat_map(Extension::iter).skip(1).collect::>().iter().rev() { - writer = chain_writer_encoder(format, writer); + writer = chain_writer_encoder(format, writer)?; } match formats[0].compression_formats[0] { Gzip | Bzip | Lz4 | Lzma | Zstd => { - writer = chain_writer_encoder(&formats[0].compression_formats[0], writer); + writer = chain_writer_encoder(&formats[0].compression_formats[0], writer)?; let mut reader = fs::File::open(&files[0]).unwrap(); io::copy(&mut reader, &mut writer)?; } @@ -352,7 +352,7 @@ fn decompress_file( let decoder: Box = match format { Gzip => Box::new(flate2::read::GzDecoder::new(decoder)), Bzip => Box::new(bzip2::read::BzDecoder::new(decoder)), - Lz4 => Box::new(lz4_flex::frame::FrameDecoder::new(decoder)), + Lz4 => Box::new(lzzzz::lz4f::ReadDecompressor::new(decoder)?), Lzma => Box::new(xz2::read::XzDecoder::new(decoder)), Zstd => Box::new(zstd::stream::Decoder::new(decoder)?), Tar | Zip => unreachable!(), @@ -440,7 +440,7 @@ fn list_archive_contents( let decoder: Box = match format { Gzip => Box::new(flate2::read::GzDecoder::new(decoder)), Bzip => Box::new(bzip2::read::BzDecoder::new(decoder)), - Lz4 => Box::new(lz4_flex::frame::FrameDecoder::new(decoder)), + Lz4 => Box::new(lzzzz::lz4f::ReadDecompressor::new(decoder)?), Lzma => Box::new(xz2::read::XzDecoder::new(decoder)), Zstd => Box::new(zstd::stream::Decoder::new(decoder)?), Tar | Zip => unreachable!(), diff --git a/src/error.rs b/src/error.rs index eeaefe196..f680b4786 100644 --- a/src/error.rs +++ b/src/error.rs @@ -12,6 +12,8 @@ use crate::utils::colors::*; pub enum Error { /// Not every IoError, some of them get filtered by `From` into other variants IoError { reason: String }, + /// From lzzzz::lz4f::Error + Lz4Error { reason: String }, /// Detected from io::Error if .kind() is io::ErrorKind::NotFound NotFound { error_title: String }, /// NEEDS MORE CONTEXT @@ -97,6 +99,7 @@ impl fmt::Display for Error { .hint("Use a more appropriate tool for this, such as rsync.") } Error::IoError { reason } => FinalError::with_title(reason), + Error::Lz4Error { reason } => FinalError::with_title(reason), Error::AlreadyExists { error_title } => FinalError::with_title(error_title).detail("File already exists"), Error::InvalidZipArchive(reason) => FinalError::with_title("Invalid zip archive").detail(reason), Error::PermissionDenied { error_title } => FinalError::with_title(error_title).detail("Permission denied"), @@ -119,6 +122,12 @@ impl From for Error { } } +impl From for Error { + fn from(err: lzzzz::lz4f::Error) -> Self { + Self::Lz4Error { reason: err.to_string() } + } +} + impl From for Error { fn from(err: zip::result::ZipError) -> Self { use zip::result::ZipError; diff --git a/tests/integration.rs b/tests/integration.rs index 53eecd3be..8ee7f93dd 100644 --- a/tests/integration.rs +++ b/tests/integration.rs @@ -33,7 +33,7 @@ enum FileExtension { Bz, Bz2, Gz, - // Lz4, // broken + Lz4, Lz, Lzma, Xz,