feat: move core services to services directory
This commit is contained in:
committed by
Andrew Phillips (aider)
parent
8cc0cfc606
commit
321e00171e
33
src/services/compression_service.rs
Normal file
33
src/services/compression_service.rs
Normal file
@@ -0,0 +1,33 @@
|
||||
use crate::compression_engine::{get_compression_engine, CompressionType};
|
||||
use crate::services::error::CoreError;
|
||||
use std::io::Read;
|
||||
use std::path::PathBuf;
|
||||
use std::str::FromStr;
|
||||
use anyhow::anyhow;
|
||||
|
||||
pub struct CompressionService;
|
||||
|
||||
impl CompressionService {
|
||||
pub fn new() -> Self {
|
||||
Self
|
||||
}
|
||||
|
||||
pub fn get_item_content(&self, item_path: PathBuf, compression: &str) -> Result<Vec<u8>, CoreError> {
|
||||
let compression_type = CompressionType::from_str(compression)
|
||||
.map_err(|e| CoreError::Compression(e.to_string()))?;
|
||||
let engine = get_compression_engine(compression_type)
|
||||
.map_err(|e| CoreError::Other(anyhow!(e.to_string())))?;
|
||||
|
||||
let mut reader = engine.open(item_path.clone())
|
||||
.map_err(|e| CoreError::Other(anyhow!("Failed to open item file {:?}: {}", item_path, e)))?;
|
||||
let mut content = Vec::new();
|
||||
reader.read_to_end(&mut content)?;
|
||||
Ok(content)
|
||||
}
|
||||
}
|
||||
|
||||
impl Default for CompressionService {
|
||||
fn default() -> Self {
|
||||
Self::new()
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user