chore: Rename compression directory to compression_engine

This commit is contained in:
Andrew Phillips
2025-05-12 17:08:00 -03:00
committed by Andrew Phillips (aider)
parent 9c8bc542c5
commit e3159473d0
5 changed files with 0 additions and 0 deletions

View 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))
}
}