Last active
November 23, 2022 15:03
-
-
Save adetaylor/b277c3dcbd0b640d99b5f8419afc5c7b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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