From 53763ed13a28bbf3d7aefd732d5dd1737083017c Mon Sep 17 00:00:00 2001 From: qkzk Date: Tue, 21 Feb 2023 21:49:14 +0100 Subject: refactor list_file_zip and document it. --- src/decompress.rs | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) (limited to 'src/decompress.rs') diff --git a/src/decompress.rs b/src/decompress.rs index a7d3575..d4bc001 100644 --- a/src/decompress.rs +++ b/src/decompress.rs @@ -49,17 +49,13 @@ pub fn decompress_xz(source: &Path) -> FmResult<()> { Ok(()) } +/// List files contained in a ZIP file. +/// Will return an error if the ZIP file is corrupted. pub fn list_files_zip

(source: P) -> FmResult> where P: AsRef, { let file = File::open(source)?; - let mut content = vec![]; - let mut zip = zip::ZipArchive::new(file)?; - - for i in 0..zip.len() { - let file = zip.by_index(i)?; - content.push(file.name().to_owned()); - } - Ok(content) + let zip = zip::ZipArchive::new(file)?; + Ok(zip.file_names().map(|f| f.to_owned()).collect()) } -- cgit v1.2.3