Struct zip::write::ZipWriter

source ·
pub struct ZipWriter<W: Write + Seek> { /* private fields */ }
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

Initializes the ZipWriter.

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

Starts a file.

Add a directory entry.

You can’t write data to the file afterwards.

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

Executes the destructor for this type. Read more
Write a buffer into this writer, returning how many bytes were written. Read more
Flush this output stream, ensuring that all intermediately buffered contents reach their destination. Read more
Like write, except that it writes from a slice of buffers. Read more
🔬This is a nightly-only experimental API. (can_vector)
Determines if this Writer has an efficient write_vectored implementation. Read more
Attempts to write an entire buffer into this writer. Read more
🔬This is a nightly-only experimental API. (write_all_vectored)
Attempts to write multiple buffers into this writer. Read more
Writes a formatted string into this writer, returning any error encountered. Read more
Creates a “by reference” adapter for this instance of Write. Read more

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more
Immutably borrows from an owned value. Read more
Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

The type returned in the event of a conversion error.
Performs the conversion.
The type returned in the event of a conversion error.
Performs the conversion.
Write a u64
Write a u32
Write a u16
Write a u8
Write a i64
Write a i32
Write a i16
Write a i8
Write a f32
Write a f64