Skip to main content

Crate zippity

Crate zippity 

Source
Expand description

§Zippity

Library for asynchronously creating a ZIP file on the fly.

CI Docs Coverage Status

§Features

  • Async, using tokio.
  • ZIP is created on the fly, can be directly streamed somewhere, does not need to be stored in RAM or on disk
  • Supports Zip64 (files > 4GB).
  • File size is known in advance
  • Output is driven from outside (implements tokio::io::AsyncRead)
  • Allows seeking in the file (implements tokio::io::AsyncSeek)
  • Supports files on the filesystem as entries (feature tokio-file)
  • Supports integration with Actix Web (feature actix-web)

§Non-features

These are not currently planned:

  • Compression: The zip only uses store method.
  • Encryption
  • Zip reading

§Example


use std::io::SeekFrom;
use tokio::io::{AsyncSeekExt, AsyncWriteExt, copy, sink};

tokio_test::block_on(async {

// Create the builder
let mut builder = zippity::Builder::<&[u8]>::new();

// Add data
builder.add_entry("Entry name".to_owned(), b"Entry data".as_slice()).unwrap();

// Build the reader object
// Note that this does not touch the data yet.
let mut zippity = builder.build();

// Getting file size is in O(1)
println!("Total zip file size will be {}B", zippity.size());

// Seek to last 10B
zippity.seek(SeekFrom::End(-10)).await.unwrap();

// Write to output (in this case a sink, throwing it away)
copy(&mut zippity, &mut sink()).await.unwrap();

})

§Crate features

NameDescriptionDefault
tokio-fileAdds support for FilesystemEntry being used as a entry data, based on Tokio::File.yes
bytesProvide method Bytes::into_bytes_stream().no
actix-webAddsactix_web::Reponder implementation to zippity::Readerno
chronoSupport for setting last modification date and time metadata using types from chrono.no

§Current state

The library is fully functional. I’m now waiting for some experience with the final integration into other projects (and perhaps some user feedback) before releasing stable version 1.0.

Structs§

Builder
Represents entries of the zip file, which can be converted to a Reader.
BuilderEntry
Represents a ZIP file entry in the metadata building phase. Reference to this struct is returned when adding a new entry and allows modifying its metadata.
FilesystemEntry
An EntryData implementation representing a filesystem object – file, directory or symlink.
Reader
Main entry point for reading a zip file.

Enums§

AddDirectoryRecursiveError
An error that can be encountered while recursively adding directories to a Builder.
AddEntryError
An error that can be encountered while adding entries to a Builder.
AddFilesystemEntryError
An error that can be encountered while adding filesystem entries to a Builder.
ReadError
Represents an error that can occur during ZIP file reading or seeking.

Traits§

EntryData
A trait for types that can be used as an entry in a ZIP file.