Python – Writing large ZIP archives without memory inflation

栏目: IT技术 · 发布时间: 5年前

内容简介:ZipFly is a zip archive generator based on zipfile.py. It was created by Buzon.io to generate very large ZIP archives for immediate sending out to clients, or for writing large ZIP archives without memory inflation.Python 3.5+Basic use case is compressing

Buzon - ZipFly

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

Requirements

Python 3.5+

Install

pip3 install zipfly

Basic usage, compress on-the-fly during writes

Basic use case is compressing on the fly. Some data will be buffered by the zipfile deflater, but memory inflation is going to be very constrained. Data will be written to destination at fairly regular intervals.

ZipFly default attributes:

  • paths: [ ]
  • mode: w
  • chunksize: (bytes) 16384
  • compression: Stored
  • allowZip64: True
  • compresslevel: None
  • storesize: (bytes) 0

paths list of dictionaries:

  • fs (filesystem): path from your disk
  • n (name): final path in zip file
import zipfly
    
    paths = [ 
        {
            'fs': 'home/user/Videos/jupiter.mp4', 
            'n': 'movies/jupiter.mp4', 
        },       
        {
            'fs': 'home/user/Documents/mercury.mp4', 
            'n': 'movies/mercury.mp4', 
        },          
    ]

    zfly = zipfly.ZipFly( paths = paths )

    generator = zfly.generator()
    print ( generator )
    # <generator object generator at 0x7f85aad60b13>

    with open("test.zip", "wb") as f:
        for i in generator:
            f.write(i)

Examples

Create a ZIP file with size estimation Use the BufferPredictionSize to compute the correct size of the resulting archive.

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

Streaming multiple files in a zip The easiest is to use the Django or Flask built-in streaming feature

Maintainer

Santiago Debus (@santiagodebus.com)

Santiago's open-source projects are supported by his Patreon. If you found this project helpful, any monetary contributions to the Patreon are appreciated and will be put to good creative use.

License

This library was created by Buzon.io and is released under the MIT. Copyright 2019 Grow HQ, Inc.


以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持 码农网

查看所有标签

猜你喜欢:

本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们

Linux C编程一站式学习

Linux C编程一站式学习

宋劲杉 / 电子工业出版社 / 2009-12 / 60.00元

本书有两条线索,一条线索是以Linux平台为载体全面深入地介绍C语言的语法和程序的工作原理,另一条线索是介绍程序设计的基本思想和开发调试方法。本书分为两部分:第一部分讲解编程语言和程序设计的基本思想方法,让读者从概念上认识C语言;第二部分结合操作系统和体系结构的知识讲解程序的工作原理,让读者从本质上认识C语言。. 本书适合做零基础的初学者学习C语言的第一本教材,帮助读者打下牢固的基础。有一定......一起来看看 《Linux C编程一站式学习》 这本书的介绍吧!

JSON 在线解析
JSON 在线解析

在线 JSON 格式化工具

Markdown 在线编辑器
Markdown 在线编辑器

Markdown 在线编辑器

html转js在线工具
html转js在线工具

html转js在线工具