bufferedstream
Advanced tools
Comparing version 3.0.5 to 3.0.6
/* jshint -W084 */ | ||
/*! | ||
* BufferedStream - A robust stream implementation for node.js and the browser | ||
* https://github.com/mjackson/bufferedstream | ||
*/ | ||
var d = require('describe-property'); | ||
var EventEmitter = require('events').EventEmitter; | ||
@@ -150,5 +155,3 @@ var isBinary = require('./utils/isBinary'); | ||
constructor: { | ||
value: BufferedStream | ||
}, | ||
constructor: d(BufferedStream), | ||
@@ -158,7 +161,5 @@ /** | ||
*/ | ||
empty: { | ||
get: function () { | ||
return this._chunks == null || this._chunks.length === 0; | ||
} | ||
}, | ||
empty: d.gs(function () { | ||
return this._chunks == null || this._chunks.length === 0; | ||
}), | ||
@@ -168,7 +169,5 @@ /** | ||
*/ | ||
full: { | ||
get: function () { | ||
return this.maxSize < this.size; | ||
} | ||
}, | ||
full: d.gs(function () { | ||
return this.maxSize < this.size; | ||
}), | ||
@@ -179,7 +178,5 @@ /** | ||
*/ | ||
piped: { | ||
get: function () { | ||
return this._source != null; | ||
} | ||
}, | ||
piped: d.gs(function () { | ||
return this._source != null; | ||
}), | ||
@@ -192,7 +189,5 @@ /** | ||
*/ | ||
setEncoding: { | ||
value: function (encoding) { | ||
this.encoding = encoding; | ||
} | ||
}, | ||
setEncoding: d(function (encoding) { | ||
this.encoding = encoding; | ||
}), | ||
@@ -203,7 +198,5 @@ /** | ||
*/ | ||
pause: { | ||
value: function () { | ||
this.paused = true; | ||
} | ||
}, | ||
pause: d(function () { | ||
this.paused = true; | ||
}), | ||
@@ -213,10 +206,8 @@ /** | ||
*/ | ||
resume: { | ||
value: function () { | ||
if (this.paused) | ||
flushSoon(this); | ||
resume: d(function () { | ||
if (this.paused) | ||
flushSoon(this); | ||
this.paused = false; | ||
} | ||
}, | ||
this.paused = false; | ||
}), | ||
@@ -231,69 +222,67 @@ /** | ||
*/ | ||
pipe: { | ||
value: function (dest, options) { | ||
var source = this; | ||
pipe: d(function (dest, options) { | ||
var source = this; | ||
function ondata(chunk) { | ||
if (dest.writable && false === dest.write(chunk)) | ||
source.pause(); | ||
} | ||
function ondata(chunk) { | ||
if (dest.writable && false === dest.write(chunk)) | ||
source.pause(); | ||
} | ||
source.on('data', ondata); | ||
source.on('data', ondata); | ||
function ondrain() { | ||
if (source.readable) | ||
source.resume(); | ||
} | ||
function ondrain() { | ||
if (source.readable) | ||
source.resume(); | ||
} | ||
dest.on('drain', ondrain); | ||
dest.on('drain', ondrain); | ||
var didOnEnd = false; | ||
function onend() { | ||
if (didOnEnd) return; | ||
didOnEnd = true; | ||
var didOnEnd = false; | ||
function onend() { | ||
if (didOnEnd) return; | ||
didOnEnd = true; | ||
dest.end(); | ||
} | ||
dest.end(); | ||
} | ||
// If the 'end' option is not supplied, dest.end() will be called when | ||
// source gets the 'end' or 'close' events. Only dest.end() once. | ||
if (!dest._isStdio && (!options || options.end !== false)) | ||
source.on('end', onend); | ||
// If the 'end' option is not supplied, dest.end() will be called when | ||
// source gets the 'end' or 'close' events. Only dest.end() once. | ||
if (!dest._isStdio && (!options || options.end !== false)) | ||
source.on('end', onend); | ||
// don't leave dangling pipes when there are errors. | ||
function onerror(error) { | ||
cleanup(); | ||
if (EventEmitter.listenerCount(this, 'error') === 0) | ||
throw error; // Unhandled stream error in pipe. | ||
} | ||
// don't leave dangling pipes when there are errors. | ||
function onerror(error) { | ||
cleanup(); | ||
if (EventEmitter.listenerCount(this, 'error') === 0) | ||
throw error; // Unhandled stream error in pipe. | ||
} | ||
source.on('error', onerror); | ||
dest.on('error', onerror); | ||
source.on('error', onerror); | ||
dest.on('error', onerror); | ||
// remove all the event listeners that were added. | ||
function cleanup() { | ||
source.removeListener('data', ondata); | ||
dest.removeListener('drain', ondrain); | ||
// remove all the event listeners that were added. | ||
function cleanup() { | ||
source.removeListener('data', ondata); | ||
dest.removeListener('drain', ondrain); | ||
source.removeListener('end', onend); | ||
source.removeListener('end', onend); | ||
source.removeListener('error', onerror); | ||
dest.removeListener('error', onerror); | ||
source.removeListener('error', onerror); | ||
dest.removeListener('error', onerror); | ||
source.removeListener('end', cleanup); | ||
} | ||
source.removeListener('end', cleanup); | ||
} | ||
source.on('end', cleanup); | ||
dest.on('close', cleanup); | ||
source.on('end', cleanup); | ||
dest.on('close', cleanup); | ||
dest.emit('pipe', source); | ||
dest.emit('pipe', source); | ||
// Mimic the behavior of node v2 streams where pipe() resumes the flow. | ||
// This lets us avoid having to do stream.resume() all over the place. | ||
source.resume(); | ||
// Mimic the behavior of node v2 streams where pipe() resumes the flow. | ||
// This lets us avoid having to do stream.resume() all over the place. | ||
source.resume(); | ||
// Allow for unix-like usage: A.pipe(B).pipe(C) | ||
return dest; | ||
} | ||
}, | ||
// Allow for unix-like usage: A.pipe(B).pipe(C) | ||
return dest; | ||
}), | ||
@@ -305,27 +294,25 @@ /** | ||
*/ | ||
write: { | ||
value: function (chunk) { | ||
if (!this.writable) | ||
throw new Error('BufferedStream is not writable'); | ||
write: d(function (chunk) { | ||
if (!this.writable) | ||
throw new Error('BufferedStream is not writable'); | ||
if (this.ended) | ||
throw new Error('BufferedStream is already ended'); | ||
if (this.ended) | ||
throw new Error('BufferedStream is already ended'); | ||
if (!isBinary(chunk)) | ||
chunk = binaryFrom(chunk, arguments[1]); | ||
if (!isBinary(chunk)) | ||
chunk = binaryFrom(chunk, arguments[1]); | ||
this._chunks.push(chunk); | ||
this.size += chunk.length; | ||
this._chunks.push(chunk); | ||
this.size += chunk.length; | ||
flushSoon(this); | ||
flushSoon(this); | ||
if (this.full) { | ||
this._wasFull = true; | ||
return false; | ||
} | ||
return true; | ||
if (this.full) { | ||
this._wasFull = true; | ||
return false; | ||
} | ||
}, | ||
return true; | ||
}), | ||
/** | ||
@@ -336,17 +323,15 @@ * Writes the given chunk to this stream and queues the end event to be | ||
*/ | ||
end: { | ||
value: function (chunk) { | ||
if (this.ended) | ||
throw new Error('BufferedStream is already ended'); | ||
end: d(function (chunk) { | ||
if (this.ended) | ||
throw new Error('BufferedStream is already ended'); | ||
if (chunk != null) | ||
this.write(chunk, arguments[1]); | ||
if (chunk != null) | ||
this.write(chunk, arguments[1]); | ||
this.ended = true; | ||
this.ended = true; | ||
// Trigger the flush cycle one last time to emit | ||
// any data that was written before end was called. | ||
flushSoon(this); | ||
} | ||
} | ||
// Trigger the flush cycle one last time to emit | ||
// any data that was written before end was called. | ||
flushSoon(this); | ||
}) | ||
@@ -353,0 +338,0 @@ }); |
@@ -5,3 +5,3 @@ { | ||
"author": "Michael Jackson", | ||
"version": "3.0.5", | ||
"version": "3.0.6", | ||
"repository": { | ||
@@ -14,3 +14,3 @@ "type": "git", | ||
"dist": "webpack modules/BufferedStream.js dist/BufferedStream.min.js", | ||
"test": "jshint . && mocha modules/**/__tests__/*-test.js", | ||
"test": "jshint . && mocha --reporter spec 'modules/**/__tests__/*-test.js'", | ||
"test-browser": "karma start" | ||
@@ -23,2 +23,3 @@ }, | ||
"bodec": "git://github.com/mjackson/bodec#browser", | ||
"describe-property": "^1.0.0", | ||
"events": "~1.0.1" | ||
@@ -25,0 +26,0 @@ }, |
16806
3
326
+ Addeddescribe-property@^1.0.0
+ Addeddescribe-property@1.1.0(transitive)
+ Addedobject-assign@2.1.1(transitive)