Struct Archive

Source
pub struct Archive<W> { /* private fields */ }
Available on crate features futures-async-io or tokio-async-io only.
Expand description

A streamed zip archive.

Create an archive using the new function and a AsyncWrite. Then, append files one by one using the append function. When finished, use the finalize function.

§Example

use std::io::Cursor;
use zipit::{Archive, FileDateTime};

#[tokio::main]
async fn main() {
    let mut archive = Archive::new(Vec::new());
    archive.append(
        "file1.txt".to_owned(),
        FileDateTime::now(),
        &mut Cursor::new(b"hello\n".to_vec()),
    ).await.unwrap();
    archive.append(
        "file2.txt".to_owned(),
        FileDateTime::now(),
        &mut Cursor::new(b"world\n".to_vec()),
    ).await.unwrap();
    let data = archive.finalize().await.unwrap();
    println!("{:?}", data);
}

Implementations§

Source§

impl<W> Archive<W>

Source

pub async fn futures_append<R>( &mut self, name: String, datetime: FileDateTime, reader: &mut R, ) -> Result<(), IoError>
where W: AsyncWrite + Unpin, R: AsyncRead + Unpin,

Available on crate features futures-async-io and tokio-async-io only.

Append a new file to the archive using the provided name, date/time and AsyncRead object. Filename must be valid UTF-8. Some (very) old zip utilities might mess up filenames during extraction if they contain non-ascii characters. File’s payload is not compressed and is given rw-r--r-- permissions.

§Error

This function will forward any error found while trying to read from the file stream or while writing to the underlying sink.

Source

pub async fn futures_finalize(self) -> Result<W, IoError>
where W: AsyncWrite + Unpin,

Available on crate features futures-async-io and tokio-async-io only.

Finalize the archive by writing the necessary metadata to the end of the archive.

§Error

This function will forward any error found while writing to the underlying sink.

Source§

impl<W> Archive<W>

Source

pub async fn tokio_append<R>( &mut self, name: String, datetime: FileDateTime, reader: &mut R, ) -> Result<(), IoError>
where W: AsyncWrite + Unpin, R: AsyncRead + Unpin,

Available on crate features futures-async-io and tokio-async-io only.

Append a new file to the archive using the provided name, date/time and AsyncRead object. Filename must be valid UTF-8. Some (very) old zip utilities might mess up filenames during extraction if they contain non-ascii characters. File’s payload is not compressed and is given rw-r--r-- permissions.

§Error

This function will forward any error found while trying to read from the file stream or while writing to the underlying sink.

Source

pub async fn tokio_finalize(self) -> Result<W, IoError>
where W: AsyncWrite + Unpin,

Available on crate features futures-async-io and tokio-async-io only.

Finalize the archive by writing the necessary metadata to the end of the archive.

§Error

This function will forward any error found while writing to the underlying sink.

Source§

impl<W> Archive<W>

Source

pub fn new(sink: W) -> Self

Create a new zip archive, using the underlying AsyncWrite to write files’ header and payload.

Trait Implementations§

Source§

impl<W: Debug> Debug for Archive<W>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<W> Freeze for Archive<W>
where W: Freeze,

§

impl<W> RefUnwindSafe for Archive<W>
where W: RefUnwindSafe,

§

impl<W> Send for Archive<W>
where W: Send,

§

impl<W> Sync for Archive<W>
where W: Sync,

§

impl<W> Unpin for Archive<W>
where W: Unpin,

§

impl<W> UnwindSafe for Archive<W>
where W: UnwindSafe,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

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

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

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

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.