【发布时间】:2015-02-09 14:01:36
【问题描述】:
我的 python 代码正在尝试使用 zlib 库解压缩 uuencoded 文件。这是代码sn-p:
self.decompress = zlib.decompressobj(wbits)
.
.
buf = self.fileobj.read(size)
.
.
uncompress = self.decompress.decompress(buf)
我当前的 wbits 值是“-zlib.MAX_WBITS”。这会引发错误:
Error -3 while decompressing: invalid literal/lengths set
我意识到python zlib 库支持:
RFC 1950 (zlib compressed format)
RFC 1951 (deflate compressed format)
RFC 1952 (gzip compressed format)
wbits 的选择是:
to (de-)compress deflate format, use wbits = -zlib.MAX_WBITS
to (de-)compress zlib format, use wbits = zlib.MAX_WBITS
to (de-)compress gzip format, use wbits = zlib.MAX_WBITS | 16
所以我的问题是:
Where does a uuencoded file fall in this list?
Is it supported by zlib?
If yes, what should be the value for wbits?
If no, how do I proceed with this?
提前致谢!
【问题讨论】:
-
你试过直接解码吗?
-
FWIW,uuencoding 不会压缩数据,它会扩展它。 UUencoding 将 3 个字节的任意二进制数据从一组 64 个安全可打印字符中转换为 4 个字节。见en.wikipedia.org/wiki/Uuencoding。
-
我假设您说的是使用 zlib 兼容的压缩方法压缩然后 uuencoded 的文件。如果是这样,使用
str.decode('uu')方法或uu模块解码,然后使用zlib解压。
标签: python gzip email-attachments zlib uuencode