| import { default as Stream } from "nodelibs/stream" |
| import { default as buffer } from "nodelibs/buffer" |
| var Transform = Stream.Transform; |
| var PassThrough = Stream.PassThrough; |
| var Buffer = buffer.Buffer; |
| * A through transform stream keep a copy of the data piped to it and provides |
| * functions to create new copies of the stream on-demand |
| export class StreamCopy extends Transform { |
| this._writableState.objectMode = true; |
| this._readableState.objectMode = true; |
| // TODO(aghassemi) make this a FIFO buffer with reasonable max-size |
| _transform(chunk, encoding, cb) { |
| for (var i=0; i < this.copies.length; i++) { |
| this.copies[i].push(chunk); |
| * Create a new copy of the stream |
| * @param {bool} onlyNewData Whether the copy should include |
| * existing data from the stream or just new data. |
| * @return {Stream} Copy of the stream |
| var copy = new PassThrough( { objectMode: true }); |
| // copy existing data first in the order received |
| for (var i = 0; i < this.buffer.length; i++) { |
| copy.push(this.buffer[i]); |