This commit is contained in:
Chris Hennick 2023-05-04 10:21:15 -07:00
parent d5e45f3c20
commit 304becbda3
No known key found for this signature in database
GPG key ID: 25653935CC8B6C74

View file

@ -469,7 +469,9 @@ impl<W: Write + Seek> ZipWriter<W> {
// Implicitly calling [`ZipWriter::end_extra_data`] for empty files.
self.end_extra_data()?;
}
let make_plain_writer = self.inner.prepare_switch_to(CompressionMethod::Stored, None)?;
let make_plain_writer = self
.inner
.prepare_switch_to(CompressionMethod::Stored, None)?;
self.inner.switch_to(make_plain_writer)?;
let writer = self.inner.get_plain();
@ -498,8 +500,9 @@ impl<W: Write + Seek> ZipWriter<W> {
pub fn abort_file(&mut self) -> ZipResult<()> {
self.files_by_name
.remove(&*self.files.pop().unwrap().file_name);
let make_plain_writer
= self.inner.prepare_switch_to(CompressionMethod::Stored, None)?;
let make_plain_writer = self
.inner
.prepare_switch_to(CompressionMethod::Stored, None)?;
self.inner.switch_to(make_plain_writer)?;
self.writing_to_file = false;
self.writing_raw = false;
@ -515,7 +518,8 @@ impl<W: Write + Seek> ZipWriter<W> {
S: Into<String>,
{
Self::normalize_options(&mut options);
let make_new_self = self.inner
let make_new_self = self
.inner
.prepare_switch_to(options.compression_method, options.compression_level)?;
self.start_entry(name, options, None)?;
self.inner.switch_to(make_new_self)?;
@ -685,8 +689,10 @@ impl<W: Write + Seek> ZipWriter<W> {
return Err(e);
}
let make_compressing_writer = match self.inner
.prepare_switch_to(file.compression_method, file.compression_level) {
let make_compressing_writer = match self
.inner
.prepare_switch_to(file.compression_method, file.compression_level)
{
Ok(writer) => writer,
Err(e) => {
let _ = self.abort_file();
@ -1037,11 +1043,9 @@ impl<W: Write + Seek> GenericZipWriter<W> {
))
}))
}
CompressionMethod::AES => {
Err(ZipError::UnsupportedArchive(
CompressionMethod::AES => Err(ZipError::UnsupportedArchive(
"AES compression is not supported for writing",
))
}
)),
#[cfg(feature = "zstd")]
CompressionMethod::Zstd => {
let level = clamp_opt(
@ -1062,8 +1066,10 @@ impl<W: Write + Seek> GenericZipWriter<W> {
}
}
fn switch_to(&mut self, make_new_self: Box<dyn FnOnce(W) -> GenericZipWriter<W>>)
-> ZipResult<()>{
fn switch_to(
&mut self,
make_new_self: Box<dyn FnOnce(W) -> GenericZipWriter<W>>,
) -> ZipResult<()> {
let bare = match mem::replace(self, Closed) {
Storer(w) => w,
#[cfg(any(
@ -1080,7 +1086,8 @@ impl<W: Write + Seek> GenericZipWriter<W> {
return Err(io::Error::new(
io::ErrorKind::BrokenPipe,
"ZipWriter was already closed",
).into());
)
.into());
}
};
*self = (make_new_self)(bare);