Skip to main content

Stream zip64 archives on the fly.

Project description

ZipFly

forthebadge forthebadge forthebadge

Build Status Build Status Build Status Build Status

ZipFly is a library for creating & streaming ZIP64 archives "on the fly"

It allows to create/fetch file content dynamically while the archive is streamed.

  • No temporary files, data is streamed directly
  • Ability to calculate archive size before streaming even begins
  • Supported deflate compression method
  • Small memory usage, streaming is done using yield statement
  • Archive structure is created on the fly, and all data can be created during stream
  • Files included into archive can be generated on the fly using Python generators
  • Independent of the goofy 🤮🤮 python's standard ZipFile implementation
  • No dependencies
  • Automatic detection and changing of duplicate names
  • Zip64 format compatible files

This library is based upon this library (this library was a piece of work...)

Typical Usage

from zipFly import ZipFly, LocalFile, consts
# compression_method is optional, defaults to consts.NO_COMPRESSION
file1 = LocalFile(file_path='files/lqbfa61deebf1.mp4', compression_method=consts.NO_COMPRESSION) #  or consts.COMPRESSION_DEFLATE 
file2 = LocalFile(file_path='public/2ae9dcd01a3aa.mp4', name="files/my_file2.mp4")  # override the file name
file3 = LocalFile(file_path='files/4shaw1dax4da.mp4', name="my_file3.mp4")  # you control the directory path by specifying it in name

files = [file1, file2, file3]

zipFly = ZipFly(files)

# save to file, or do something else with the stream() generator
with open("out/file.zip", 'wb') as f_out:
    for chunk in zipFly.stream():
        f_out.write(chunk)

Supports dynamically created files

from zipFly import ZipFly, GenFile, LocalFile, consts


def file_generator():
    yield b"uga buga"
    yield b"a29jaGFtIGFsdGVybmF0eXdraQ=="
    yield b"2137"
    
# size is optional, it allows to calculate the total size of the archive before any data is generated
# modification_time in epoch time, defaults to time.time()
file1 = GenFile(name="file.txt", generator=file_generator(), modification_time=time.time(), size=size, compression_method=consts.COMPRESSION_DEFLATE)
file2 = LocalFile(file_path='files/as61aade2ebfd.mp4', compression_method=consts.NO_COMPRESSION) #  or consts.COMPRESSION_DEFLATE 

files = [file1, file2]

zipFly = ZipFly(files)
archive_size = zipFly.calculate_archive_size() # raises ValueError if it can't calculate size

# for example you can set as content length in http response
response['Content-Length'] = archive_size

for chunk in zipFly.stream():
       # do something

Other

I created this library for my I Drive project.

If you have a different case scenario, and LocalFile and GenFile are not enough, you can extend BaseFile and everything else should work out of the box.

PS

I wholeheartedly hope everyone responsible for creating ZIP documentation gets slaughtered in the most gore and painful way 😊 (in game)

(pls redo ur docs)

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

zipfly64-1.0.0.tar.gz (12.2 kB view details)

Uploaded Source

Built Distribution

zipFly64-1.0.0-py3-none-any.whl (12.6 kB view details)

Uploaded Python 3

File details

Details for the file zipfly64-1.0.0.tar.gz.

File metadata

  • Download URL: zipfly64-1.0.0.tar.gz
  • Upload date:
  • Size: 12.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.12.6

File hashes

Hashes for zipfly64-1.0.0.tar.gz
Algorithm Hash digest
SHA256 803fb0197d19d4d363636301c1e4b141377c55cabaa78b44c091688cbd8dfe1d
MD5 cba8fa3c58506d28c1ef530124d8f707
BLAKE2b-256 ea16e1354e43a34b47544cd8e59ba0d2298dce5d864579a31fb913b39aeb453f

See more details on using hashes here.

File details

Details for the file zipFly64-1.0.0-py3-none-any.whl.

File metadata

  • Download URL: zipFly64-1.0.0-py3-none-any.whl
  • Upload date:
  • Size: 12.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.12.6

File hashes

Hashes for zipFly64-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 6f4405a609d70747e2349af80b6ea16b3c39c019b45c290a9957a551d9657e43
MD5 c70cdb507588734dca0e6e4a470ebb86
BLAKE2b-256 51d0b717d0dc27069452a43a802bdb765618334be25229d155ee66f44f90d9ba

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page