Skip to content

Instantly share code, notes, and snippets.

@adetaylor
Last active November 23, 2022 15:03
Show Gist options
  • Save adetaylor/b277c3dcbd0b640d99b5f8419afc5c7b to your computer and use it in GitHub Desktop.
Save adetaylor/b277c3dcbd0b640d99b5f8419afc5c7b to your computer and use it in GitHub Desktop.
// extra 'use' statements omitted
fn main() -> Result<()> {
let args = Args::parse();
let mut zip = zip::ZipArchive::new(args.zipfile)?;
let file_count = zip.len();
println!("Zip has {} files", file_count);
(0..file_count).for_each(|i| {
let mut file = zip.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