Copying a ZipExtFile

Moore, Mathew L MooreML at BATTELLE.ORG
Mon Oct 26 10:36:14 EDT 2009


> En Fri, 23 Oct 2009 14:15:33 -0300, Moore, Mathew L
> <MooreML at battelle.org>
> escribió:
> 
> >     with io.BytesIO() as memio:
> >         shutil.copyfileobj(f, memio)
> >         zip = zipfile.ZipFile(file=memio)
> >         # Can't use zip.extract(), because I want to ignore paths
> >         # within archive.
> >         src = zip.open('unknowndir/src.txt')
> >         with open('dst.txt', mode='wb') as dst:
> >             shutil.copyfileobj(src, dst)
> >
> >
> > The last line throws an Error:
> >
> >
> > Traceback (most recent call last):
> >   File "test.py", line 25, in <module>
> >     shutil.copyfileobj(src, dst)
> >   File "C:\Python26\lib\shutil.py", line 27, in copyfileobj
> >     buf = fsrc.read(length)
> >   File "C:\Python26\lib\zipfile.py", line 594, in read
> >     bytes = self.fileobj.read(bytesToRead)
> > TypeError: integer argument expected, got 'long'
> 
> Try adding a length parameter to the copyfileobj call, so the copy is
> done in small enough chunks.
> 


Hmmm...tried a variety of lengths (512, 1024, etc.) with no luck.  Maybe this is a good opportunity for me to learn some Python debugging tools.

Thanks!
--Matt




More information about the Python-list mailing list