stream-stream
Advanced tools
Comparing version 1.2.2 to 1.2.3
@@ -15,38 +15,36 @@ var util = require('util'); | ||
if(options) { | ||
var separator = options.separator; | ||
switch(typeof separator) { | ||
// if the separator is a constant value | ||
// we make it a function to be treated in the | ||
// next case | ||
case 'string': | ||
var val = separator; | ||
separator = function(cb) { | ||
process.nextTick(function() { | ||
cb(val); | ||
}) | ||
} | ||
// make this._separator() always return | ||
// a stream filled with the results of the callback | ||
// if the reset is a stream, pipe it as separator | ||
case 'function': | ||
var fn = separator; | ||
separator = function() { | ||
var ps = new stream.PassThrough(options); | ||
ps._isSeparator = true; | ||
fn(function(res) { | ||
if(res.readable) | ||
res.pipe(ps); | ||
else | ||
ps.end(res); | ||
}); | ||
return ps; | ||
} | ||
break; | ||
default: | ||
separator = null; | ||
break; | ||
} | ||
this._separator = separator; | ||
var separator = options.separator; | ||
switch(typeof separator) { | ||
// if the separator is a constant value | ||
// we make it a function to be treated in the | ||
// next case | ||
case 'string': | ||
var val = separator; | ||
separator = function(cb) { | ||
process.nextTick(function() { | ||
cb(val); | ||
}) | ||
} | ||
// make this._separator() always return | ||
// a stream filled with the results of the callback | ||
// if the reset is a stream, pipe it as separator | ||
case 'function': | ||
var fn = separator; | ||
separator = function() { | ||
var ps = new stream.PassThrough(options); | ||
ps._isSeparator = true; | ||
fn(function(res) { | ||
if(res.readable) | ||
res.pipe(ps); | ||
else | ||
ps.end(res); | ||
}); | ||
return ps; | ||
} | ||
break; | ||
default: | ||
separator = null; | ||
break; | ||
} | ||
this._separator = separator; | ||
@@ -59,6 +57,2 @@ this._readableState.objectMode = options.objectMode; | ||
StreamStream.prototype._transform = function _transform(stream, encoding, done) { | ||
if(this._lastStream && !this._lastStream._readableState.ended) { | ||
return done(new Error('There still a stream active')); | ||
} | ||
if(this._lastStream && this._separator && this._needSeparator) { | ||
@@ -73,4 +67,6 @@ var withSep = new StreamStream(this._readableState.objectMode); | ||
stream.on('readable', function() { | ||
var chunk = stream.read(); | ||
if(chunk !== null) self.push(chunk); | ||
var chunk; | ||
while(chunk = stream.read()) { | ||
self.push(chunk); | ||
} | ||
}); | ||
@@ -77,0 +73,0 @@ stream.on('end', done); |
{ | ||
"name": "stream-stream", | ||
"version": "1.2.2", | ||
"version": "1.2.3", | ||
"description": "A stream of streams in order to concatenates the contents of several streams", | ||
@@ -10,3 +10,3 @@ "main": "index.js", | ||
"scripts": { | ||
"test": "nodeunit test/test-*.js" | ||
"test": "istanbul cover nodeunit test/test-*.js && istanbul check --branches 90 --statements 95 --lines 100 --functions 100" | ||
}, | ||
@@ -26,3 +26,4 @@ "repository": { | ||
"nodeunit": "0.7.x", | ||
"stream-sink": "~1.1" | ||
"stream-sink": "~1.1", | ||
"istanbul": "~0.1.42" | ||
}, | ||
@@ -29,0 +30,0 @@ "author": "Florent Jaby <florent.jaby@gmail.com>", |
@@ -86,1 +86,36 @@ var stream = require('stream'); | ||
exports.testObjectModeOverrun = function (test) { | ||
var options = {objectMode: true}; | ||
var a = new stream.PassThrough(options); | ||
var b = new stream.PassThrough(options); | ||
var c = new stream.PassThrough(options); | ||
var ss = SS(options) | ||
var done = false; | ||
ss.pipe(sink(options)).on('data', function(data) { | ||
done = true; | ||
clearTimeout(to); | ||
test.doesNotThrow(function() { | ||
test.ok(Array.isArray(data), "Data should be an array"); | ||
test.equal(data.length, 6, "Data should have same length"); | ||
test.equal(data.join(''), 'aabbcc', 'Data should be aabbcc') | ||
}) | ||
test.done(); | ||
}); | ||
a.write('a'); | ||
ss.write(a); | ||
a.end('a'); | ||
b.write('b'); | ||
b.end('b'); | ||
ss.write(b); | ||
ss.end(c); | ||
c.write('c'); | ||
c.end('c'); | ||
var to = setTimeout(function(){ | ||
if(!done) { | ||
test.fail('no end detected'); | ||
test.done(); | ||
} | ||
}, 20) | ||
} |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
17108
466
3