add file size logging
This commit is contained in:
+10
-19
@@ -54,10 +54,9 @@ fn implode_test(
|
|||||||
for mut file in file_list {
|
for mut file in file_list {
|
||||||
let mut curr_file = File::open(&file)?;
|
let mut curr_file = File::open(&file)?;
|
||||||
let mut buf: Vec<u8> = Vec::new();
|
let mut buf: Vec<u8> = Vec::new();
|
||||||
let byte_count = curr_file.read_to_end(&mut buf)?;
|
let source_byte_count = curr_file.read_to_end(&mut buf)?;
|
||||||
|
|
||||||
file = String::from(file.split('\\').last().unwrap());
|
file = String::from(file.split('\\').last().unwrap());
|
||||||
//println!("{}: {}", file, byte_count);
|
|
||||||
|
|
||||||
let mod_time_unix = curr_file
|
let mod_time_unix = curr_file
|
||||||
.metadata()?
|
.metadata()?
|
||||||
@@ -66,17 +65,22 @@ fn implode_test(
|
|||||||
.as_secs();
|
.as_secs();
|
||||||
let mod_time2 = ZipDateTime::from_unix(mod_time_unix.cast_signed());
|
let mod_time2 = ZipDateTime::from_unix(mod_time_unix.cast_signed());
|
||||||
|
|
||||||
println!("imploding {}...", file);
|
print!("imploding {}...", file);
|
||||||
process_file(&mut archive, &file.as_str(), mod_time2, &buf)?;
|
let compressed_size = process_file(&mut archive, &file.as_str(), mod_time2, &buf)?;
|
||||||
|
println!("{} -> {} bytes", source_byte_count, compressed_size);
|
||||||
}
|
}
|
||||||
|
|
||||||
archive.finish()?;
|
archive.finish()?;
|
||||||
|
|
||||||
|
println!("writing the archive to disk...");
|
||||||
|
|
||||||
{
|
{
|
||||||
let mut file = File::create(output_archive)?;
|
let mut file = File::create(output_archive)?;
|
||||||
file.write_all(output.as_slice())?;
|
file.write_all(output.as_slice())?;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
println!("done!");
|
||||||
|
|
||||||
Ok::<(), Box<dyn std::error::Error>>(())
|
Ok::<(), Box<dyn std::error::Error>>(())
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -85,7 +89,7 @@ fn process_file(
|
|||||||
filename: &str,
|
filename: &str,
|
||||||
modification_time: ZipDateTime,
|
modification_time: ZipDateTime,
|
||||||
data: &[u8],
|
data: &[u8],
|
||||||
) -> Result<(), Box<dyn std::error::Error>> {
|
) -> Result<u64, Box<dyn std::error::Error>> {
|
||||||
let (mut entry, config) = archive
|
let (mut entry, config) = archive
|
||||||
.new_file(filename)
|
.new_file(filename)
|
||||||
//setting last_modified sets the "UT extra field modtime" which is fine for pkzip but breaks mdk2
|
//setting last_modified sets the "UT extra field modtime" which is fine for pkzip but breaks mdk2
|
||||||
@@ -106,20 +110,7 @@ fn process_file(
|
|||||||
let (_, descriptor) = writer.finish()?;
|
let (_, descriptor) = writer.finish()?;
|
||||||
let compressed = entry.finish(descriptor)?;
|
let compressed = entry.finish(descriptor)?;
|
||||||
|
|
||||||
/*
|
Ok::<u64, Box<dyn std::error::Error>>(compressed)
|
||||||
|
|
||||||
let cmp2 = pklib::implode_bytes(data, pklib::CompressionMode::Binary, pklib::DictionarySize::Size4K).unwrap();
|
|
||||||
let dcmp2 = pklib::explode_bytes(&cmp2).unwrap();
|
|
||||||
|
|
||||||
let c = data.to_vec();
|
|
||||||
|
|
||||||
assert_eq!(data.eq(&c), true);
|
|
||||||
assert_eq!(data.eq(&dcmp2), true);
|
|
||||||
assert_eq!(data.len(), dcmp2.len());
|
|
||||||
assert_eq!(dcmp2, c);
|
|
||||||
*/
|
|
||||||
|
|
||||||
Ok::<(), Box<dyn std::error::Error>>(())
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn main() -> Result<(), Box<dyn std::error::Error>> {
|
fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||||
|
|||||||
Reference in New Issue
Block a user