memstreams
Version:
Memory Streams library for JavaScript based on readable-stream
39 lines • 1.08 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.ObjectWriter = void 0;
const readable_stream_1 = require("readable-stream");
class ObjectWriter extends readable_stream_1.Writable {
constructor(options = {}) {
options.objectMode = true;
super(options);
this.init();
}
init() {
this._queue = [];
}
get queue() {
return this._queue;
}
get data() {
return [...this._queue];
}
_write(chunk, encoding, callback) {
if (this.listenerCount('write')) {
this.emit('write', chunk);
}
else {
this._queue.push(chunk);
}
callback();
}
forward(destination, options) {
const forward = (data) => destination.push(data);
this.on('write', forward);
if (!options || options.end) {
this.once('finish', () => this.removeListener('data', forward));
}
return destination;
}
}
exports.ObjectWriter = ObjectWriter;
//# sourceMappingURL=object-writer.js.map