Reformat
This commit is contained in:
parent
d5e45f3c20
commit
304becbda3
1 changed files with 33 additions and 26 deletions
33
src/write.rs
33
src/write.rs
|
@ -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);
|
||||
|
|
Loading…
Add table
Reference in a new issue