-
Notifications
You must be signed in to change notification settings - Fork 229
Commit
* replace bind() * re-add WriteReq and CorkedRequest constructors * Updated to v7.7.2, refactored the build to not crawl The new build system uses the tarball from nodejs.org. * try updating zuul * just remove android
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,6 +6,20 @@ | |
|
||
module.exports = Writable; | ||
|
||
function WriteReq(chunk, encoding, cb) { | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
js517
|
||
this.chunk = chunk; | ||
this.encoding = encoding; | ||
this.callback = cb; | ||
this.next = null; | ||
} | ||
// It seems a linked list but it is not | ||
// there will be only 2 of these for each stream | ||
function CorkedRequest(state) { | ||
this.next = null; | ||
this.entry = null; | ||
this.finish = onCorkedFinish.bind(undefined, this, state); | ||
} | ||
|
||
/*<replacement>*/ | ||
var processNextTick = require('process-nextick-args'); | ||
/*</replacement>*/ | ||
|
@@ -77,7 +91,7 @@ function WritableState(options, stream) { | |
this.highWaterMark = hwm || hwm === 0 ? hwm : defaultHwm; | ||
|
||
// cast to ints. | ||
this.highWaterMark = ~ ~this.highWaterMark; | ||
this.highWaterMark = ~~this.highWaterMark; | ||
|
||
// drain event flag. | ||
this.needDrain = false; | ||
|
@@ -232,20 +246,16 @@ function writeAfterEnd(stream, cb) { | |
processNextTick(cb, er); | ||
} | ||
|
||
// If we get something that is not a buffer, string, null, or undefined, | ||
// and we're not in objectMode, then that's an error. | ||
// Otherwise stream chunks are all considered to be of length=1, and the | ||
// watermarks determine how many objects to keep in the buffer, rather than | ||
// how many bytes or characters. | ||
// Checks that a user-supplied chunk is valid, especially for the particular | ||
// mode the stream is in. Currently this means that `null` is never accepted | ||
// and undefined/non-string values are only allowed in object mode. | ||
function validChunk(stream, state, chunk, cb) { | ||
var valid = true; | ||
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) { | ||
} else if (typeof chunk !== 'string' && chunk !== undefined && !state.objectMode) { | ||
er = new TypeError('Invalid non-string/buffer chunk'); | ||
} | ||
if (er) { | ||
|
@@ -259,19 +269,20 @@ function validChunk(stream, state, chunk, cb) { | |
Writable.prototype.write = function (chunk, encoding, cb) { | ||
var state = this._writableState; | ||
var ret = false; | ||
var isBuf = Buffer.isBuffer(chunk); | ||
|
||
if (typeof encoding === 'function') { | ||
cb = encoding; | ||
encoding = null; | ||
} | ||
|
||
if (Buffer.isBuffer(chunk)) encoding = 'buffer';else if (!encoding) encoding = state.defaultEncoding; | ||
if (isBuf) encoding = 'buffer';else if (!encoding) encoding = state.defaultEncoding; | ||
|
||
if (typeof cb !== 'function') cb = nop; | ||
|
||
if (state.ended) writeAfterEnd(this, cb);else if (validChunk(this, state, chunk, cb)) { | ||
if (state.ended) writeAfterEnd(this, cb);else if (isBuf || validChunk(this, state, chunk, cb)) { | ||
state.pendingcb++; | ||
ret = writeOrBuffer(this, state, chunk, encoding, cb); | ||
ret = writeOrBuffer(this, state, isBuf, chunk, encoding, cb); | ||
} | ||
|
||
return ret; | ||
|
@@ -311,10 +322,11 @@ function decodeChunk(state, chunk, encoding) { | |
// if we're already writing something, then just put this | ||
// in the queue, and wait our turn. Otherwise, call _write | ||
// If we return false, then we need a drain event, so set that flag. | ||
function writeOrBuffer(stream, state, chunk, encoding, cb) { | ||
chunk = decodeChunk(state, chunk, encoding); | ||
|
||
if (Buffer.isBuffer(chunk)) encoding = 'buffer'; | ||
function writeOrBuffer(stream, state, isBuf, chunk, encoding, cb) { | ||
if (!isBuf) { | ||
chunk = decodeChunk(state, chunk, encoding); | ||
if (Buffer.isBuffer(chunk)) encoding = 'buffer'; | ||
} | ||
var len = state.objectMode ? 1 : chunk.length; | ||
|
||
state.length += len; | ||
|
@@ -383,8 +395,8 @@ function onwrite(stream, er) { | |
asyncWrite(afterWrite, stream, state, finished, cb); | ||
/*</replacement>*/ | ||
} else { | ||
afterWrite(stream, state, finished, cb); | ||
} | ||
afterWrite(stream, state, finished, cb); | ||
} | ||
} | ||
} | ||
|
||
|
@@ -535,7 +547,6 @@ function CorkedRequest(state) { | |
|
||
this.next = null; | ||
this.entry = null; | ||
|
||
this.finish = function (err) { | ||
var entry = _this.entry; | ||
_this.entry = null; | ||
|
This function now gets defined twice