Sign HN: Stream-zip – Stream-assemble ZIP archives in Python

46
Sign HN: Stream-zip – Stream-assemble ZIP archives in Python

Python feature to assemble a ZIP archive on the fly – with out having to store the total ZIP in memory or disk. This is precious in memory-constrained environments, or whereas it is possible you’ll perchance well fancy to open returning compressed records before you have even retrieved the total uncompressed records. Producing ZIPs on-interrogate in a web based server is a conventional use case for circulation-zip.

Presents an identical performance to zipfly, but with a definite API, and does not use Python’s zipfile module beneath the hood.

To unZIP info on the fly try circulation-unzip.

Set up

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)

Barriers

Or not it is miles impossible to fully circulation-write ZIP info. Diminutive bits of metadata for every member file, equivalent to its name, must be placed at the dwell of the ZIP. In repeat to retain out this, circulation-unzip buffers this metadata in memory till it goes to also be output.

Join the pack! Join 8000+ others registered users, and derive chat, build groups, put up updates and build pals across the world!
www.knowasiak.com/register/

Charlie Layers
WRITTEN BY

Charlie Layers

Fill your life with experiences so you always have a great story to tell