Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 86701
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 10, 20262026-05-10T22:17:15+00:00 2026-05-10T22:17:15+00:00

I’ve got a large amount of data (a couple gigs) I need to write

  • 0

I’ve got a large amount of data (a couple gigs) I need to write to a zip file in Python. I can’t load it all into memory at once to pass to the .writestr method of ZipFile, and I really don’t want to feed it all out to disk using temporary files and then read it back.

Is there a way to feed a generator or a file-like object to the ZipFile library? Or is there some reason this capability doesn’t seem to be supported?

By zip file, I mean zip file. As supported in the Python zipfile package.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. 2026-05-10T22:17:15+00:00Added an answer on May 10, 2026 at 10:17 pm

    The only solution is to rewrite the method it uses for zipping files to read from a buffer. It would be trivial to add this to the standard libraries; I’m kind of amazed it hasn’t been done yet. I gather there’s a lot of agreement the entire interface needs to be overhauled, and that seems to be blocking any incremental improvements.

    import zipfile, zlib, binascii, struct class BufferedZipFile(zipfile.ZipFile):     def writebuffered(self, zipinfo, buffer):         zinfo = zipinfo          zinfo.file_size = file_size = 0         zinfo.flag_bits = 0x00         zinfo.header_offset = self.fp.tell()          self._writecheck(zinfo)         self._didModify = True          zinfo.CRC = CRC = 0         zinfo.compress_size = compress_size = 0         self.fp.write(zinfo.FileHeader())         if zinfo.compress_type == zipfile.ZIP_DEFLATED:             cmpr = zlib.compressobj(zlib.Z_DEFAULT_COMPRESSION, zlib.DEFLATED, -15)         else:             cmpr = None          while True:             buf = buffer.read(1024 * 8)             if not buf:                 break              file_size = file_size + len(buf)             CRC = binascii.crc32(buf, CRC) & 0xffffffff             if cmpr:                 buf = cmpr.compress(buf)                 compress_size = compress_size + len(buf)              self.fp.write(buf)          if cmpr:             buf = cmpr.flush()             compress_size = compress_size + len(buf)             self.fp.write(buf)             zinfo.compress_size = compress_size         else:             zinfo.compress_size = file_size          zinfo.CRC = CRC         zinfo.file_size = file_size          position = self.fp.tell()         self.fp.seek(zinfo.header_offset + 14, 0)         self.fp.write(struct.pack('<LLL', zinfo.CRC, zinfo.compress_size, zinfo.file_size))         self.fp.seek(position, 0)         self.filelist.append(zinfo)         self.NameToInfo[zinfo.filename] = zinfo 
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 123k
  • Answers 123k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer I often use Notepad++'s macro function for things like this.… May 12, 2026 at 1:00 am
  • Editorial Team
    Editorial Team added an answer The standard Python list is not sorted in any form.… May 12, 2026 at 1:00 am
  • Editorial Team
    Editorial Team added an answer From MSDN (http://msdn.microsoft.com/en-us/library/ms228606.aspx) A constant-expression is an expression that can… May 12, 2026 at 1:00 am

Related Questions

I ran into a problem. Wrote the following code snippet: teksti = teksti.Trim() teksti
I am currently running into a problem where an element is coming back from
Seemingly simple, but I cannot find anything relevant on the web. What is the
Does anyone know how can I replace this 2 symbol below from the string
Configuring TinyMCE to allow for tags, based on a customer requirement. My config is

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.