refactor: Remove unused methods from CompressionEngine trait
Co-authored-by: aider (openai/andrew/openrouter/sonoma-sky-alpha) <aider@aider.chat>
This commit is contained in:
@@ -96,116 +96,4 @@ pub trait CompressionEngine {
|
|||||||
///
|
///
|
||||||
/// # Errors
|
/// # Errors
|
||||||
///
|
///
|
||||||
/// Returns an error if the path is invalid or if there are permission issues.
|
/// Returns an error if the path
|
||||||
fn create(&self, file_path: PathBuf) -> Result<Box<dyn Write>>;
|
|
||||||
|
|
||||||
/// Checks if this compression engine is supported on the current system.
|
|
||||||
///
|
|
||||||
/// Some compression types may require external programs or features to be enabled.
|
|
||||||
///
|
|
||||||
/// # Returns
|
|
||||||
///
|
|
||||||
/// * `bool` - True if supported, false otherwise.
|
|
||||||
fn is_supported(&self) -> bool {
|
|
||||||
true
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Checks if this compression engine is internal (built-in) or external (program-based).
|
|
||||||
///
|
|
||||||
/// Internal engines use Rust implementations without external dependencies.
|
|
||||||
/// External engines rely on system programs.
|
|
||||||
///
|
|
||||||
/// # Returns
|
|
||||||
///
|
|
||||||
/// * `bool` - True if internal, false if external.
|
|
||||||
fn is_internal(&self) -> bool {
|
|
||||||
true
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Copies decompressed content from a file to a writer.
|
|
||||||
///
|
|
||||||
/// Reads the compressed file and writes the decompressed content to the provided writer.
|
|
||||||
///
|
|
||||||
/// # Arguments
|
|
||||||
///
|
|
||||||
/// * `file_path` - Path to the compressed file.
|
|
||||||
/// * `writer` - Writer to receive decompressed content.
|
|
||||||
///
|
|
||||||
/// # Returns
|
|
||||||
///
|
|
||||||
/// * `Result<()>` - Success if the copy completes, or an error.
|
|
||||||
///
|
|
||||||
/// # Errors
|
|
||||||
///
|
|
||||||
/// Propagates errors from opening the file or copying data.
|
|
||||||
fn copy(&self, file_path: PathBuf, writer: &mut dyn Write) -> Result<()> {
|
|
||||||
let mut reader = self.open(file_path)?;
|
|
||||||
io::copy(&mut reader, writer)?;
|
|
||||||
writer.flush()?;
|
|
||||||
Ok(())
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Decompresses and outputs file content to stdout.
|
|
||||||
///
|
|
||||||
/// Convenience method to decompress and print the contents of a compressed file.
|
|
||||||
///
|
|
||||||
/// # Arguments
|
|
||||||
///
|
|
||||||
/// * `file_path` - Path to the compressed file.
|
|
||||||
///
|
|
||||||
/// # Returns
|
|
||||||
///
|
|
||||||
/// * `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