pub struct Archive<W> { /* private fields */ }
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>
impl<W> Archive<W>
Sourcepub async fn futures_append<R>(
&mut self,
name: String,
datetime: FileDateTime,
reader: &mut R,
) -> Result<(), IoError>
Available on crate features futures-async-io
and tokio-async-io
only.
pub async fn futures_append<R>( &mut self, name: String, datetime: FileDateTime, reader: &mut R, ) -> Result<(), IoError>
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.
Sourcepub async fn futures_finalize(self) -> Result<W, IoError>where
W: AsyncWrite + Unpin,
Available on crate features futures-async-io
and tokio-async-io
only.
pub async fn futures_finalize(self) -> Result<W, IoError>where
W: AsyncWrite + Unpin,
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>
impl<W> Archive<W>
Sourcepub async fn tokio_append<R>(
&mut self,
name: String,
datetime: FileDateTime,
reader: &mut R,
) -> Result<(), IoError>
Available on crate features futures-async-io
and tokio-async-io
only.
pub async fn tokio_append<R>( &mut self, name: String, datetime: FileDateTime, reader: &mut R, ) -> Result<(), IoError>
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.
Sourcepub async fn tokio_finalize(self) -> Result<W, IoError>where
W: AsyncWrite + Unpin,
Available on crate features futures-async-io
and tokio-async-io
only.
pub async fn tokio_finalize(self) -> Result<W, IoError>where
W: AsyncWrite + Unpin,
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.