项目作者: BuzonIO

项目描述 :
Writing large ZIP archives without memory inflation
高级语言: Python
项目地址: git://github.com/BuzonIO/zipfly.git
创建时间: 2020-03-24T01:36:38Z
项目社区:https://github.com/BuzonIO/zipfly

开源协议:MIT License

下载


GitHub Actions Workflow Status
GitHub release (latest by date)
Downloads

ZipFly

ZipFly is a zip archive generator based on zipfile.py.
It was created to generate very large ZIP archives for immediate sending out to clients, or for writing large ZIP archives without memory inflation.

Requirements

Python 3.6+ Added support for writing to unseekable streams.

Install

  1. pip3 install zipfly

Basic usage, compress on-the-fly during writes

Using this library will save you from having to write the Zip to disk. Some data will be buffered by the zipfile deflater, but memory inflation is going to be very constrained. Data will be written to destination by default at regular 32KB intervals.

ZipFly defaults attributes:

  • paths: [ ]
  • mode: (write) w
  • chunksize: (bytes) 32768
  • compression: Stored
  • allowZip64: True
  • compresslevel: None
  • storesize: (bytes) 0
  • encode: utf-8


paths list of dictionaries:

.
fs Should be the path to a file on the filesystem
n (Optional) Is the name which it will have within the archive
(by default, this will be the same as fs)


  1. import zipfly
  2. paths = [
  3. {
  4. 'fs': '/path/to/large/file'
  5. },
  6. ]
  7. zfly = zipfly.ZipFly(paths = paths)
  8. generator = zfly.generator()
  9. print (generator)
  10. # <generator object ZipFly.generator at 0x7f74d52bcc50>
  11. with open("large.zip", "wb") as f:
  12. for i in generator:
  13. f.write(i)

Examples

Streaming multiple files in a zip with Django or Flask
Send forth large files to clients with the most popular frameworks

Create paths
Easy way to create the array paths from a parent folder.

Predict the size of the zip file before creating it
Use the BufferPredictionSize to compute the correct size of the resulting archive before creating it.

Streaming a large file
Efficient way to read a single very large binary file in python

Set a comment
Your own comment in the zip file