v.1.1.1: Fix compatibility with Node.js v0.12 by filtering out nulls from source streams

master
Sven Slootweg 9 years ago
parent b96ee82d9a
commit dfd11e8dcb

@ -131,6 +131,7 @@ class CombinedStream extends stream.Readable
@_currentSource = @_sources.shift()[0] @_currentSource = @_sources.shift()[0]
@_currentIsStream = isStream @_currentSource @_currentIsStream = isStream @_currentSource
debug "switching to new source (stream = %s): %s", @_currentIsStream, @_currentSource.toString().replace(/\n/g, "\\n").replace(/\r/g, "\\r")
if @_currentIsStream if @_currentIsStream
@_currentSource.once "end", => @_currentSource.once "end", =>
@ -181,7 +182,12 @@ class CombinedStream extends stream.Readable
Promise.try => Promise.try =>
@_sourceDataAvailable = false @_sourceDataAvailable = false
@_wantData = false @_wantData = false
@push @_currentSource.read() chunk = @_currentSource.read()
# Since Node.js v0.12, a stream will apparently return null when it is finished... we need to filter this out, to prevent it from ending our combined stream prematurely.
if chunk?
@push chunk
Promise.resolve() Promise.resolve()
# Public module API # Public module API

@ -190,6 +190,7 @@ CombinedStream = (function(_super) {
} }
this._currentSource = this._sources.shift()[0]; this._currentSource = this._sources.shift()[0];
this._currentIsStream = isStream(this._currentSource); this._currentIsStream = isStream(this._currentSource);
debug("switching to new source (stream = %s): %s", this._currentIsStream, this._currentSource.toString().replace(/\n/g, "\\n").replace(/\r/g, "\\r"));
if (this._currentIsStream) { if (this._currentIsStream) {
this._currentSource.once("end", (function(_this) { this._currentSource.once("end", (function(_this) {
return function() { return function() {
@ -243,9 +244,13 @@ CombinedStream = (function(_super) {
CombinedStream.prototype._doStreamRead = function() { CombinedStream.prototype._doStreamRead = function() {
return Promise["try"]((function(_this) { return Promise["try"]((function(_this) {
return function() { return function() {
var chunk;
_this._sourceDataAvailable = false; _this._sourceDataAvailable = false;
_this._wantData = false; _this._wantData = false;
_this.push(_this._currentSource.read()); chunk = _this._currentSource.read();
if (chunk != null) {
_this.push(chunk);
}
return Promise.resolve(); return Promise.resolve();
}; };
})(this)); })(this));

@ -1,6 +1,6 @@
{ {
"name": "combined-stream2", "name": "combined-stream2",
"version": "1.1.0", "version": "1.1.1",
"description": "A drop-in Streams2-compatible replacement for combined-stream.", "description": "A drop-in Streams2-compatible replacement for combined-stream.",
"main": "index.js", "main": "index.js",
"scripts": { "scripts": {
@ -19,6 +19,7 @@
"author": "Sven Slootweg", "author": "Sven Slootweg",
"license": "WTFPL", "license": "WTFPL",
"devDependencies": { "devDependencies": {
"dev-null": "^0.1.1",
"gulp": "~3.8.0", "gulp": "~3.8.0",
"gulp-cached": "~0.0.3", "gulp-cached": "~0.0.3",
"gulp-coffee": "~2.0.1", "gulp-coffee": "~2.0.1",

@ -0,0 +1,9 @@
fs = require "fs"
CombinedStream = require "./"
devNull = require "dev-null"
combinedStream = CombinedStream.create()
combinedStream.append fs.createReadStream("./package.json")
combinedStream.append fs.createReadStream("./test.coffee")
#combinedStream.pipe devNull()
combinedStream.pipe process.stdout
Loading…
Cancel
Save