Created
September 29, 2012 18:32
-
-
Save isaacs/3804825 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module.exports = Concat; | |
var util = require('util'); | |
var Readable = require('readable-stream'); | |
var assert = require('assert'); | |
// mostly for instanceof checks or whatever. | |
// but also for .pipe() etc | |
util.inherits(Concat, Readable) | |
function Concat(/* readable, readable... */) { | |
// no relevant options, since we override read() anyway. | |
Readable.call(this); | |
this._length = arguments.length; | |
this._sources = new Array(this._length); | |
for (var i = 0; i < this._length; i++) { | |
var source = this._sources[i] = arguments[i]; | |
// only new readables are supported. | |
assert(source instanceof Readable); | |
source.on('end', this._next.bind(this)); | |
source.on('error', this.emit.bind(this, 'error')); | |
} | |
this._index = 0; | |
} | |
Concat.prototype.read = function(n) { | |
return this._sources[this._index].read(n); | |
}; | |
Concat.prototype._next = function() { | |
this._index++; | |
if (this._index === this._length{ | |
return this.emit('end'); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment