This commit is contained in:
2025-10-17 13:05:11 +03:00
parent ac8b4d6f81
commit e5f238a126
2 changed files with 22 additions and 4 deletions

View File

@@ -3,7 +3,7 @@ mod utils;
use clap::Parser;
use std::collections::HashMap;
use std::io::Write;
use std::{fs, io};
use std::{fs, io, time};
use utils::{Metadata, Zsdiff, get_hash};
use walkdir::WalkDir;
@@ -77,10 +77,25 @@ pub async fn zsdiff(
let new_hashes = walk_dir(new).await;
let compare_hashes = compare_hashes(old_hashes, new_hashes).await;
let parts = compare_hashes.to_vec().await;
let mut size_before = 0;
for p in &parts {
size_before += p.len();
}
let now = time::Instant::now();
utils::compress_parts(parts, &fs::File::create(output_filename)?, level).await;
let output_hash = get_hash(fs::read(output_filename)?).await;
let output_data = fs::read(output_filename)?;
let size_after = output_data.len();
let output_hash = get_hash(output_data).await;
fs::File::create(format!("{}.md5", output_filename))?.write_all(output_hash.as_bytes())?;
let elapsed = now.elapsed();
println!("Zsdiff hash: {}", output_hash);
println!("Size before: {:.1?}KB", size_before / 1024);
println!("Size after: {:.1?}KB", size_after / 1024);
println!(
"Compress ratio: {:.2?}%",
size_after as f64 / size_before as f64 * 100.0
);
print!("Time elapsed: {:.2?}s", elapsed);
Ok(())
}