Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions src/aes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,16 @@ impl<W: Write> AesWriter<W> {
})
}

/// Gets a reference to the underlying writer.
pub fn get_ref(&self) -> &W {
&self.writer
}

/// Gets a mutable reference to the underlying writer.
pub fn get_mut(&mut self) -> &mut W {
&mut self.writer
}

pub fn finish(mut self) -> io::Result<W> {
self.write_encrypted_file_header()?;

Expand Down
78 changes: 78 additions & 0 deletions src/write.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,25 @@ enum MaybeEncrypted<W> {
ZipCrypto(crate::zipcrypto::ZipCryptoWriter<W>),
}

impl<W: Write> MaybeEncrypted<W> {
fn get_ref(&self) -> &W {
match self {
MaybeEncrypted::Unencrypted(w) => w,
#[cfg(feature = "aes-crypto")]
MaybeEncrypted::Aes(w) => w.get_ref(),
MaybeEncrypted::ZipCrypto(w) => w.get_ref(),
}
}
fn get_mut(&mut self) -> &mut W {
match self {
MaybeEncrypted::Unencrypted(w) => w,
#[cfg(feature = "aes-crypto")]
MaybeEncrypted::Aes(w) => w.get_mut(),
MaybeEncrypted::ZipCrypto(w) => w.get_mut(),
}
}
}

impl<W> Debug for MaybeEncrypted<W> {
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
// Don't print W, since it may be a huge Vec<u8>
Expand Down Expand Up @@ -182,6 +201,55 @@ pub(crate) mod zip_writer {
self.comment, self.flush_on_finish_file))
}
}

impl<W: Write + Seek> ZipWriter<W> {
/// Gets a reference to the underlying writer in this ZipWrite.
pub fn get_ref(&self) -> &W {
use GenericZipWriter::*;
match &self.inner {
Closed => panic!("Can't get underlying writer of closed archive"),
Storer(w) => w.get_ref(),
#[cfg(feature = "deflate-flate2")]
Deflater(w) => w.get_ref().get_ref(),
#[cfg(feature = "deflate-zopfli")]
ZopfliDeflater(w) => w.get_ref().get_ref(),
#[cfg(feature = "deflate-zopfli")]
BufferedZopfliDeflater(w) => w.get_ref().get_ref().get_ref(),
#[cfg(feature = "bzip2")]
Bzip2(w) => w.get_ref().get_ref(),
#[cfg(feature = "zstd")]
Zstd(w) => w.get_ref().get_ref(),
#[cfg(feature = "xz")]
Xz(w) => w.inner().get_ref(),
#[cfg(feature = "ppmd")]
Ppmd(w) => w.get_ref().get_ref(),
}
}

/// Gets a reference to the underlying writer in this ZipWrite.
pub fn get_mut(&mut self) -> &mut W {
use MaybeEncrypted::*;
use GenericZipWriter::*;
match &mut self.inner {
Closed => panic!("Can't get underlying writer of closed archive"),
Storer(w) => w.get_mut(),
#[cfg(feature = "deflate-flate2")]
Deflater(w) => w.get_mut().get_mut(),
#[cfg(feature = "deflate-zopfli")]
ZopfliDeflater(w) => w.get_mut().get_mut(),
#[cfg(feature = "deflate-zopfli")]
BufferedZopfliDeflater(w) => w.get_mut().get_mut().get_mut(),
#[cfg(feature = "bzip2")]
Bzip2(w) => w.get_mut().get_mut(),
#[cfg(feature = "zstd")]
Zstd(w) => w.get_mut().get_mut(),
#[cfg(feature = "xz")]
Xz(w) => w.inner_mut().get_mut(),
#[cfg(feature = "ppmd")]
Ppmd(w) => w.get_mut().get_mut(),
}
}
}
}
#[doc(inline)]
pub use self::sealed::FileOptionExtension;
Expand Down Expand Up @@ -2142,6 +2210,16 @@ impl<W: Write> StreamWriter<W> {
}
}

/// Gets a reference to the underlying writer.
pub fn get_ref(&self) -> &W {
&self.inner
}

/// Gets a mutable reference to the underlying writer.
pub fn get_mut(&mut self) -> &mut W {
&mut self.inner
}

/// Consumes this wrapper, returning the underlying writer.
pub fn into_inner(self) -> W {
self.inner
Expand Down
10 changes: 10 additions & 0 deletions src/zipcrypto.rs
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,16 @@ pub(crate) struct ZipCryptoWriter<W> {
pub(crate) keys: ZipCryptoKeys,
}
impl<W: std::io::Write> ZipCryptoWriter<W> {
/// Gets a reference to the underlying writer.
pub fn get_ref(&self) -> &W {
&self.writer
}

/// Gets a mutable reference to the underlying writer.
pub fn get_mut(&mut self) -> &mut W {
&mut self.writer
}

#[allow(unused)]
pub(crate) fn finish(mut self, crc32: u32) -> std::io::Result<W> {
self.buffer[11] = (crc32 >> 24) as u8;
Expand Down