Zip, Encrypted, Gziped files with Python

python

Solution

You can use the `zlib` module to decompress a gzip stream, with something like:

zlib.decompress(inf, 16+zlib.MAX_WBITS)

where `inf` is your gzip stream. The `16 + zlib.MAX_WBITS` is a magic value that makes zlib skip over the gzip header.

Problem

I have to deal with a "proprietary" file format that's nothing more than a bunch of text files, which each has been gzip'd, then encrypted, and then finally all of them bundled in a zip file. I'm using python to automate the extraction of these files. So the unzipping is easy with ZipFile. Then I have a list of xyz_001.gz.rc4 files which I can decrypt with RC4 + key. Then, however, that leaves me with a gz stream, and cannot use gzip standard library module to open that stream. I suppose I could store that stream to disk and then open that gz file, but I was wondering if there was a more graceful way to handle it. Help is much appreciated.

Original source