v.1.1.1: Fix compatibility with Node.js v0.12 by filtering out nulls from source streams
This commit is contained in:
parent
b96ee82d9a
commit
dfd11e8dcb
|
@ -131,6 +131,7 @@ class CombinedStream extends stream.Readable
|
|||
|
||||
@_currentSource = @_sources.shift()[0]
|
||||
@_currentIsStream = isStream @_currentSource
|
||||
debug "switching to new source (stream = %s): %s", @_currentIsStream, @_currentSource.toString().replace(/\n/g, "\\n").replace(/\r/g, "\\r")
|
||||
|
||||
if @_currentIsStream
|
||||
@_currentSource.once "end", =>
|
||||
|
@ -181,7 +182,12 @@ class CombinedStream extends stream.Readable
|
|||
Promise.try =>
|
||||
@_sourceDataAvailable = 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()
|
||||
|
||||
# Public module API
|
||||
|
|
|
@ -190,6 +190,7 @@ CombinedStream = (function(_super) {
|
|||
}
|
||||
this._currentSource = this._sources.shift()[0];
|
||||
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) {
|
||||
this._currentSource.once("end", (function(_this) {
|
||||
return function() {
|
||||
|
@ -243,9 +244,13 @@ CombinedStream = (function(_super) {
|
|||
CombinedStream.prototype._doStreamRead = function() {
|
||||
return Promise["try"]((function(_this) {
|
||||
return function() {
|
||||
var chunk;
|
||||
_this._sourceDataAvailable = false;
|
||||
_this._wantData = false;
|
||||
_this.push(_this._currentSource.read());
|
||||
chunk = _this._currentSource.read();
|
||||
if (chunk != null) {
|
||||
_this.push(chunk);
|
||||
}
|
||||
return Promise.resolve();
|
||||
};
|
||||
})(this));
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"name": "combined-stream2",
|
||||
"version": "1.1.0",
|
||||
"version": "1.1.1",
|
||||
"description": "A drop-in Streams2-compatible replacement for combined-stream.",
|
||||
"main": "index.js",
|
||||
"scripts": {
|
||||
|
@ -19,6 +19,7 @@
|
|||
"author": "Sven Slootweg",
|
||||
"license": "WTFPL",
|
||||
"devDependencies": {
|
||||
"dev-null": "^0.1.1",
|
||||
"gulp": "~3.8.0",
|
||||
"gulp-cached": "~0.0.3",
|
||||
"gulp-coffee": "~2.0.1",
|
||||
|
|
9
test.coffee
Normal file
9
test.coffee
Normal file
|
@ -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…
Reference in a new issue