restify-new-nodejs-compatible
Version:
REST framework
24 lines (18 loc) • 462 B
JavaScript
;
const stream = require('stream');
class StreamRecorder extends stream.Writable {
constructor(options) {
options = options || {};
super(options);
this.flushRecords();
}
_write(chunk, encoding, callback) {
const record = JSON.parse(chunk.toString());
this.records.push(record);
callback();
}
flushRecords() {
this.records = [];
}
}
module.exports = StreamRecorder;