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:
@@ -155,4 +155,57 @@ pub trait CompressionEngine {
|
|||||||
///
|
///
|
||||||
/// # Returns
|
/// # 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
|
||||||
Reference in New Issue
Block a user