Created
September 28, 2015 06:45
-
-
Save sasikanth/977e6af7744173b7111b to your computer and use it in GitHub Desktop.
Frisby test : How to decompress a raw Buffer with Gunzip.( Asynchronously )
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| //gunzip Sample | |
| var frisby=require('frisby'); | |
| var zlib = require('zlib'); | |
| var tc02 = frisby.create('Gzip Test'); | |
| tc02.get('http://httpbin.org/gzip', { encoding: null }) | |
| .after(function(error, response, body){ | |
| if (!error && response.statusCode == 200) { | |
| var encoding = response.headers['content-encoding'] | |
| if (encoding && encoding.indexOf('gzip') > -1) { | |
| zlib.gunzip(body, function(err, dezipped) { | |
| var json_string = dezipped.toString('utf-8'); | |
| var json = JSON.parse(json_string); | |
| console.log(json); | |
| }); | |
| } else { | |
| console.log("Response encoding is not gzip"); | |
| } | |
| } | |
| }) | |
| .toss(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment