unzipping a zipx file

B

b_erickson1

I have python 2.6.2 and I trying to get it to unzip a file made with winzippro. The file extension is zipx. This is on a windows machine where I have to send them all that files necessary to run. I am packaging this with py2exe. I can open the file with
zFile = zipfile.ZipFile(fullPathName,'r')
and I can look through all the file in the archive
for filename in zFile.namelist():
but when I write the file out with this code:
ozFile = open(filename,'w')
ozFile.write(zFile.read(filename))
ozFile.close()
that file still looks encrypted. No errors are thrown. The file is just atext file not a jpeg or anything else. I can open the file with 7zip and extract the text file out just fine.


What am I missing?

Thanks
 
J

John Gordon

In said:
ozFile = open(filename,'w')
ozFile.write(zFile.read(filename))
ozFile.close()

Perhaps you want to use zFile.extract() instead of zFile.read()?
 
J

John Gordon

Perhaps you want to use zFile.extract() instead of zFile.read()?

No, that's not it. Your code should work.

You said the output file 'looks encrypted'. Is the source zip file
encrypted?

Is the source text file something other than plain ASCII?
 
S

Steven D'Aprano

I have python 2.6.2 and I trying to get it to unzip a file made with
winzip pro. The file extension is zipx. This is on a windows machine
where I have to send them all that files necessary to run. I am
packaging this with py2exe. I can open the file with zFile =
zipfile.ZipFile(fullPathName,'r') and I can look through all the file in
the archive for filename in zFile.namelist():
but when I write the file out with this code:
ozFile = open(filename,'w')
ozFile.write(zFile.read(filename))
ozFile.close()
that file still looks encrypted. No errors are thrown. The file is
just a text file not a jpeg or anything else. I can open the file with
7zip and extract the text file out just fine.


What am I missing?


You are missing that zipx is not the same as zip, and Python very likely
does not support the zipx compression algorithm.

http://kb.winzip.com/kb/entry/7/

My guess is that the zipx header is similar enough to zip that Python can
retrieve the file names, but it cannot decompress the files.
Unfortunately, instead of getting a nice error, it is fooled into
thinking that it decompressed when in fact you just got junk.


I suggest that you start with a simple example: create a plain text file
with just a few words. Compress this single file to .zipx, then try to
decompress it using Python. If it still fails, you will have a simple
example that you could post here and see if others have more success.
 
D

Dave Angel

You are missing that zipx is not the same as zip, and Python very likely
does not support the zipx compression algorithm.

http://kb.winzip.com/kb/entry/7/

My guess is that the zipx header is similar enough to zip that Python can
retrieve the file names, but it cannot decompress the files.
Unfortunately, instead of getting a nice error, it is fooled into
thinking that it decompressed when in fact you just got junk.

The zip header includes a 32bit CRC for each file. Do you know whether
the zip module checks that CRC ?
 

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

Members online

Forum statistics

Threads
473,836
Messages
2,569,750
Members
45,545
Latest member
rapter____0

Latest Threads

Top