/ Decompress gzipped http response inside Vim

Decompress gzipped http response inside Vim

For debugging purposes I sniffed some requests & responses from my server/client. The compression is enabled so the responses are sent in gzip format. I know that probably I could just disable `mod_deflate`, but… out of curiosity, is there a way to decompress the gzipped response right in vim?

Here’s an example of a response:

HTTP/1.1 200 OK Date: Tue, 09 Jul 2013 08:00:18 GMT Server: Apache/2.2.14 (Ubuntu) X-Powered-By: PHP/5.3.2-1ubuntu4.19 Content-Disposition: inline; filename="combo" Last-Modified: Tue, 09 Jul 2013 08:00:18 GMT Expires: Tue, 09 Jul 2013 08:00:20 GMT Pragma: Accept-Ranges: none Content-Encoding: gzip Vary: Accept-Encoding Content-Length: 209 Keep-Alive: timeout=15, max=79 Connection: Keep-Alive Content-Type: text/css ^_<8b>^H^@^@^@^@^@^@^C<94><8f>Í^N<82>0^P<84>ï>E^SÏ%^H)<87>öiJ»@cm<9b>º <84>øîò#ê^Ac<ìafvçË&JZpZF ^]8¤A:°d,¥:×Ñ·NSå­<8f>üX^T<85>(}Ô^Py^VzrõÖhòáÒ<9b>ÑØp<92><92>9<9e>'^U÷C²[<9f>^L­É©ï Z9L^@<87>S¶^G­ªj<83><9e>ÞPÆ<98>¸ÈX^[GÑ^GNYè7m¡ÂÕø<8f>Ýdɲ<84>^F-<90>qmãùÄdë7"H­<8d>«y*^Pz¤Ò<9a>Úq5<9d>@üÎZÄë¿g+ûÕö^@^@^@ÿÿ^C^@d«^X^^<94>^A^@^@

I’d like to select the gzipped text section & decompress it on the fly (maybe running a terminal command on it? something like :!sort to sort lines…)

Select the gzipped text section (or provide a range, e.g. `:/^$\n\zs/,$`). Then you can unzip the part by piping it through the external `gunzip` command (which naturally must be installed & accessible):

:!gunzip -

When I tested this, the buffer had to be opened in 'binary' mode: :edit ++bin filename. Also, I received gzip: stdin: unexpected end of file after the unpacked contents, yet that probably can be tolerated.