How To Parse Gzipped Data In Nodejs Submitted By External Api
An external API sends a POST request with its results compressed in the gzip format to my postback_url. Here is what I get in body param. Btw, I shorten the output as it is a very
Solution 1:
If it's a gzip in base64 then you can Decode it like this.
const zlib = require('zlib');
const buffer = Buffer.from(data, 'base64');
zlib.unzip(buffer, { finishFlush: zlib.constants.Z_SYNC_FLUSH }, (err, buffer) => {
if (err) {
console.error('An error occurred:', err);
}
console.log(JSON.parse(buffer.toString()));
});
Post a Comment for "How To Parse Gzipped Data In Nodejs Submitted By External Api"