My python code is trying to decompress a uuencoded file using the zlib library. Here is the code snippet:
self.decompress = zlib.decompressobj(wbits)
.
.
buf = self.fileobj.read(size)
.
.
uncompress = self.decompress.decompress(buf)
My current value for wbits is '-zlib.MAX_WBITS'. This throws an error:
Error -3 while decompressing: invalid literal/lengths set
I realize that the python zlib library supports:
RFC 1950 (zlib compressed format)
RFC 1951 (deflate compressed format)
RFC 1952 (gzip compressed format)
and the choice for wbits is to be:
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
So my questions are:
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?
Thanks in advance!
Here's a quick demo of how to compress with zlib and encode with uuencode, and then reverse the procedure.
output
The code above will only work on Python 2. Python 3 makes a clear separation between text and bytes, and it doesn't support the encoding of bytes strings, or the decoding of text strings. So it can't use the simple uuencoding / uudecoding technique shown above.
Here's a new version that works on both Python2 and Python 3.
output
Please note that
zlib_uuencode
andzlib_uuencode
work onbytes
strings: you must pass them abytes
arg, and they return abytes
result.