Easy HTTP requests with gzip/deflate compression

For anyone coming across this in recent times, the request library supports gzip decompression out of the box now. Use as follows: request( { method: ‘GET’ , uri: ‘http://www.google.com’ , gzip: true } , function (error, response, body) { // body is the decompressed response body console.log(‘server encoded the data as: ‘ + (response.headers[‘content-encoding’] || … Read more

Decompressing GZip Stream from HTTPClient Response

Just instantiate HttpClient like this: HttpClientHandler handler = new HttpClientHandler() { AutomaticDecompression = DecompressionMethods.GZip | DecompressionMethods.Deflate }; using (var client = new HttpClient(handler)) //see update below { // your code } Update June 19, 2020: It’s not recommended to use httpclient in a ‘using’ block as it might cause port exhaustion. private static HttpClient client … Read more

How can I Zip and Unzip a string using GZIPOutputStream that is compatible with .Net?

The GZIP methods: public static byte[] compress(String string) throws IOException { ByteArrayOutputStream os = new ByteArrayOutputStream(string.length()); GZIPOutputStream gos = new GZIPOutputStream(os); gos.write(string.getBytes()); gos.close(); byte[] compressed = os.toByteArray(); os.close(); return compressed; } public static String decompress(byte[] compressed) throws IOException { final int BUFFER_SIZE = 32; ByteArrayInputStream is = new ByteArrayInputStream(compressed); GZIPInputStream gis = new GZIPInputStream(is, BUFFER_SIZE); … Read more

How are zlib, gzip and zip related? What do they have in common and how are they different?

Short form: .zip is an archive format using, usually, the Deflate compression method. The .gz gzip format is for single files, also using the Deflate compression method. Often gzip is used in combination with tar to make a compressed archive format, .tar.gz. The zlib library provides Deflate compression and decompression code for use by zip, … Read more

Does python urllib2 automatically uncompress gzip data fetched from webpage?

How can I tell if the data at a URL is gzipped? This checks if the content is gzipped and decompresses it: from StringIO import StringIO import gzip request = urllib2.Request(‘http://example.com/’) request.add_header(‘Accept-encoding’, ‘gzip’) response = urllib2.urlopen(request) if response.info().get(‘Content-Encoding’) == ‘gzip’: buf = StringIO(response.read()) f = gzip.GzipFile(fileobj=buf) data = f.read() Does urllib2 automatically uncompress the data … Read more

How can I decompress a gzip stream with zlib?

To decompress a gzip format file with zlib, call inflateInit2 with the windowBits parameter as 16+MAX_WBITS, like this: inflateInit2(&stream, 16+MAX_WBITS); If you don’t do this, zlib will complain about a bad stream format. By default, zlib creates streams with a zlib header, and on inflate does not recognise the different gzip header unless you tell … Read more

How to ‘minify’ Javascript code

DIY Minification No minifier can compress properly a bad code. In this example i just wanna show how much a minifier does. What you should do before you minify And regarding jQuery… i don’t use jQuery.jQuery is for old browsers,it was made for compatibility reasons .. check caniuse.com, almost everything works on every browser (also … Read more

Enable IIS7 gzip

Configuration You can enable GZIP compression entirely in your Web.config file. This is particularly useful if you’re on shared hosting and can’t configure IIS directly, or you want your config to carry between all environments you target. <system.webServer> <httpCompression directory=”%SystemDrive%\inetpub\temp\IIS Temporary Compressed Files”> <scheme name=”gzip” dll=”%Windir%\system32\inetsrv\gzip.dll”/> <dynamicTypes> <add mimeType=”text/*” enabled=”true”/> <add mimeType=”message/*” enabled=”true”/> <add mimeType=”application/javascript” … Read more