To ungzip (decompress) a Node.js request’s module gzip response body, we use the zlib library.
For instance, we write
const request = require("request");
const zlib = require("zlib");
const concat = require("concat-stream");
request(url)
.pipe(zlib.createGunzip())
.pipe(
concat((stringBuffer) => {
console.log(stringBuffer.toString());
})
);
to call request to make a get request to the file url.
Then we call pipe with the stream returned by zlib.createGunzip() to unzip the file.
And we call pipe again with the stream returned by the concat function to get the unzipped data as a buffer from stringBuffer.