Automatically decompress gzip response via WebClient.DownloadData

WebClient uses HttpWebRequest under the covers. And HttpWebRequest supports gzip/deflate decompression. See HttpWebRequest AutomaticDecompression property However, WebClient class does not expose this property directly. So you will have to derive from it to set the property on the underlying HttpWebRequest. class MyWebClient : WebClient { protected override WebRequest GetWebRequest(Uri address) { HttpWebRequest request = base.GetWebRequest(address) … Read more

TypeError: ‘str’ does not support the buffer interface

If you use Python3x then string is not the same type as for Python 2.x, you must cast it to bytes (encode it). plaintext = input(“Please enter the text you want to compress”) filename = input(“Please enter the desired filename”) with gzip.open(filename + “.gz”, “wb”) as outfile: outfile.write(bytes(plaintext, ‘UTF-8’)) Also do not use variable names … Read more

JavaScript implementation of Gzip [closed]

Edit There appears to be a better LZW solution that handles Unicode strings correctly at http://pieroxy.net/blog/pages/lz-string/index.html (Thanks to pieroxy in the comments). I don’t know of any gzip implementations, but the jsolait library (the site seems to have gone away) has functions for LZW compression/decompression. The code is covered under the LGPL. // LZW-compress a … Read more