aboutsummaryrefslogtreecommitdiff
path: root/node_modules/ordered-read-streams/index.js
diff options
context:
space:
mode:
Diffstat (limited to 'node_modules/ordered-read-streams/index.js')
-rw-r--r--node_modules/ordered-read-streams/index.js34
1 files changed, 14 insertions, 20 deletions
diff --git a/node_modules/ordered-read-streams/index.js b/node_modules/ordered-read-streams/index.js
index f58ccf1dd..03e936b65 100644
--- a/node_modules/ordered-read-streams/index.js
+++ b/node_modules/ordered-read-streams/index.js
@@ -1,20 +1,21 @@
-var Readable = require('stream').Readable;
+var Readable = require('readable-stream/readable');
+var isReadable = require('is-stream').readable;
var util = require('util');
-
function addStream(streams, stream)
{
- if(!stream.readable) throw new Error('All input streams must be readable');
-
- if(this._readableState.ended) throw new Error('Adding streams after ended');
-
+ if(!isReadable(stream)) throw new Error('All input streams must be readable');
var self = this;
stream._buffer = [];
- stream.on('data', function(chunk)
+ stream.on('readable', function()
{
+ var chunk = stream.read();
+ if (chunk === null)
+ return;
+
if(this === streams[0])
self.push(chunk);
@@ -39,7 +40,6 @@ function addStream(streams, stream)
stream.on('error', this.emit.bind(this, 'error'));
-
streams.push(stream);
}
@@ -64,20 +64,14 @@ function OrderedStreams(streams, options) {
var addStream_bind = addStream.bind(this, []);
- this.concat = function()
+ streams.forEach(function(item)
{
- Array.prototype.forEach.call(arguments, function(item)
- {
- if(Array.isArray(item))
- item.forEach(addStream_bind);
-
- else
- addStream_bind(item);
- });
- };
-
+ if(Array.isArray(item))
+ item.forEach(addStream_bind);
- this.concat(streams);
+ else
+ addStream_bind(item);
+ });
}
util.inherits(OrderedStreams, Readable);