Skip to content

Instantly share code, notes, and snippets.

@miguelmota
miguelmota / dezip.js
Last active November 8, 2021 09:22
Uncompress gzip response body in Node.js with zlib example
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)