Skip to content

Instantly share code, notes, and snippets.

@adetaylor
Last active December 5, 2022 08:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save adetaylor/b9ce7297af9fa78b3b0b41dc88e6d720 to your computer and use it in GitHub Desktop.
Save adetaylor/b9ce7297af9fa78b3b0b41dc88e6d720 to your computer and use it in GitHub Desktop.
fn main() -> Result<()> {
let args = Args::parse();
let zipfile = File::open(args.zipfile)?;
let zipfile = CloneableFile::new(zipfile);
let zip = zip::ZipArchive::new(zipfile)?;
let file_count = zip.len();
println!("Zip has {} files", file_count);
(0..file_count).into_par_iter().for_each(|i| {
let mut myzip = zip.clone();
let mut file = myzip.by_index(i).expect("Unable to get file from zip");
if file.is_dir() {
return;
}
let out_file = file.enclosed_name().unwrap();
println!("Filename: {}", out_file.display());
if let Some(parent) = out_file.parent() {
create_dir_all(parent).unwrap_or_else(|err| {
panic!(
"Unable to create parent directories for {}: {}",
out_file.display(),
err
)
});
}
let mut out_file = File::create(out_file).unwrap();
std::io::copy(&mut file, &mut out_file).unwrap();
});
Ok(())
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment