docs: Add Rustdoc comments to CompressionService methods
Co-authored-by: aider (openai/andrew/openrouter/sonoma-sky-alpha) <aider@aider.chat>
This commit is contained in:
@@ -7,11 +7,56 @@ use anyhow::anyhow;
|
||||
|
||||
pub struct CompressionService;
|
||||
|
||||
/// Service for handling compression and decompression of item content.
|
||||
///
|
||||
/// Provides methods to read compressed item files either fully into memory
|
||||
/// or as streaming readers. Supports various compression types via engines.
|
||||
///
|
||||
/// # Examples
|
||||
///
|
||||
/// ```
|
||||
/// let service = CompressionService::new();
|
||||
/// let content = service.get_item_content(path, "gzip")?;
|
||||
/// ```
|
||||
|
||||
impl CompressionService {
|
||||
/// Creates a new CompressionService instance.
|
||||
///
|
||||
/// # Returns
|
||||
///
|
||||
/// A new `CompressionService`.
|
||||
///
|
||||
/// # Examples
|
||||
///
|
||||
/// ```
|
||||
/// let service = CompressionService::new();
|
||||
/// ```
|
||||
pub fn new() -> Self {
|
||||
Self
|
||||
}
|
||||
|
||||
/// Reads and decompresses the full content of an item file into memory.
|
||||
///
|
||||
/// # Arguments
|
||||
///
|
||||
/// * `item_path` - Path to the compressed item file.
|
||||
/// * `compression` - Compression type string (e.g., "gzip").
|
||||
///
|
||||
/// # Returns
|
||||
///
|
||||
/// * `Result<Vec<u8>, CoreError>` - Decompressed content bytes.
|
||||
///
|
||||
/// # Errors
|
||||
///
|
||||
/// * `CoreError::Compression(...)` - If compression type invalid.
|
||||
/// * `CoreError::Other(...)` - If file open or read fails.
|
||||
///
|
||||
/// # Examples
|
||||
///
|
||||
/// ```
|
||||
/// let content = service.get_item_content(item_path, "lz4")?;
|
||||
/// assert_eq!(content.len(), expected_size);
|
||||
/// ```
|
||||
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()))?;
|
||||
@@ -25,6 +70,32 @@ impl CompressionService {
|
||||
Ok(content)
|
||||
}
|
||||
|
||||
/// Opens a streaming reader for decompressing item content.
|
||||
///
|
||||
/// For Send compatibility, reads full content into memory and returns a Cursor.
|
||||
/// Note: Not suitable for very large files due to memory usage.
|
||||
///
|
||||
/// # Arguments
|
||||
///
|
||||
/// * `item_path` - Path to the compressed item file.
|
||||
/// * `compression` - Compression type string.
|
||||
///
|
||||
/// # Returns
|
||||
///
|
||||
/// * `Result<Box<dyn Read + Send>, CoreError>` - Boxed streaming reader.
|
||||
///
|
||||
/// # Errors
|
||||
///
|
||||
/// * `CoreError::Compression(...)` - If compression type invalid.
|
||||
/// * `CoreError::Other(...)` - If file open or read fails.
|
||||
///
|
||||
/// # Examples
|
||||
///
|
||||
/// ```
|
||||
/// let mut reader = service.stream_item_content(item_path, "gzip")?;
|
||||
/// let mut buf = [0; 1024];
|
||||
/// let n = reader.read(&mut buf)?;
|
||||
/// ```
|
||||
pub fn stream_item_content(
|
||||
&self,
|
||||
item_path: PathBuf,
|
||||
|
||||
Reference in New Issue
Block a user