解压缩nodejs中的数据
ungzip the data in nodejs
我正在尝试使用下面的代码解压缩 base64 解码的缓冲区对象,但没有执行回调函数。谁能告诉我我在这里缺少什么
function (event, context) {
event.Records.forEach(function (record) {
// Kinesis data is base64 encoded so decode here
var payload = new Buffer(record.kinesis.data, 'base64');
zlib.gunzip(payload, function (err, data) {
console.log("new data2");
if (!err) {
console.log("new data3");
console.log(data);
}
else {
console.log("new data4");
console.log(err, err.stack);
}
});
});
context.done();
};
将 context.done()
调用移到您的回调中,这样 Lambda 函数就不会提前终止。像这样:
function (event, context) {
event.Records.forEach(function (record) {
// Kinesis data is base64 encoded so decode here
var payload = new Buffer(record.kinesis.data, 'base64');
zlib.gunzip(payload, function (err, data) {
console.log("new data2");
if (!err) {
console.log("new data3");
console.log(data);
}
else {
console.log("new data4");
console.log(err, err.stack);
}
context.done();
});
});
};
我正在尝试使用下面的代码解压缩 base64 解码的缓冲区对象,但没有执行回调函数。谁能告诉我我在这里缺少什么
function (event, context) {
event.Records.forEach(function (record) {
// Kinesis data is base64 encoded so decode here
var payload = new Buffer(record.kinesis.data, 'base64');
zlib.gunzip(payload, function (err, data) {
console.log("new data2");
if (!err) {
console.log("new data3");
console.log(data);
}
else {
console.log("new data4");
console.log(err, err.stack);
}
});
});
context.done();
};
将 context.done()
调用移到您的回调中,这样 Lambda 函数就不会提前终止。像这样:
function (event, context) {
event.Records.forEach(function (record) {
// Kinesis data is base64 encoded so decode here
var payload = new Buffer(record.kinesis.data, 'base64');
zlib.gunzip(payload, function (err, data) {
console.log("new data2");
if (!err) {
console.log("new data3");
console.log(data);
}
else {
console.log("new data4");
console.log(err, err.stack);
}
context.done();
});
});
};