Python function to construct a ZIP archive with stream processing - without having to store the entire ZIP in memory or disk
Project description
stream-zip
Python function to construct a ZIP archive on the fly - without having to store the entire ZIP in memory or disk. This is useful in memory-constrained environments, or when you would like to start returning compressed data before you've even retrieved all the uncompressed data. Generating ZIPs on-demand in a web server is a typical use case for stream-zip.
Offers similar functionality to zipfly, but with a different API, and does not use Python's zipfile module under the hood.
To unZIP files on the fly try stream-unzip.
Installation
pip install stream-zip
Usage
from datetime import datetime
from stream_zip import stream_zip
def unzipped_files():
modified_at = datetime.now()
perms = 0o600
def file_1_data():
yield b'Some bytes'
def file_2_data():
yield b'Some bytes'
yield 'my-file-1.txt', modified_at, perms, file_1_data()
yield 'my-file-2.txt', modified_at, perms, file_2_data()
for zipped_chunk in stream_zip(unzipped_files()):
print(zipped_chunk)
Limitations
It's not possible to completely stream-write ZIP files. Small bits of metadata for each member file, such as its name, must be placed at the end of the ZIP. In order to do this, stream-unzip buffers this metadata in memory until it can be output.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Hashes for stream_zip-0.0.9-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1d62f0fb5d2eef0f7e483fddfc15545e3e340001269caf6bcfb64afc8f21388b |
|
MD5 | 016c325031ec07e95d3d655232157e0d |
|
BLAKE2b-256 | f388cf1fbdd4ef3504db2fc47d7b752799e95f81a322d7aa8efd5b63385d4ea9 |