Last active
November 8, 2021 09:22
-
-
Save miguelmota/9946206 to your computer and use it in GitHub Desktop.
Uncompress gzip response body in Node.js with zlib example
This file contains 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
var request = require('request') | |
var zlib = require('zlib') | |
request(url, {encoding: null}, (err, response, body) => { | |
if(response.headers['content-encoding'] == 'gzip'){ | |
zlib.gunzip(body, (err, dezipped) => { | |
callback(dezipped.toString()) | |
}) | |
} else { | |
callback(body) | |
} | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thank you so much.