Progress in Lzma compression

This commit is contained in:
Vinícius Rodrigues Miguel 2021-03-24 17:21:00 -03:00
parent 3fa939ac90
commit f3dd4d9804
3 changed files with 21 additions and 2 deletions

View File

@ -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;
pub use self::tomemory::GzipCompressor;
pub use self::tomemory::LzmaCompressor;

View File

@ -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<Vec<u8>> {
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)?
),
}
}
}

View File

@ -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))