From 32b2f5b4832ae95965eaf05f50eaf78dabea4d9f Mon Sep 17 00:00:00 2001 From: zhanghar Date: Thu, 25 Feb 2021 23:54:20 -0500 Subject: [PATCH] refactor: use iterator for file list init --- src/write.rs | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/src/write.rs b/src/write.rs index 2994b40a..68ae1147 100644 --- a/src/write.rs +++ b/src/write.rs @@ -208,18 +208,15 @@ impl ZipWriter { let (archive_offset, directory_start, number_of_files) = ZipArchive::get_directory_counts(&mut readwriter, &footer, cde_start_pos)?; - let mut files = Vec::new(); - if let Err(_) = readwriter.seek(io::SeekFrom::Start(directory_start)) { return Err(ZipError::InvalidArchive( "Could not seek to start of central directory", )); } - for _ in 0..number_of_files { - let file = central_header_to_zip_file(&mut readwriter, archive_offset)?; - files.push(file); - } + let files = (0..number_of_files) + .map(|_| central_header_to_zip_file(&mut readwriter, archive_offset)) + .collect::, _>>()?; let _ = readwriter.seek(io::SeekFrom::Start(directory_start)); // seek directory_start to overwrite it