mirror of
https://github.com/DeNNiiInc/dbgate.git
synced 2026-04-19 06:06:01 +00:00
better loading free table data
This commit is contained in:
33
packages/api/src/shell/collectorWriter.js
Normal file
33
packages/api/src/shell/collectorWriter.js
Normal file
@@ -0,0 +1,33 @@
|
||||
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;
|
||||
Reference in New Issue
Block a user