This commit is contained in:
2025-10-17 14:01:13 +03:00
parent c93bf8f1d2
commit 54500810a0
2 changed files with 4 additions and 3 deletions

View File

@@ -2,6 +2,7 @@ mod utils;
use clap::Parser;
use std::collections::HashMap;
use std::fmt::format;
use std::io::Write;
use std::{fs, io, time};
use utils::{Metadata, Zsdiff, get_hash};
@@ -108,7 +109,7 @@ pub async fn zsdiff(
utils::compress_parts(parts, &fs::File::create(output_filename)?, level).await;
let output_data = fs::read(output_filename)?;
let size_after = output_data.len();
let output_hash = get_hash(output_data).await;
let output_hash = format!("{} {}", get_hash(output_data).await, output_filename);
fs::File::create(format!("{}.md5", output_filename))?.write_all(output_hash.as_bytes())?;
let elapsed = now.elapsed();
println!("Zsdiff hash: {}", output_hash);

View File

@@ -34,9 +34,9 @@ async fn extract_files(zsdiff: &Zsdiff, filename: String) -> Result<String, io::
async fn check_hash(filename: String) -> Result<(), io::Error> {
let file_data = read(format!("{}.zdiff", filename))?;
let hash_file = read(format!("{}.zdiff.md5", filename))?;
let hash_file = String::from_utf8(read(format!("{}.zdiff.md5", filename))?).unwrap();
let hash = utils::get_hash(file_data).await;
if !String::from_utf8(hash_file).unwrap().eq(&hash) {
if !hash_file.split(" ").next().unwrap().eq(&hash) {
return Err(io::Error::new(io::ErrorKind::Other, "Hash mismatch"));
}
println!("Zsdiff hash: {}", hash);