From bdb078a9b7c243d5e600a6f3aed7c21bbe35b839 Mon Sep 17 00:00:00 2001 From: Ruslan Isaev Date: Wed, 8 Jul 2026 11:11:55 +0300 Subject: [PATCH] add file size logging --- src/main.rs | 29 ++++++++++------------------- 1 file changed, 10 insertions(+), 19 deletions(-) diff --git a/src/main.rs b/src/main.rs index d7945e8..fc7559d 100644 --- a/src/main.rs +++ b/src/main.rs @@ -54,10 +54,9 @@ fn implode_test( for mut file in file_list { let mut curr_file = File::open(&file)?; let mut buf: Vec = Vec::new(); - let byte_count = curr_file.read_to_end(&mut buf)?; + let source_byte_count = curr_file.read_to_end(&mut buf)?; file = String::from(file.split('\\').last().unwrap()); - //println!("{}: {}", file, byte_count); let mod_time_unix = curr_file .metadata()? @@ -66,17 +65,22 @@ fn implode_test( .as_secs(); let mod_time2 = ZipDateTime::from_unix(mod_time_unix.cast_signed()); - println!("imploding {}...", file); - process_file(&mut archive, &file.as_str(), mod_time2, &buf)?; + print!("imploding {}...", file); + let compressed_size = process_file(&mut archive, &file.as_str(), mod_time2, &buf)?; + println!("{} -> {} bytes", source_byte_count, compressed_size); } archive.finish()?; + println!("writing the archive to disk..."); + { let mut file = File::create(output_archive)?; file.write_all(output.as_slice())?; } + println!("done!"); + Ok::<(), Box>(()) } @@ -85,7 +89,7 @@ fn process_file( filename: &str, modification_time: ZipDateTime, data: &[u8], -) -> Result<(), Box> { +) -> Result> { let (mut entry, config) = archive .new_file(filename) //setting last_modified sets the "UT extra field modtime" which is fine for pkzip but breaks mdk2 @@ -106,20 +110,7 @@ fn process_file( let (_, descriptor) = writer.finish()?; let compressed = entry.finish(descriptor)?; - /* - - let cmp2 = pklib::implode_bytes(data, pklib::CompressionMode::Binary, pklib::DictionarySize::Size4K).unwrap(); - let dcmp2 = pklib::explode_bytes(&cmp2).unwrap(); - - let c = data.to_vec(); - - assert_eq!(data.eq(&c), true); - assert_eq!(data.eq(&dcmp2), true); - assert_eq!(data.len(), dcmp2.len()); - assert_eq!(dcmp2, c); - */ - - Ok::<(), Box>(()) + Ok::>(compressed) } fn main() -> Result<(), Box> {