zipfile extracting png files corrupt

M

marks542004

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.
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
try:
if zipfile.is_zipfile(fil):
z = zipfile.ZipFile(fil,"r")
nmes = z.namelist()
for i in nmes:
fn = os.path.split(i)[1]
print "...",fn
dta = z.read(i)
if len(dta) >0 :
enam = epath + fn
fo = file(enam,"wb")
fo.write(z.read(i))
fo.flush()
fo.close()
except:
myerr = fil +"," + str(sys.exc_info()[1]) +"\n"
ferr.write(myerr)
ferr.close()

any ideas ? thanks
 
G

Gabriel Genellina

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 tested the zip files with other tools? I can't spot anything
obviously wrong in your code (except a tendency to shrten vrble nmes :) )
 
D

Dave Angel

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
always wrong?
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
try:
if zipfile.is_zipfile(fil):
z = zipfile.ZipFile(fil,"r")
nmes = z.namelist()
for i in nmes:
fn = os.path.split(i)[1]
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")
fo.write(z.read(i))
fo.flush()
fo.close()
except:
myerr = fil +"," + str(sys.exc_info()[1]) +"\n"
ferr.write(myerr)
ferr.close()

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Members online

Forum statistics

Threads
473,766
Messages
2,569,569
Members
45,042
Latest member
icassiem

Latest Threads

Top