v0.2.1
This commit is contained in:
@@ -2,6 +2,7 @@ mod utils;
|
|||||||
|
|
||||||
use clap::Parser;
|
use clap::Parser;
|
||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
|
use std::fmt::format;
|
||||||
use std::io::Write;
|
use std::io::Write;
|
||||||
use std::{fs, io, time};
|
use std::{fs, io, time};
|
||||||
use utils::{Metadata, Zsdiff, get_hash};
|
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;
|
utils::compress_parts(parts, &fs::File::create(output_filename)?, level).await;
|
||||||
let output_data = fs::read(output_filename)?;
|
let output_data = fs::read(output_filename)?;
|
||||||
let size_after = output_data.len();
|
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())?;
|
fs::File::create(format!("{}.md5", output_filename))?.write_all(output_hash.as_bytes())?;
|
||||||
let elapsed = now.elapsed();
|
let elapsed = now.elapsed();
|
||||||
println!("Zsdiff hash: {}", output_hash);
|
println!("Zsdiff hash: {}", output_hash);
|
||||||
|
|||||||
@@ -34,9 +34,9 @@ async fn extract_files(zsdiff: &Zsdiff, filename: String) -> Result<String, io::
|
|||||||
|
|
||||||
async fn check_hash(filename: String) -> Result<(), io::Error> {
|
async fn check_hash(filename: String) -> Result<(), io::Error> {
|
||||||
let file_data = read(format!("{}.zdiff", filename))?;
|
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;
|
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"));
|
return Err(io::Error::new(io::ErrorKind::Other, "Hash mismatch"));
|
||||||
}
|
}
|
||||||
println!("Zsdiff hash: {}", hash);
|
println!("Zsdiff hash: {}", hash);
|
||||||
|
|||||||
Reference in New Issue
Block a user