-
-
Save xiangyuan/26ca525cd359bba02fb20d3ecfc8b445 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
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