From f3dd4d9804b1c894783b684e4fed454e83194237 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vin=C3=ADcius=20Rodrigues=20Miguel?= Date: Wed, 24 Mar 2021 17:21:00 -0300 Subject: [PATCH] Progress in Lzma compression --- src/compressors/mod.rs | 3 ++- src/compressors/tomemory.rs | 17 +++++++++++++++++ src/evaluator.rs | 3 ++- 3 files changed, 21 insertions(+), 2 deletions(-) diff --git a/src/compressors/mod.rs b/src/compressors/mod.rs index 93336d4..ad0ec85 100644 --- a/src/compressors/mod.rs +++ b/src/compressors/mod.rs @@ -9,4 +9,5 @@ pub use self::compressor::Entry; pub use self::tar::TarCompressor; pub use self::zip::ZipCompressor; pub use self::bzip::BzipCompressor; -pub use self::tomemory::GzipCompressor; \ No newline at end of file +pub use self::tomemory::GzipCompressor; +pub use self::tomemory::LzmaCompressor; \ No newline at end of file diff --git a/src/compressors/tomemory.rs b/src/compressors/tomemory.rs index 66db3ea..152d7ee 100644 --- a/src/compressors/tomemory.rs +++ b/src/compressors/tomemory.rs @@ -8,6 +8,7 @@ use crate::utils::ensure_exists; use super::{Compressor, Entry}; pub struct GzipCompressor {} +pub struct LzmaCompressor {} struct CompressorToMemory {} @@ -78,6 +79,7 @@ fn get_encoder<'a>( buffer, flate2::Compression::default(), )), + CompressionFormat::Lzma => Box::new(xz2::write::XzEncoder::new(buffer, 6)), _other => unreachable!(), } } @@ -94,4 +96,19 @@ impl Compressor for GzipCompressor { ), } } +} + + +impl Compressor for LzmaCompressor { + fn compress(&self, from: Entry) -> OuchResult> { + let format = CompressionFormat::Lzma; + match from { + Entry::Files(files) => Ok( + CompressorToMemory::compress_files(files, format)? + ), + Entry::InMemory(file) => Ok( + CompressorToMemory::compress_file_in_memory(file, format)? + ), + } + } } \ No newline at end of file diff --git a/src/evaluator.rs b/src/evaluator.rs index b245d82..d87c684 100644 --- a/src/evaluator.rs +++ b/src/evaluator.rs @@ -9,6 +9,7 @@ use crate::compressors::{ ZipCompressor, GzipCompressor, BzipCompressor, + LzmaCompressor }; use crate::decompressors::{ @@ -73,7 +74,7 @@ impl Evaluator { CompressionFormat::Zip => Box::new(ZipCompressor {}), CompressionFormat::Bzip => Box::new(BzipCompressor {}), CompressionFormat::Gzip => Box::new(GzipCompressor {}), - _other => todo!() + CompressionFormat::Lzma => Box::new(LzmaCompressor {}), }; Ok((first_compressor, second_compressor))