From e5f238a1265dbe79b29eb68bd36d6280bbc503ce Mon Sep 17 00:00:00 2001 From: ScuroNeko Date: Fri, 17 Oct 2025 13:05:11 +0300 Subject: [PATCH] messages --- src/zsdiff.rs | 19 +++++++++++++++++-- src/zspatch.rs | 7 +++++-- 2 files changed, 22 insertions(+), 4 deletions(-) diff --git a/src/zsdiff.rs b/src/zsdiff.rs index 805c477..047413d 100644 --- a/src/zsdiff.rs +++ b/src/zsdiff.rs @@ -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(()) } diff --git a/src/zspatch.rs b/src/zspatch.rs index d12beac..41d2d8c 100644 --- a/src/zspatch.rs +++ b/src/zspatch.rs @@ -4,7 +4,7 @@ use clap::Parser; use std::fs::read; use std::io::Write; use std::path::Path; -use std::{fs, io}; +use std::{fs, io, time}; use utils::Zsdiff; async fn create_tmp_dir(dir_name: String) -> Result { @@ -33,6 +33,7 @@ async fn check_hash(filename: String) -> Result<(), io::Error> { if !String::from_utf8(hash_file).unwrap().eq(&hash) { return Err(io::Error::new(io::ErrorKind::Other, "Hash mismatch")); } + println!("Zsdiff hash: {}", hash); Ok(()) } @@ -41,6 +42,7 @@ async fn zspatch(filename: String, dest_dir: String) -> Result<(), io::Error> { let parts = utils::decompress_parts(read(filename)?).await?; let diff = Zsdiff::from_vec(parts).await?; let tmp_dir_name = extract_files(&diff, filename).await?; + let now = time::Instant::now(); for name in diff.content.keys().collect::>() { let from_path = Path::new(&tmp_dir_name).join(name); let to_path = Path::new(&dest_dir).join(name); @@ -62,6 +64,8 @@ async fn zspatch(filename: String, dest_dir: String) -> Result<(), io::Error> { } } fs::remove_dir_all(tmp_dir_name).ok(); + println!("Patching done!"); + println!("Elapsed time: {:.2?}", now.elapsed()); Ok(()) } @@ -78,7 +82,6 @@ struct Args { #[tokio::main] async fn main() -> io::Result<()> { let args = Args::parse(); - println!("{}", args.hash_check); if args.hash_check { check_hash(args.filename.clone()).await?; }