diff --git a/CHANGELOG.md b/CHANGELOG.md index c1c8fedd..b000d5d1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -142,4 +142,8 @@ ### Fixed - Fixes a rare bug where the size of the extra-data field could overflow when `large_file` was set. - - Fixes more cases of a bug when ZIP64 magic bytes occur in filenames. \ No newline at end of file + - Fixes more cases of a bug when ZIP64 magic bytes occur in filenames. + +## [0.8.1] + + - `ZipWriter` now implements `Send` if the underlying writer does. \ No newline at end of file diff --git a/src/read.rs b/src/read.rs index 051b11b6..cc95558c 100644 --- a/src/read.rs +++ b/src/read.rs @@ -14,7 +14,6 @@ use std::borrow::Cow; use std::collections::HashMap; use std::io::{self, prelude::*}; use std::path::Path; -use std::rc::Rc; use std::sync::Arc; #[cfg(any( @@ -551,7 +550,7 @@ impl ZipArchive { } /// Search for a file entry by name - pub fn by_name<'a>(&'a mut self, name: &str) -> ZipResult> { + pub fn by_name(&mut self, name: &str) -> ZipResult { Ok(self.by_name_with_optional_password(name, None)?.unwrap()) } @@ -582,11 +581,11 @@ impl ZipArchive { /// There are many passwords out there that will also pass the validity checks /// we are able to perform. This is a weakness of the ZipCrypto algorithm, /// due to its fairly primitive approach to cryptography. - pub fn by_index_decrypt<'a>( - &'a mut self, + pub fn by_index_decrypt( + &mut self, file_number: usize, password: &[u8], - ) -> ZipResult, InvalidPassword>> { + ) -> ZipResult> { self.by_index_with_optional_password(file_number, Some(password)) } @@ -613,11 +612,11 @@ impl ZipArchive { }) } - fn by_index_with_optional_password<'a>( - &'a mut self, + fn by_index_with_optional_password( + &mut self, file_number: usize, mut password: Option<&[u8]>, - ) -> ZipResult, InvalidPassword>> { + ) -> ZipResult> { let data = self .shared .files @@ -738,8 +737,8 @@ fn central_header_to_zip_file_inner( uncompressed_size: uncompressed_size as u64, file_name, file_name_raw, - extra_field: Rc::new(extra_field), - central_extra_field: Rc::new(vec![]), + extra_field: Arc::new(extra_field), + central_extra_field: Arc::new(vec![]), file_comment, header_start: offset, central_header_start, @@ -1099,8 +1098,8 @@ pub fn read_zipfile_from_stream<'a, R: Read>(reader: &'a mut R) -> ZipResult, /// Extra field usually used for storage expansion - pub extra_field: Rc>, + pub extra_field: Arc>, /// Extra field only written to central directory - pub central_extra_field: Rc>, + pub central_extra_field: Arc>, /// File comment pub file_comment: String, /// Specifies where the local header of the file starts @@ -531,8 +531,8 @@ mod test { uncompressed_size: 0, file_name: file_name.clone(), file_name_raw: file_name.into_bytes(), - extra_field: Rc::new(vec![]), - central_extra_field: Rc::new(vec![]), + extra_field: Arc::new(vec![]), + central_extra_field: Arc::new(vec![]), file_comment: String::new(), header_start: 0, data_start: AtomicU64::new(0), @@ -581,6 +581,7 @@ mod test { assert!(DateTime::from_date_and_time(2107, 12, 32, 0, 0, 0).is_err()); } + use std::sync::Arc; #[cfg(feature = "time")] use time::{format_description::well_known::Rfc3339, OffsetDateTime}; diff --git a/src/write.rs b/src/write.rs index 7eaa8d27..ea9921bf 100644 --- a/src/write.rs +++ b/src/write.rs @@ -14,7 +14,7 @@ use std::io; use std::io::prelude::*; use std::io::{BufReader, SeekFrom}; use std::mem; -use std::rc::Rc; +use std::sync::Arc; #[cfg(any( feature = "deflate", @@ -134,8 +134,8 @@ pub struct FileOptions { pub(crate) permissions: Option, pub(crate) large_file: bool, encrypt_with: Option, - extra_data: Rc>, - central_extra_data: Rc>, + extra_data: Arc>, + central_extra_data: Arc>, alignment: u16, } @@ -149,8 +149,8 @@ impl arbitrary::Arbitrary<'_> for FileOptions { permissions: Option::::arbitrary(u)?, large_file: bool::arbitrary(u)?, encrypt_with: Option::::arbitrary(u)?, - extra_data: Rc::new(vec![]), - central_extra_data: Rc::new(vec![]), + extra_data: Arc::new(vec![]), + central_extra_data: Arc::new(vec![]), alignment: u16::arbitrary(u)?, }; u.arbitrary_loop(Some(0), Some((u16::MAX / 4) as u32), |u| { @@ -252,12 +252,12 @@ impl FileOptions { } else { &mut self.extra_data }; - let vec = Rc::get_mut(field); + let vec = Arc::get_mut(field); let vec = match vec { Some(exclusive) => exclusive, None => { - *field = Rc::new(field.to_vec()); - Rc::get_mut(field).unwrap() + *field = Arc::new(field.to_vec()); + Arc::get_mut(field).unwrap() } }; vec.reserve_exact(data.len() + 4); @@ -272,10 +272,10 @@ impl FileOptions { #[must_use] pub fn clear_extra_data(mut self) -> FileOptions { if self.extra_data.len() > 0 { - self.extra_data = Rc::new(vec![]); + self.extra_data = Arc::new(vec![]); } if self.central_extra_data.len() > 0 { - self.central_extra_data = Rc::new(vec![]); + self.central_extra_data = Arc::new(vec![]); } self } @@ -305,8 +305,8 @@ impl Default for FileOptions { permissions: None, large_file: false, encrypt_with: None, - extra_data: Rc::new(vec![]), - central_extra_data: Rc::new(vec![]), + extra_data: Arc::new(vec![]), + central_extra_data: Arc::new(vec![]), alignment: 1, } } @@ -1398,7 +1398,7 @@ mod test { use crate::ZipArchive; use std::io; use std::io::{Read, Write}; - use std::rc::Rc; + use std::sync::Arc; #[test] fn write_empty_zip() { @@ -1518,8 +1518,8 @@ mod test { permissions: Some(33188), large_file: false, encrypt_with: None, - extra_data: Rc::new(vec![]), - central_extra_data: Rc::new(vec![]), + extra_data: Arc::new(vec![]), + central_extra_data: Arc::new(vec![]), alignment: 1, }; writer.start_file("mimetype", options).unwrap(); @@ -1558,8 +1558,8 @@ mod test { permissions: Some(33188), large_file: false, encrypt_with: None, - extra_data: Rc::new(vec![]), - central_extra_data: Rc::new(vec![]), + extra_data: Arc::new(vec![]), + central_extra_data: Arc::new(vec![]), alignment: 0, }; writer.start_file(RT_TEST_FILENAME, options).unwrap(); @@ -1608,8 +1608,8 @@ mod test { permissions: Some(33188), large_file: false, encrypt_with: None, - extra_data: Rc::new(vec![]), - central_extra_data: Rc::new(vec![]), + extra_data: Arc::new(vec![]), + central_extra_data: Arc::new(vec![]), alignment: 0, }; writer.start_file(RT_TEST_FILENAME, options).unwrap();