Skip to content

Zip64 support, and pre-calculating zip size! #7

@jhodges10

Description

@jhodges10

Hey there! I'm loving this library for my fastapi + zipstream approach to generating zips on the fly. The only drawback is that I'm hitting the 4GB file limit because I'm trying to zip image sequences up.

Any chance I could convince you to take a stab at that?

By the way, you can pre-calculate the size of zip files beforehand using this function. It's very helpful when using this with something like fastapi because you can set the content-length header in the response so you get progress in the browser. You have to get this perfect for the download to work properly though.

So if you do end up wanting to tackle zip64, we'll have to figure out the different padding amounts that go with that.

def calculate_zip_size(zip_queue: ZipQueue) -> int:
    # This is pretty hard to do, directions found here though!
    # https://stackoverflow.com/questions/10927442/calculate-size-of-zip-file-with-compression-level-0/19380600
    
    file_count = 0
    total_size = 0
    filename_chars = ""
    for file in zip_queue:
        info = os.stat(file['file']) # load file info
        total_size += info.st_size # size in bytes
        filename_chars += file['name'] # filename
        file_count += 1

    return file_count * (30+16+46) + 2 * len(filename_chars) + total_size + 22

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions