Files
dbgate/packages/api/src/shell/collectorWriter.js
2020-10-29 10:07:09 +01:00

34 lines
688 B
JavaScript

const stream = require('stream');
class CollectorWriterStream extends stream.Writable {
constructor(options) {
super(options);
this.rows = [];
this.structure = null;
this.runid = options.runid;
}
_write(chunk, enc, next) {
if (!this.structure) this.structure = chunk;
else this.rows.push(chunk);
next();
}
_final(callback) {
process.send({
msgtype: 'freeData',
runid: this.runid,
freeData: { rows: this.rows, structure: this.structure },
});
callback();
}
}
async function collectorWriter({ runid }) {
return new CollectorWriterStream({
objectMode: true,
runid,
});
}
module.exports = collectorWriter;