Add default traits and open function to CompressionEngine

This commit is contained in:
Andrew Phillips
2023-09-20 19:01:50 +00:00
parent 1fe276d110
commit fdc4544068
5 changed files with 59 additions and 51 deletions

View File

@@ -1,7 +1,7 @@
use anyhow::Result;
use std::fs::File;
use std::io;
use std::io::Write;
use std::io::{Read,Write};
use std::path::PathBuf;
use log::*;
@@ -25,17 +25,11 @@ impl CompressionEngine for CompressionEngineGZip {
true
}
fn cat(&self, file_path: PathBuf) -> Result<()> {
debug!("COMPRESSION: Outputting {:?} to STDOUT using {:?}", file_path, *self);
fn open(&self, file_path: PathBuf) -> Result<Box<dyn Read>> {
debug!("COMPRESSION: Opening {:?} using {:?}", file_path, *self);
let mut stdout = io::stdout().lock();
let file = File::open(file_path)?;
let mut gzip_read = GzDecoder::new(file);
io::copy(&mut gzip_read, &mut stdout)?;
stdout.flush()?;
Ok(())
Ok(Box::new(GzDecoder::new(file)))
}
fn create(&self, file_path: PathBuf) -> Result<Box<dyn Write>> {