how2
Version:
AI for your terminal. Uses Google and Stackoverflow to find how to do things on a Unix command line.
24 lines (21 loc) • 567 B
JavaScript
const zlib = require('zlib');
/**
* Parse the buffer, StackExchange promises to always deliver zipped content,
* but since JSON parsing is required just wrap it in a try/catch.
*
* @param {Buffer} buffer response content
* @param {Function} callback return results
* @api private
*/
function parseBody(buffer, callback) {
zlib
.unzip(buffer, (error, body) => {
try {
callback(error, JSON.parse(body.toString()));
} catch (error) {
callback(error);
}
});
}
// Export functions
module.exports.parseBody = parseBody;