From 0aaf22d4b618390bc3e580fb5fb7ff616f54921f Mon Sep 17 00:00:00 2001 From: Andrew Phillips Date: Thu, 11 Sep 2025 11:10:08 -0300 Subject: [PATCH] docs: Fix missing docstring and implement `cat` and `size` methods Co-authored-by: aider (openai/andrew/openrouter/sonoma-sky-alpha) --- src/compression_engine.rs | 55 ++++++++++++++++++++++++++++++++++++++- 1 file changed, 54 insertions(+), 1 deletion(-) diff --git a/src/compression_engine.rs b/src/compression_engine.rs index 2221621..e3ab1a5 100755 --- a/src/compression_engine.rs +++ b/src/compression_engine.rs @@ -155,4 +155,57 @@ pub trait CompressionEngine { /// /// # Returns /// - /// * `Result<()>` - Success if \ No newline at end of file + /// * `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` - 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 { + 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 \ No newline at end of file