diff options
Diffstat (limited to 'deps/npm/node_modules/sha/node_modules/readable-stream/lib/_stream_writable.js')
-rw-r--r-- | deps/npm/node_modules/sha/node_modules/readable-stream/lib/_stream_writable.js | 26 |
1 files changed, 22 insertions, 4 deletions
diff --git a/deps/npm/node_modules/sha/node_modules/readable-stream/lib/_stream_writable.js b/deps/npm/node_modules/sha/node_modules/readable-stream/lib/_stream_writable.js index 4b976a9f3f..d0254d5a71 100644 --- a/deps/npm/node_modules/sha/node_modules/readable-stream/lib/_stream_writable.js +++ b/deps/npm/node_modules/sha/node_modules/readable-stream/lib/_stream_writable.js @@ -24,10 +24,20 @@ // the drain event emission and buffering. module.exports = Writable; + +/*<replacement>*/ +var Buffer = require('buffer').Buffer; +/*</replacement>*/ + Writable.WritableState = WritableState; -var util = require('util'); -var assert = require('assert'); + +/*<replacement>*/ +var util = require('core-util-is'); +util.inherits = require('inherits'); +/*</replacement>*/ + + var Stream = require('stream'); util.inherits(Writable, Stream); @@ -104,12 +114,17 @@ function WritableState(options, stream) { this.writelen = 0; this.buffer = []; + + // True if the error was already emitted and should not be thrown again + this.errorEmitted = false; } function Writable(options) { + var Duplex = require('./_stream_duplex'); + // Writable ctor is applied to Duplexes, though they're not // instanceof Writable, they're instanceof Readable. - if (!(this instanceof Writable) && !(this instanceof require('./_stream_duplex'))) + if (!(this instanceof Writable) && !(this instanceof Duplex)) return new Writable(options); this._writableState = new WritableState(options, this); @@ -203,7 +218,9 @@ function writeOrBuffer(stream, state, chunk, encoding, cb) { state.length += len; var ret = state.length < state.highWaterMark; - state.needDrain = !ret; + // we must ensure that previous needDrain will not be reset to false. + if (!ret) + state.needDrain = true; if (state.writing) state.buffer.push(new WriteReq(chunk, encoding, cb)); @@ -230,6 +247,7 @@ function onwriteError(stream, state, sync, er, cb) { else cb(er); + stream._writableState.errorEmitted = true; stream.emit('error', er); } |