mirror of
https://github.com/DeNNiiInc/dbgate.git
synced 2026-04-18 20:46:01 +00:00
34 lines
688 B
JavaScript
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;
|