feat: move core services to services directory

This commit is contained in:
Andrew Phillips
2025-08-25 18:22:17 -03:00
committed by Andrew Phillips (aider)
parent 8cc0cfc606
commit 321e00171e
9 changed files with 201 additions and 533 deletions

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