chore: Rename compression directory to compression_engine
This commit is contained in:
committed by
Andrew Phillips (aider)
parent
9c8bc542c5
commit
e3159473d0
40
src/compression_engine/lz4.rs
Normal file
40
src/compression_engine/lz4.rs
Normal file
@@ -0,0 +1,40 @@
|
||||
use anyhow::Result;
|
||||
use log::*;
|
||||
use std::fs::File;
|
||||
use std::io::{Read, Write};
|
||||
use std::path::PathBuf;
|
||||
|
||||
use lz4_flex::frame::{FrameDecoder, FrameEncoder};
|
||||
|
||||
use crate::compression::CompressionEngine;
|
||||
|
||||
#[derive(Debug, Eq, PartialEq, Clone, Default)]
|
||||
pub struct CompressionEngineLZ4 {}
|
||||
|
||||
impl CompressionEngineLZ4 {
|
||||
pub fn new() -> CompressionEngineLZ4 {
|
||||
CompressionEngineLZ4 {}
|
||||
}
|
||||
}
|
||||
|
||||
impl CompressionEngine for CompressionEngineLZ4 {
|
||||
fn is_supported(&self) -> bool {
|
||||
true
|
||||
}
|
||||
|
||||
fn open(&self, file_path: PathBuf) -> Result<Box<dyn Read>> {
|
||||
debug!("COMPRESSION: Opening {:?} using {:?}", file_path, *self);
|
||||
|
||||
let file = File::open(file_path)?;
|
||||
Ok(Box::new(FrameDecoder::new(file)))
|
||||
}
|
||||
|
||||
fn create(&self, file_path: PathBuf) -> Result<Box<dyn Write>> {
|
||||
debug!("COMPRESSION: Writting to {:?} using {:?}", file_path, *self);
|
||||
|
||||
let file = File::create(file_path)?;
|
||||
let lz4_write = FrameEncoder::new(file).auto_finish();
|
||||
|
||||
Ok(Box::new(lz4_write))
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user