summaryrefslogtreecommitdiff
path: root/deps/npm/node_modules/readable-stream/lib/_stream_writable.js
diff options
context:
space:
mode:
authorKat Marchán <kzm@sykosomatic.org>2016-05-27 14:07:59 -0700
committerJeremiah Senkpiel <fishrock123@rocketmail.com>2016-05-28 10:42:48 -0400
commitbd8b1ddb2007dcc8ec2a0a08e16208aa21b83400 (patch)
treeaab54a7bbc42e1477a8a2b175dfc9f9eb36ca9e2 /deps/npm/node_modules/readable-stream/lib/_stream_writable.js
parent16f98e589c69ffe6283aa11493fd417368708557 (diff)
downloadandroid-node-v8-bd8b1ddb2007dcc8ec2a0a08e16208aa21b83400.tar.gz
android-node-v8-bd8b1ddb2007dcc8ec2a0a08e16208aa21b83400.tar.bz2
android-node-v8-bd8b1ddb2007dcc8ec2a0a08e16208aa21b83400.zip
deps: upgrade npm to 3.9.3
Contains the following npm releases: - v3.9.0: https://github.com/npm/npm/releases/tag/v3.9.0 - v3.9.1: https://github.com/npm/npm/releases/tag/v3.9.1 - v3.9.2: https://github.com/npm/npm/releases/tag/v3.9.2 - v3.9.3: https://github.com/npm/npm/releases/tag/v3.9.3 PR-URL: https://github.com/nodejs/node/pull/7030 Reviewed-By: Jeremiah Senkpiel <fishrock123@rocketmail.com>
Diffstat (limited to 'deps/npm/node_modules/readable-stream/lib/_stream_writable.js')
-rw-r--r--deps/npm/node_modules/readable-stream/lib/_stream_writable.js40
1 files changed, 25 insertions, 15 deletions
diff --git a/deps/npm/node_modules/readable-stream/lib/_stream_writable.js b/deps/npm/node_modules/readable-stream/lib/_stream_writable.js
index 95916c992a..ed5efcbd20 100644
--- a/deps/npm/node_modules/readable-stream/lib/_stream_writable.js
+++ b/deps/npm/node_modules/readable-stream/lib/_stream_writable.js
@@ -14,10 +14,6 @@ var processNextTick = require('process-nextick-args');
var asyncWrite = !process.browser && ['v0.10', 'v0.9.'].indexOf(process.version.slice(0, 5)) > -1 ? setImmediate : processNextTick;
/*</replacement>*/
-/*<replacement>*/
-var Buffer = require('buffer').Buffer;
-/*</replacement>*/
-
Writable.WritableState = WritableState;
/*<replacement>*/
@@ -43,6 +39,9 @@ var Stream;
/*</replacement>*/
var Buffer = require('buffer').Buffer;
+/*<replacement>*/
+var bufferShim = require('buffer-shims');
+/*</replacement>*/
util.inherits(Writable, Stream);
@@ -146,10 +145,9 @@ function WritableState(options, stream) {
// count buffered requests
this.bufferedRequestCount = 0;
- // create the two objects needed to store the corked requests
- // they are not a linked list, as no new elements are inserted in there
+ // allocate the first CorkedRequest, there is always
+ // one allocated and free to use, and we maintain at most two
this.corkedRequestsFree = new CorkedRequest(this);
- this.corkedRequestsFree.next = new CorkedRequest(this);
}
WritableState.prototype.getBuffer = function writableStateGetBuffer() {
@@ -196,7 +194,7 @@ function Writable(options) {
// Otherwise people can pipe Writable streams, which is just wrong.
Writable.prototype.pipe = function () {
- this.emit('error', new Error('Cannot pipe. Not readable.'));
+ this.emit('error', new Error('Cannot pipe, not readable'));
};
function writeAfterEnd(stream, cb) {
@@ -213,9 +211,16 @@ function writeAfterEnd(stream, cb) {
// how many bytes or characters.
function validChunk(stream, state, chunk, cb) {
var valid = true;
-
- if (!Buffer.isBuffer(chunk) && typeof chunk !== 'string' && chunk !== null && chunk !== undefined && !state.objectMode) {
- var er = new TypeError('Invalid non-string/buffer chunk');
+ var er = false;
+ // Always throw error if a null is written
+ // if we are not in object mode then throw
+ // if it is not a buffer, string, or undefined.
+ if (chunk === null) {
+ er = new TypeError('May not write null values to stream');
+ } else if (!Buffer.isBuffer(chunk) && typeof chunk !== 'string' && chunk !== undefined && !state.objectMode) {
+ er = new TypeError('Invalid non-string/buffer chunk');
+ }
+ if (er) {
stream.emit('error', er);
processNextTick(cb, er);
valid = false;
@@ -265,11 +270,12 @@ Writable.prototype.setDefaultEncoding = function setDefaultEncoding(encoding) {
if (typeof encoding === 'string') encoding = encoding.toLowerCase();
if (!(['hex', 'utf8', 'utf-8', 'ascii', 'binary', 'base64', 'ucs2', 'ucs-2', 'utf16le', 'utf-16le', 'raw'].indexOf((encoding + '').toLowerCase()) > -1)) throw new TypeError('Unknown encoding: ' + encoding);
this._writableState.defaultEncoding = encoding;
+ return this;
};
function decodeChunk(state, chunk, encoding) {
if (!state.objectMode && state.decodeStrings !== false && typeof chunk === 'string') {
- chunk = new Buffer(chunk, encoding);
+ chunk = bufferShim.from(chunk, encoding);
}
return chunk;
}
@@ -392,12 +398,16 @@ function clearBuffer(stream, state) {
doWrite(stream, state, true, state.length, buffer, '', holder.finish);
- // doWrite is always async, defer these to save a bit of time
+ // doWrite is almost always async, defer these to save a bit of time
// as the hot path ends with doWrite
state.pendingcb++;
state.lastBufferedRequest = null;
- state.corkedRequestsFree = holder.next;
- holder.next = null;
+ if (holder.next) {
+ state.corkedRequestsFree = holder.next;
+ holder.next = null;
+ } else {
+ state.corkedRequestsFree = new CorkedRequest(state);
+ }
} else {
// Slow case, write chunks one-by-one
while (entry) {