简体   繁体   English

使用Python压缩,加密,Gziped文件

[英]Zip, Encrypted, Gziped files with Python

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. 我必须处理一个“专有”文件格式,它只不过是一堆文本文件,每个文件都是gzip,然后加密,最后所有文件都捆绑在一个zip文件中。 I'm using python to automate the extraction of these files. 我正在使用python自动提取这些文件。 So the unzipping is easy with ZipFile. 因此ZipFile可以轻松解压缩。 Then I have a list of xyz_001.gz.rc4 files which I can decrypt with RC4 + key. 然后我有一个xyz_001.gz.rc4文件列表,我可以用RC4 +密钥解密。 Then, however, that leaves me with a gz stream, and cannot use gzip standard library module to open that stream. 然而,然而,这留给我一个gz流,并且不能使用gzip标准库模块来打开该流。 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. 我想我可以将该流存储到磁盘然后打开该gz文件,但我想知道是否有更优雅的方式来处理它。

Help is much appreciated. 非常感谢帮助。

You can use the zlib module to decompress a gzip stream, with something like: 您可以使用zlib模块解压缩gzip流,例如:

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

where inf is your gzip stream. inf是你的gzip流。 The 16 + zlib.MAX_WBITS is a magic value that makes zlib skip over the gzip header. 16 + zlib.MAX_WBITS是一个神奇的值,它使zlib跳过gzip头。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM