Expand description
Generator for ZIP files.
fn doit() -> zip::result::ZipResult<()>
{
use std::io::Write;
// For this example we write to a buffer, but normally you should use a File
let mut buf: &mut [u8] = &mut [0u8; 65536];
let mut w = std::io::Cursor::new(buf);
let mut zip = zip::ZipWriter::new(w);
let options = zip::write::FileOptions::default().compression_method(zip::CompressionMethod::Stored);
zip.start_file("hello_world.txt", options)?;
zip.write(b"Hello, World!")?;
// Optionally finish the zip. (this is also done on drop)
zip.finish()?;
Ok(())
}
println!("Result: {:?}", doit().unwrap());
Implementations
sourceimpl<W: Write + Seek> ZipWriter<W>
impl<W: Write + Seek> ZipWriter<W>
sourcepub fn new(inner: W) -> ZipWriter<W> ⓘ
pub fn new(inner: W) -> ZipWriter<W> ⓘ
Initializes the ZipWriter.
Before writing to this object, the start_file command should be called.
sourcepub fn start_file<S>(&mut self, name: S, options: FileOptions) -> ZipResult<()>where
S: Into<String>,
pub fn start_file<S>(&mut self, name: S, options: FileOptions) -> ZipResult<()>where
S: Into<String>,
Starts a file.
sourcepub fn add_directory<S>(&mut self, name: S, options: FileOptions) -> ZipResult<()>where
S: Into<String>,
pub fn add_directory<S>(&mut self, name: S, options: FileOptions) -> ZipResult<()>where
S: Into<String>,
Add a directory entry.
You can’t write data to the file afterwards.
Trait Implementations
sourceimpl<W: Write + Seek> Write for ZipWriter<W>
impl<W: Write + Seek> Write for ZipWriter<W>
sourcefn write(&mut self, buf: &[u8]) -> Result<usize>
fn write(&mut self, buf: &[u8]) -> Result<usize>
Write a buffer into this writer, returning how many bytes were written. Read more
sourcefn flush(&mut self) -> Result<()>
fn flush(&mut self) -> Result<()>
Flush this output stream, ensuring that all intermediately buffered
contents reach their destination. Read more
sourcefn is_write_vectored(&self) -> bool
fn is_write_vectored(&self) -> bool
🔬This is a nightly-only experimental API. (
can_vector
)1.0.0 · sourcefn write_all(&mut self, buf: &[u8]) -> Result<(), Error>
fn write_all(&mut self, buf: &[u8]) -> Result<(), Error>
Attempts to write an entire buffer into this writer. Read more
sourcefn write_all_vectored(&mut self, bufs: &mut [IoSlice<'_>]) -> Result<(), Error>
fn write_all_vectored(&mut self, bufs: &mut [IoSlice<'_>]) -> Result<(), Error>
🔬This is a nightly-only experimental API. (
write_all_vectored
)Attempts to write multiple buffers into this writer. Read more
Auto Trait Implementations
impl<W> RefUnwindSafe for ZipWriter<W>where
W: RefUnwindSafe,
impl<W> Send for ZipWriter<W>where
W: Send,
impl<W> Sync for ZipWriter<W>where
W: Sync,
impl<W> Unpin for ZipWriter<W>where
W: Unpin,
impl<W> UnwindSafe for ZipWriter<W>where
W: UnwindSafe,
Blanket Implementations
sourceimpl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more