zipfly

sandesMIT长期未更新

用 Python 流式生成 ZIP 文件,边写边发,不用把整个压缩包读进内存,适合大文件或内存紧张的场景。

Python Zip Stream

v6.0.5发布于 2022-10-20 05:35 UTC528star25fork同步于 2026-11-07 07:33 UTC

怎么上手

由 README 提炼,执行前请确认
pip3 install zipfly
硬件要求按 README 说明

README 未说明,纯 Python 库,无 GPU 或显存要求

下载:源码 zip·GitHub Releases(安装包)本站不镜像安装包

项目说明

由 README 自动翻译提炼

基于 zipfile.py 的 ZIP 流式生成器,边读边写超大压缩包,不占内存

用 Python 流式生成 ZIP 文件,边写边发,不用把整个压缩包读进内存,适合大文件或内存紧张的场景。

核心能力

  • 以生成器逐块产出 ZIP 数据,默认每 32KB 写出一次
  • 支持写入不可 seek 的流,可直接边生成边推给客户端
  • 通过 paths 列表指定文件系统路径与包内文件名
  • 内置 BufferPredictionSize 可在生成前预估压缩包大小
  • 支持 Zip64、自定义压缩级别与压缩包注释

容易踩的坑

需 Python 3.6+,低版本不支持写入不可 seek 流;默认压缩方式为 Stored(不压缩),要压缩需自行设置 compression 与 compresslevel;paths 中每项必须给出 fs 路径,否则无法读取源文件

内容由模型根据 README 生成,可能不完整或不准确,以官方文档为准。看原文 README

最近发版

5 个版本v6.0.5
  1. v6.0.5最新正式版2022-10-20 · 2022-10-20 05:35 UTC

    这个版本没有写更新说明。

  2. v6.0.42022-10-19 · 2022-10-19 16:19 UTC

    这个版本没有写更新说明。

  3. v6.0.32020-05-28 · 2020-05-28 09:12 UTC

    这个版本没有写更新说明。

  4. v6.0.22020-05-27 · 2020-05-27 16:46 UTC

    这个版本没有写更新说明。

  5. v6.0.12020-05-25 · 2020-05-25 04:44 UTC

    这个版本没有写更新说明。

用户点评

登录用户的真实使用记录,可按版本和硬件筛选
共 0 条

    还没有人点评。第一个说出真实体验的人最有价值。

    README 原文

    未翻译

    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

    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:

    .
    fsShould 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)
    
        import zipfly
    
        paths = [
            {
                'fs': '/path/to/large/file'
            },
        ]
    
        zfly = zipfly.ZipFly(paths = paths)
    
        generator = zfly.generator()
        print (generator)
        # <generator object ZipFly.generator at 0x7f74d52bcc50>
    
    
        with open("large.zip", "wb") as f:
            for i in generator:
                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