docs: Fix missing docstring and implement cat and size methods

Co-authored-by: aider (openai/andrew/openrouter/sonoma-sky-alpha) <aider@aider.chat>
This commit is contained in:
Andrew Phillips
2025-09-11 11:10:08 -03:00
parent 7be0b6735e
commit 0aaf22d4b6

View File

@@ -155,4 +155,57 @@ pub trait CompressionEngine {
///
/// # Returns
///
/// * `Result<()>` - Success if
/// * `Result<()>` - Success if the content is output, or an error.
///
/// # Errors
///
/// Propagates errors from copying to stdout.
fn cat(&self, file_path: PathBuf) -> Result<()> {
let mut stdout = io::stdout().lock();
self.copy(file_path, &mut stdout)
}
/// Calculates the decompressed size of a file.
///
/// Reads the entire decompressed content to determine its size in bytes.
///
/// # Arguments
///
/// * `file_path` - Path to the compressed file.
///
/// # Returns
///
/// * `Result<usize>` - The decompressed size in bytes, or an error.
///
/// # Errors
///
/// Returns an error if the file cannot be opened or read.
///
/// # Examples
///
/// ```
/// let engine = /* some engine */;
/// let size = engine.size("file.gz".into()).unwrap();
/// println!("Decompressed size: {} bytes", size);
/// ```
fn size(&self, file_path: PathBuf) -> Result<usize> {
let mut reader = self.open(file_path)?;
let mut buffer = [0; libc::BUFSIZ as usize];
let mut size: usize = 0;
loop {
let n = reader.read(&mut buffer[..libc::BUFSIZ as usize])?;
if n == 0 {
debug!("COMPRESSION: EOF");
break;
}
size += n;
}
Ok(size)
}
}
lazy_static! {
/// Mapping of