diff --git a/src/read.rs b/src/read.rs index 6e494f5e..82c3e60a 100644 --- a/src/read.rs +++ b/src/read.rs @@ -810,13 +810,13 @@ impl ZipArchive { /// /// This uses the central directory record of the ZIP file, and ignores local file headers. pub fn with_config(config: Config, mut reader: R) -> ZipResult> { - let results = spec::Zip32CentralDirectoryEnd::find_and_parse(&mut reader)?; - for (footer, cde_start_pos) in results { - if let Ok(shared) = Self::get_metadata(config, &mut reader, &footer, cde_start_pos) { + let mut results = spec::Zip32CentralDirectoryEnd::find_and_parse(&mut reader)?; + for (footer, cde_start_pos) in results.iter_mut() { + if let Ok(shared) = Self::get_metadata(config, &mut reader, &footer, *cde_start_pos) { return Ok(ZipArchive { reader, shared: shared.into(), - comment: footer.zip_file_comment.into(), + comment: Arc::from(mem::replace(&mut footer.zip_file_comment, Box::new([]))), }); } } diff --git a/src/write.rs b/src/write.rs index 73184945..8779893c 100644 --- a/src/write.rs +++ b/src/write.rs @@ -625,17 +625,17 @@ impl ZipWriter { /// /// This uses the given read configuration to initially read the archive. pub fn new_append_with_config(config: Config, mut readwriter: A) -> ZipResult> { - let results = spec::Zip32CentralDirectoryEnd::find_and_parse(&mut readwriter)?; - for (footer, cde_start_pos) in results { + let mut results = spec::Zip32CentralDirectoryEnd::find_and_parse(&mut readwriter)?; + for (footer, cde_start_pos) in results.iter_mut() { if let Ok(metadata) = - ZipArchive::get_metadata(config, &mut readwriter, &footer, cde_start_pos) + ZipArchive::get_metadata(config, &mut readwriter, &footer, *cde_start_pos) { return Ok(ZipWriter { inner: Storer(MaybeEncrypted::Unencrypted(readwriter)), files: metadata.files, stats: Default::default(), writing_to_file: false, - comment: footer.zip_file_comment, + comment: mem::replace(&mut footer.zip_file_comment, Box::new([])), writing_raw: true, // avoid recomputing the last file's header flush_on_finish_file: false, });