#zip-file #tokio #fly #io #file-io #size #entries

zippity

Library for asynchronously creating a ZIP file on the fly

1 unstable release

0.3.0 Oct 7, 2024
0.2.0 Jul 28, 2024

#218 in Compression

Download history 7/week @ 2024-09-14 4/week @ 2024-09-21 6/week @ 2024-09-28 140/week @ 2024-10-05 20/week @ 2024-10-12

110 downloads per month

MIT license

125KB
3K SLoC

Zippity

Library for asynchronously creating a ZIP file on the fly.

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.
    • Supports tokio_uring
  • Supports integration with Actix Web (see [Reader::into_responder()])
  • Entry metadata

Non-features

These are not planned to be implemented.

  • 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()).await.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();

})

Current state

Consider this a beta version. The library is mostly finished, with lot of polish missing for version 1.0.0.

Crate features

Name Description Default
tokio-file Adds support for TokioFileEntry being used as a entry data through Tokio file. yes
bytes Implement EntryData for bytes::Bytes, and provide method into_bytes_stream() for Reader. no
actix-web Addsactix_web::Reponder implementation to zippity::Reader no
proptest Add module zippity::proptest, with strategies, and proptest::arbitrary::Arbitrary implementation for Reader. no

Dependencies

~4–16MB
~207K SLoC