Skip to content

Instantly share code, notes, and snippets.

@xiangyuan
Forked from adetaylor/ripunzip4.rs
Created December 5, 2022 08:07
Show Gist options
  • Save xiangyuan/26ca525cd359bba02fb20d3ecfc8b445 to your computer and use it in GitHub Desktop.
Save xiangyuan/26ca525cd359bba02fb20d3ecfc8b445 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