From 32b50e9c7aacb4ae8c4a853903f3519895b14177 Mon Sep 17 00:00:00 2001 From: Jonas Frei Date: Thu, 21 Sep 2023 05:55:37 +0200 Subject: [PATCH] Added test code, handled BlockSize error, block size = 16MiB Signed-off-by: Jonas Frei --- README.md | 1 - src/commands/compress.rs | 4 ++-- src/error.rs | 12 ++++++++++++ tests/integration.rs | 2 ++ 4 files changed, 16 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 74c7678..70caede 100644 --- a/README.md +++ b/README.md @@ -178,7 +178,6 @@ Otherwise, you'll need these libraries installed on your system: * [libbz2](https://www.sourceware.org/bzip2) * [libbz3](https://github.com/kspalaiologos/bzip3) * [libz](https://www.zlib.net) ->>>>>>> 066184e (Add support for bzip3) These should be available in your system's package manager. diff --git a/src/commands/compress.rs b/src/commands/compress.rs index 3b0ef3d..986b11d 100644 --- a/src/commands/compress.rs +++ b/src/commands/compress.rs @@ -57,8 +57,8 @@ pub fn compress_files( level.map_or_else(Default::default, |l| bzip2::Compression::new((l as u32).clamp(1, 9))), )), Bzip3 => Box::new( - // Unwrap is safe when using a valid block size - bzip3::write::Bz3Encoder::new(encoder, bytesize::ByteSize::mib(5).0 as usize).unwrap(), + // Use block size of 16 MiB + bzip3::write::Bz3Encoder::new(encoder, 16 * 2_usize.pow(20))?, ), Lz4 => Box::new(lz4_flex::frame::FrameEncoder::new(encoder).auto_finish()), Lzma => Box::new(xz2::write::XzEncoder::new( diff --git a/src/error.rs b/src/error.rs index 2a3a2b1..b8c274d 100644 --- a/src/error.rs +++ b/src/error.rs @@ -200,6 +200,18 @@ impl From for Error { } } +impl From for Error { + fn from(err: bzip3::Error) -> Self { + use bzip3::Error as Bz3Error; + match err { + Bz3Error::Io(inner) => inner.into(), + Bz3Error::BlockSize | Bz3Error::ProcessBlock(_) | Bz3Error::InvalidSignature => { + FinalError::with_title("bzip3 error").detail(err.to_string()).into() + } + } + } +} + 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 b31258e..82315c3 100644 --- a/tests/integration.rs +++ b/tests/integration.rs @@ -21,6 +21,7 @@ enum DirectoryExtension { Tar, Tbz, Tbz2, + Tbz3, Tgz, Tlz4, Tlzma, @@ -36,6 +37,7 @@ enum DirectoryExtension { enum FileExtension { Bz, Bz2, + Bz3, Gz, Lz4, Lzma,