0

I'm working on an application that needs to scan files from 3rd parties and process them. Sometimes these are compressed, so I've created a function that checks the file extension (tar.gz, gz, zip) and uncompresses accordingly. Some of the .zip files return this error: NotImplementedError: compression type 12 (bzip2).

Is there a better way for me to identify the the compression type other than the file extension?

econgineer
  • 1,117
  • 10
  • 20

2 Answers2

0

Turns out the zipfile module in Python 2.7 doesn't support a later version of PKZIP that has bzip2 support. Switching to Python 3.3 and using zipfile module works fine.

econgineer
  • 1,117
  • 10
  • 20
0

Python zipfile module is implemented in pretty straitforward python source (modifiable). It is quite simple to implement bz2 compression and decompression capabilities when bz2 module is available (~ 7 locations to edit, mostly to rewrite zlib to bz2 compression/decompression calls). Take a look at my take on that, if you need it: https://gist.github.com/zahradil/e1a79a6152209619f046d349576d9de2

Jiri
  • 16,425
  • 6
  • 52
  • 68