[][src]Struct zip::write::ZipWriter

pub struct ZipWriter<W: Write + Seek> { /* fields omitted */ }

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());

Methods

impl<W: Write + Seek> ZipWriter<W>[src]

Important traits for ZipWriter<W>
pub fn new(inner: W) -> ZipWriter<W>[src]

Initializes the ZipWriter.

Before writing to this object, the start_file command should be called.

pub fn start_file<S>(&mut self, name: S, options: FileOptions) -> ZipResult<()> where
    S: Into<String>, 
[src]

Starts a file.

pub fn start_file_from_path(
    &mut self,
    path: &Path,
    options: FileOptions
) -> ZipResult<()>
[src]

Starts a file, taking a Path as argument.

This function ensures that the '/' path seperator is used. It also ignores all non 'Normal' Components, such as a starting '/' or '..' and '.'.

pub fn add_directory<S>(
    &mut self,
    name: S,
    options: FileOptions
) -> ZipResult<()> where
    S: Into<String>, 
[src]

Add a directory entry.

You can't write data to the file afterwards.

pub fn add_directory_from_path(
    &mut self,
    path: &Path,
    options: FileOptions
) -> ZipResult<()>
[src]

Add a directory entry, taking a Path as argument.

This function ensures that the '/' path seperator is used. It also ignores all non 'Normal' Components, such as a starting '/' or '..' and '.'.

pub fn finish(&mut self) -> ZipResult<W>[src]

Finish the last file and write all other zip-structures

This will return the writer, but one should normally not append any data to the end of the file. Note that the zipfile will also be finished on drop.

Trait Implementations

impl<W: Write + Seek> Drop for ZipWriter<W>[src]

impl<W: Write + Seek> Write for ZipWriter<W>[src]

fn write_vectored(&mut self, bufs: &[IoSlice]) -> Result<usize, Error>1.36.0[src]

Like write, except that it writes from a slice of buffers. Read more

fn write_all(&mut self, buf: &[u8]) -> Result<(), Error>1.0.0[src]

Attempts to write an entire buffer into this writer. Read more

fn write_fmt(&mut self, fmt: Arguments) -> Result<(), Error>1.0.0[src]

Writes a formatted string into this writer, returning any error encountered. Read more

fn by_ref(&mut self) -> &mut Self1.0.0[src]

Creates a "by reference" adaptor for this instance of Write. Read more

Auto Trait Implementations

impl<W> Sync for ZipWriter<W> where
    W: Sync

impl<W> Send for ZipWriter<W> where
    W: Send

impl<W> Unpin for ZipWriter<W> where
    W: Unpin

impl<W> RefUnwindSafe for ZipWriter<W> where
    W: RefUnwindSafe

impl<W> UnwindSafe for ZipWriter<W> where
    W: UnwindSafe

Blanket Implementations

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<W> WritePodExt for W where
    W: Write
[src]