[Patches] [ python-Patches-503592 ] Add method readfile() to class ZipFile

noreply@sourceforge.net noreply@sourceforge.net
Mon, 21 Jan 2002 01:10:37 -0800


Patches item #503592, was opened at 2002-01-14 15:04
You can respond by visiting: 
http://sourceforge.net/tracker/?func=detail&atid=305470&aid=503592&group_id=5470

Category: Library (Lib)
Group: None
>Status: Closed
>Resolution: Rejected
Priority: 5
Submitted By: Branko Cibej (brane)
Assigned to: Nobody/Anonymous (nobody)
Summary: Add method readfile() to class ZipFile

Initial Comment:
The ZipFile class doesn't provide a method to read
bytes from the
archive directly to a disk-based file. That's
unfortunate, because
reading large files from a zip file using the read()
method will burn
about twice the file size amount of RAM. This patch
adds a readfile()
method that reads small chunks of the archived file and
writes them
directly to disk.


Changes to class ZipFile (src/Lib/zipfile.py):

- New attribute _chunk_size: readfile() and write() use
this to
  calculate the read/write buffer sizes.

- New method _readcheck: Like _writecheck, but used for
error checking
  before reading from the archive.

- Changes to read(): Factor out error checking and call
_readcheck().

- Changes to write(): Use self._chunk_size as the read
size instead
  of a hard-coded value.

- New method readfile().


Changes to the docs (src/Doc/lib/libzipfile.tex):

- Document ZipFile.readfile().


----------------------------------------------------------------------

>Comment By: Martin v. Löwis (loewis)
Date: 2002-01-21 01:10

Message:
Logged In: YES 
user_id=21627

Ok, I'll reject this patch, then. If you ever find time for
this issue, please submit a new patch.

----------------------------------------------------------------------

Comment By: Branko Cibej (brane)
Date: 2002-01-20 17:12

Message:
Logged In: YES 
user_id=427248

Yes, that would make sense, for both reading and writing.
The exitsing methods could even be reimplemented on top of
such a file-like object.

And it would be nice to have a way to _replace_ the contents
of an entry in the zip file.

If only i had enough time for all that ... but since I don't,
and I needed a way to reduce my script's memory footprint
from 60 megs to 6, this patch is the result.


----------------------------------------------------------------------

Comment By: Martin v. Löwis (loewis)
Date: 2002-01-16 03:44

Message:
Logged In: YES 
user_id=21627

I'd rather prefer a different solution: create a .open()
method on ZipFile opjects, which return file-like objects.
With that, you can shutils.copyfileobj to achive what you want.

----------------------------------------------------------------------

You can respond by visiting: 
http://sourceforge.net/tracker/?func=detail&atid=305470&aid=503592&group_id=5470