ZipArchive reuse
This commit is contained in:
parent
eedcf9a1b1
commit
f7fa686057
12
src/main.rs
12
src/main.rs
@ -42,7 +42,10 @@ fn write_file<T: Seek + Write>(
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn process_files(files: &[PathBuf]) -> Result<(), Box<dyn std::error::Error>> {
|
||||
fn process_files<R: Read + Seek>(
|
||||
archive: &mut zip::ZipArchive<R>,
|
||||
files: &[PathBuf],
|
||||
) -> Result<(), Box<dyn std::error::Error>> {
|
||||
if files.is_empty() {
|
||||
return Ok(());
|
||||
}
|
||||
@ -59,10 +62,6 @@ fn process_files(files: &[PathBuf]) -> Result<(), Box<dyn std::error::Error>> {
|
||||
trap: EncoderTrap::Ignore,
|
||||
};
|
||||
|
||||
let zip_file = fs::File::open(INPUT_FILENAME)?;
|
||||
let zip_reader = io::BufReader::new(zip_file);
|
||||
let mut archive = zip::ZipArchive::new(zip_reader)?;
|
||||
|
||||
let mut outfile = fs::File::create(OUTPUT_FILENAME)?;
|
||||
let mut zip_writer = ZipWriter::new(&mut outfile);
|
||||
|
||||
@ -105,14 +104,13 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||
}
|
||||
})
|
||||
.collect();
|
||||
drop(archive);
|
||||
|
||||
println!("processing {} files...", source_files.len());
|
||||
|
||||
source_files.sort();
|
||||
let source_files = source_files;
|
||||
|
||||
process_files(&source_files)?;
|
||||
process_files(&mut archive, &source_files)?;
|
||||
|
||||
println!("done");
|
||||
Ok(())
|
||||
|
Loading…
Reference in New Issue
Block a user