Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Accessing .zipx with Python

Tags:

python

zip

I'm attempting to write a very simple script that counts the number of entries/files a given ZIP file has, for some statistics.

I'm using the zipfile library, and I'm running into this problem where the library appears not to support .zipx format.

bash-3.1$ python zipcount.py t.zipx

Traceback (most recent call last):
  File "zipcount.py", line 10, in <module>
    zipCount(file)
  File "zipcount.py", line 5, in zipCount
    with ZipFile(file, "r") as zf:
  File "c:\Python34\lib\zipfile.py", line 937, in __init__
    self._RealGetContents()
  File "c:\Python34\lib\zipfile.py", line 978, in _RealGetContents
    raise BadZipFile("File is not a zip file")
zipfile.BadZipFile: File is not a zip file

Googling for help reveals that the zipx format is not the same as zip, and so maybe I shouldn't be expecting this to work. Further googling though fails to bring up a library that actually can deal with zipx. Searching stack overflow didn't find much either.

I can't possibly be the only person who wants to manipulate zipx files in python, right? Any suggestions?

like image 406
FrobberOfBits Avatar asked Feb 19 '26 06:02

FrobberOfBits


1 Answers

chilkat might work for this. It's not a free library but there is a 30 day trial. Here is an example from http://www.example-code.com/python/ppmd_compress_file.asp:

import sys
import chilkat

compress = chilkat.CkCompression()

#  Any string argument automatically begins a 30-day trial.
success = compress.UnlockComponent("30-day trial")
if (success != True):
    print "Compression component unlock failed"
    sys.exit()

compress.put_Algorithm("ppmd")

#  Decompress back to the original:
success = compress.DecompressFile("t.zipx", "t")
if (success != True):
    print compress.lastErrorText()
    sys.exit()

print "Success!"

The API documentation: http://www.chilkatsoft.com/refdoc/pythonCkCompressionRef.html

like image 55
chown Avatar answered Feb 20 '26 20:02

chown



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!