zipfile extracting png files corrupt
davea at ieee.org
Sat Oct 17 13:24:46 CEST 2009
marks542004 at yahoo.com wrote:
> Hi, I am using the zipfile in Python 2.4 to extract files from
> existing zips.
> It appears to work but the files extracted are corrupt.
Have you done any analysis to see in what sense they are corrupt? For
example, do text files work, but not binary ones? If the file fragment
is small, are you getting a zero-length file out? Is the filesize
> Here is my code :
> import zipfile
> import os, sys , shutil
> epath = "c:/ziptest/"
> fil = "J:/archives/xzips/duplicates/gothicfence_1470.zip"
> ferr = file((epath + "/errlog.txt"),"w")
> print "Extracting to ",epath
> if zipfile.is_zipfile(fil):
> z = zipfile.ZipFile(fil,"r")
> nmes = z.namelist()
> for i in nmes:
> fn = os.path.split(i)
> print "...",fn
> dta = z.read(i)
You read the data here, but don't use it. So the subsequent read below
presumably misses this first part of the data.
> if len(dta) >0 :
> enam = epath + fn
> fo = file(enam,"wb")
> myerr = fil +"," + str(sys.exc_info()) +"\n"
> any ideas ? thanks
In addition, I don't know if Zipfile.read() might return only a portion
of the file. If so, you'll need to make a loop instead of a simple if
in that final fragment.
More information about the Python-list