messages
This commit is contained in:
@@ -3,7 +3,7 @@ mod utils;
|
|||||||
use clap::Parser;
|
use clap::Parser;
|
||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
use std::io::Write;
|
use std::io::Write;
|
||||||
use std::{fs, io};
|
use std::{fs, io, time};
|
||||||
use utils::{Metadata, Zsdiff, get_hash};
|
use utils::{Metadata, Zsdiff, get_hash};
|
||||||
use walkdir::WalkDir;
|
use walkdir::WalkDir;
|
||||||
|
|
||||||
@@ -77,10 +77,25 @@ pub async fn zsdiff(
|
|||||||
let new_hashes = walk_dir(new).await;
|
let new_hashes = walk_dir(new).await;
|
||||||
let compare_hashes = compare_hashes(old_hashes, new_hashes).await;
|
let compare_hashes = compare_hashes(old_hashes, new_hashes).await;
|
||||||
let parts = compare_hashes.to_vec().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;
|
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())?;
|
fs::File::create(format!("{}.md5", output_filename))?.write_all(output_hash.as_bytes())?;
|
||||||
|
let elapsed = now.elapsed();
|
||||||
println!("Zsdiff hash: {}", output_hash);
|
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(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ use clap::Parser;
|
|||||||
use std::fs::read;
|
use std::fs::read;
|
||||||
use std::io::Write;
|
use std::io::Write;
|
||||||
use std::path::Path;
|
use std::path::Path;
|
||||||
use std::{fs, io};
|
use std::{fs, io, time};
|
||||||
use utils::Zsdiff;
|
use utils::Zsdiff;
|
||||||
|
|
||||||
async fn create_tmp_dir(dir_name: String) -> Result<String, io::Error> {
|
async fn create_tmp_dir(dir_name: String) -> Result<String, io::Error> {
|
||||||
@@ -33,6 +33,7 @@ async fn check_hash(filename: String) -> Result<(), io::Error> {
|
|||||||
if !String::from_utf8(hash_file).unwrap().eq(&hash) {
|
if !String::from_utf8(hash_file).unwrap().eq(&hash) {
|
||||||
return Err(io::Error::new(io::ErrorKind::Other, "Hash mismatch"));
|
return Err(io::Error::new(io::ErrorKind::Other, "Hash mismatch"));
|
||||||
}
|
}
|
||||||
|
println!("Zsdiff hash: {}", hash);
|
||||||
Ok(())
|
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 parts = utils::decompress_parts(read(filename)?).await?;
|
||||||
let diff = Zsdiff::from_vec(parts).await?;
|
let diff = Zsdiff::from_vec(parts).await?;
|
||||||
let tmp_dir_name = extract_files(&diff, filename).await?;
|
let tmp_dir_name = extract_files(&diff, filename).await?;
|
||||||
|
let now = time::Instant::now();
|
||||||
for name in diff.content.keys().collect::<Vec<&String>>() {
|
for name in diff.content.keys().collect::<Vec<&String>>() {
|
||||||
let from_path = Path::new(&tmp_dir_name).join(name);
|
let from_path = Path::new(&tmp_dir_name).join(name);
|
||||||
let to_path = Path::new(&dest_dir).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();
|
fs::remove_dir_all(tmp_dir_name).ok();
|
||||||
|
println!("Patching done!");
|
||||||
|
println!("Elapsed time: {:.2?}", now.elapsed());
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -78,7 +82,6 @@ struct Args {
|
|||||||
#[tokio::main]
|
#[tokio::main]
|
||||||
async fn main() -> io::Result<()> {
|
async fn main() -> io::Result<()> {
|
||||||
let args = Args::parse();
|
let args = Args::parse();
|
||||||
println!("{}", args.hash_check);
|
|
||||||
if args.hash_check {
|
if args.hash_check {
|
||||||
check_hash(args.filename.clone()).await?;
|
check_hash(args.filename.clone()).await?;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user