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.
stream-unzip unconditionally creates ZIP64 files to support sizes bigger than 4GB. Older software may not be able to open these. This may change in later versions.
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.10-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | a4a8f3157519b8b2c353f5bebdf7add1905c67611f8c950ce151ac4d2f12e83c |
|
MD5 | 53740c91dba74abc62aed0e208f7206b |
|
BLAKE2b-256 | 8e0897c8affdc976e90030bbe0be8fc5975b27ddfd459986d7d42a5644fc8b52 |