diff --git a/src/read.rs b/src/read.rs index 75096950..bb2855b6 100644 --- a/src/read.rs +++ b/src/read.rs @@ -57,7 +57,7 @@ pub(crate) mod zip_archive { /// for i in 0..zip.len() { /// let mut file = zip.by_index(i)?; /// println!("Filename: {}", file.name()); - /// std::io::copy(&mut file, &mut std::io::stdout()); + /// std::io::copy(&mut file, &mut std::io::stdout())?; /// } /// /// Ok(()) diff --git a/src/write.rs b/src/write.rs index 4c2fea55..a5f47083 100644 --- a/src/write.rs +++ b/src/write.rs @@ -475,12 +475,8 @@ impl ZipWriter { self.stats.hasher = Hasher::new(); } if let Some(keys) = options.encrypt_with { - let mut zipwriter = crate::zipcrypto::ZipCryptoWriter { - writer: mem::replace(&mut self.inner, Closed).unwrap(), - buffer: vec![], - keys, - }; - let crypto_header = [0u8; 12]; + let mut zipwriter = crate::zipcrypto::ZipCryptoWriter { writer: core::mem::replace(&mut self.inner, GenericZipWriter::Closed).unwrap(), buffer: vec![], keys }; + let mut crypto_header = [0u8; 12]; zipwriter.write_all(&crypto_header)?; self.inner = Storer(MaybeEncrypted::Encrypted(zipwriter)); @@ -509,9 +505,15 @@ impl ZipWriter { // Implicitly calling [`ZipWriter::end_extra_data`] for empty files. self.end_extra_data()?; } - let make_plain_writer = self + let make_plain_writer = match self .inner - .prepare_next_writer(CompressionMethod::Stored, None)?; + .prepare_next_writer(CompressionMethod::Stored, None)? { + MaybeEncrypted::Encrypted(writer) => { + let crc32 = self.stats.hasher.clone().finalize(); + self.inner = Storer(MaybeEncrypted::Unencrypted(writer.finish(crc32)?)) + }, + MaybeEncrypted::Unencrypted(writer) => writer + } self.inner.switch_to(make_plain_writer)?; let writer = self.inner.get_plain();