this repo has no description
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

refactor: rename MultiLevelCompressor to Pipeline and update module/comments

+24 -40
+2 -2
src/backends/mod.rs
··· 1 1 mod bzip2; 2 2 mod gzip; 3 3 mod lz4; 4 - mod multi_level; 4 + mod pipeline; 5 5 mod tar; 6 6 mod xz; 7 7 mod zip; ··· 10 10 pub use bzip2::{Bzip2, Bzip2Args}; 11 11 pub use gzip::{Gzip, GzipArgs}; 12 12 pub use lz4::{Lz4, Lz4Args}; 13 - pub use multi_level::MultiLevelCompressor; 13 + pub use pipeline::Pipeline; 14 14 pub use tar::{Tar, TarArgs}; 15 15 pub use xz::{Xz, XzArgs}; 16 16 pub use zip::{Zip, ZipArgs};
+15 -25
src/backends/multi_level.rs src/backends/pipeline.rs
··· 4 4 use std::sync::mpsc::{channel, Receiver, Sender}; 5 5 use std::thread; 6 6 7 - /// A compressor that chains multiple compressors together 8 - /// This allows for multi-level compression formats like tar.gz 9 - pub struct MultiLevelCompressor { 7 + /// A pipeline of one or more compressors applied in sequence (e.g., tar.gz) 8 + pub struct Pipeline { 10 9 // The chain of compressors to apply in order (innermost to outermost) 11 10 compressors: Vec<Box<dyn Compressor>>, 12 11 } 13 12 14 - impl MultiLevelCompressor { 15 - /// Create a new MultiLevelCompressor with a chain of compressors 13 + impl Pipeline { 14 + /// Create a new Pipeline with the given compressors 16 15 pub fn new(compressors: Vec<Box<dyn Compressor>>) -> Self { 17 - MultiLevelCompressor { compressors } 16 + Pipeline { compressors } 18 17 } 19 18 20 - /// Create a new MultiLevelCompressor from compressor type names 19 + /// Create a new Pipeline from compressor type names 21 20 pub fn from_names(compressor_names: &[String]) -> io::Result<Self> { 22 21 let compressors = compressor_names 23 22 .iter() ··· 149 148 } 150 149 } 151 150 152 - impl Compressor for MultiLevelCompressor { 151 + impl Compressor for Pipeline { 153 152 fn name(&self) -> &str { 154 153 if let Some(comp) = self.compressors.last() { 155 154 comp.name() ··· 217 216 if self.compressors.is_empty() { 218 217 return Err(io::Error::new( 219 218 io::ErrorKind::Other, 220 - "No compressors in multi-level chain", 219 + "No compressors in pipeline", 221 220 )); 222 221 } 223 222 ··· 272 271 if self.compressors.is_empty() { 273 272 return Err(io::Error::new( 274 273 io::ErrorKind::Other, 275 - "No compressors in multi-level chain for extraction", 274 + "No compressors in pipeline for extraction", 276 275 )); 277 276 } 278 277 ··· 349 348 use tempfile::tempdir; 350 349 351 350 #[test] 352 - fn test_multi_level_compression() -> Result<(), io::Error> { 353 - // Create a temporary directory for our test 351 + fn test_pipeline_compression() -> Result<(), io::Error> { 354 352 let temp_dir = tempdir()?; 355 353 356 - // Create a test file 357 - let test_content = "This is a test file for multi-level compression"; 354 + let test_content = "This is a test file for pipeline compression"; 358 355 let test_file_path = temp_dir.path().join("test.txt"); 359 356 fs::write(&test_file_path, test_content)?; 360 357 361 - // Create a tar.gz compressor (tar first, then gzip) 362 - let compressors: Vec<Box<dyn Compressor>> = vec![ 358 + let pipeline = Pipeline::new(vec![ 363 359 Box::new(crate::backends::Tar::default()), 364 360 Box::new(crate::backends::Gzip::default()), 365 - ]; 366 - let multi_compressor = MultiLevelCompressor::new(compressors); 361 + ]); 367 362 368 - // Compress the test file 369 363 let archive_path = temp_dir.path().join("test.tar.gz"); 370 - multi_compressor.compress( 364 + pipeline.compress( 371 365 CmprssInput::Path(vec![test_file_path.clone()]), 372 366 CmprssOutput::Path(archive_path.clone()), 373 367 )?; 374 368 375 - // Verify the archive was created 376 369 assert!(archive_path.exists()); 377 370 378 - // Extract the archive 379 371 let output_dir = temp_dir.path().join("extracted"); 380 372 fs::create_dir(&output_dir)?; 381 - multi_compressor.extract( 373 + pipeline.extract( 382 374 CmprssInput::Path(vec![archive_path.clone()]), 383 375 CmprssOutput::Path(output_dir.clone()), 384 376 )?; 385 377 386 - // Verify the file was extracted correctly 387 378 let extracted_file = output_dir.join("test.txt"); 388 379 assert!(extracted_file.exists()); 389 380 390 - // Verify the content is the same 391 381 let extracted_content = fs::read_to_string(extracted_file)?; 392 382 assert_eq!(extracted_content, test_content); 393 383
+3 -3
src/main.rs
··· 81 81 action: Action, 82 82 } 83 83 84 - /// Get a compressor from a filename, detecting multi-level formats like tar.gz 84 + /// Get a compressor pipeline from a filename by scanning extensions right-to-left 85 85 fn get_compressor_from_filename(filename: &Path) -> Option<Box<dyn Compressor>> { 86 86 let file_name = filename.file_name()?.to_str()?; 87 87 let parts: Vec<&str> = file_name.split('.').collect(); ··· 108 108 109 109 // Reverse to innermost-to-outermost order 110 110 compressor_names.reverse(); 111 - MultiLevelCompressor::from_names(&compressor_names) 111 + Pipeline::from_names(&compressor_names) 112 112 .ok() 113 113 .map(|m| Box::new(m) as Box<dyn Compressor>) 114 114 } ··· 507 507 } 508 508 // Handle all Writer output cases 509 509 (_, CmprssOutput::Writer(_)) => { 510 - // Writer outputs are only supported in multi-level compression 510 + // Writer outputs are only used internally by Pipeline 511 511 // In main.rs we'll assume compression 512 512 action = Action::Compress; 513 513 }
+4 -10
tests/multi_level.rs tests/pipeline.rs
··· 8 8 use predicates::prelude::*; 9 9 use std::process::Command; 10 10 11 - // Test the most common multi-level compression case: tar.gz 11 + // Test manual step-by-step tar.gz roundtrip 12 12 #[test] 13 13 fn test_tar_gz_manual_roundtrip() -> Result<(), Box<dyn std::error::Error>> { 14 14 let temp_dir = TempDir::new()?; ··· 62 62 Ok(()) 63 63 } 64 64 65 - // 66 - // Test the multi-level compression using tar.gz format 67 - // 65 + // Test pipeline compression using tar.gz format 68 66 #[test] 69 67 fn test_tar_gz_compress() -> Result<(), Box<dyn std::error::Error>> { 70 68 let temp_dir = TempDir::new()?; ··· 91 89 Ok(()) 92 90 } 93 91 94 - // 95 - // Test the multi-level extraction using tar.gz format 96 - // 92 + // Test pipeline extraction using tar.gz format 97 93 #[test] 98 94 fn test_tar_gz_extract() -> Result<(), Box<dyn std::error::Error>> { 99 95 let temp_dir = TempDir::new()?; ··· 179 175 Ok(()) 180 176 } 181 177 182 - // 183 - // Test the multi-level extraction using tar.gz format with explicit commands 184 - // 178 + // Test pipeline extraction using tar.gz with explicit compress then auto-detect extract 185 179 #[test] 186 180 fn test_tar_gz_explicit_then_extract() -> Result<(), Box<dyn std::error::Error>> { 187 181 let temp_dir = TempDir::new()?;