format: prettify entire project

This commit is contained in:
Rim
2025-04-02 06:50:39 -04:00
parent 86f0782a98
commit 7ccc0be712
1711 changed files with 755867 additions and 235931 deletions

View File

@ -1 +1 @@
module.exports = require('./readable').Duplex
module.exports = require('./readable').Duplex;

View File

@ -32,12 +32,15 @@ var pna = require('process-nextick-args');
/*</replacement>*/
/*<replacement>*/
var objectKeys = Object.keys || function (obj) {
var keys = [];
for (var key in obj) {
keys.push(key);
}return keys;
};
var objectKeys =
Object.keys ||
function (obj) {
var keys = [];
for (var key in obj) {
keys.push(key);
}
return keys;
};
/*</replacement>*/
module.exports = Duplex;
@ -57,7 +60,8 @@ util.inherits(Duplex, Readable);
var keys = objectKeys(Writable.prototype);
for (var v = 0; v < keys.length; v++) {
var method = keys[v];
if (!Duplex.prototype[method]) Duplex.prototype[method] = Writable.prototype[method];
if (!Duplex.prototype[method])
Duplex.prototype[method] = Writable.prototype[method];
}
}
@ -84,7 +88,7 @@ Object.defineProperty(Duplex.prototype, 'writableHighWaterMark', {
enumerable: false,
get: function () {
return this._writableState.highWaterMark;
}
},
});
// the no-half-open enforcer
@ -104,7 +108,10 @@ function onEndNT(self) {
Object.defineProperty(Duplex.prototype, 'destroyed', {
get: function () {
if (this._readableState === undefined || this._writableState === undefined) {
if (
this._readableState === undefined ||
this._writableState === undefined
) {
return false;
}
return this._readableState.destroyed && this._writableState.destroyed;
@ -112,7 +119,10 @@ Object.defineProperty(Duplex.prototype, 'destroyed', {
set: function (value) {
// we ignore the value if the stream
// has not been initialized yet
if (this._readableState === undefined || this._writableState === undefined) {
if (
this._readableState === undefined ||
this._writableState === undefined
) {
return;
}
@ -120,7 +130,7 @@ Object.defineProperty(Duplex.prototype, 'destroyed', {
// managing destroyed
this._readableState.destroyed = value;
this._writableState.destroyed = value;
}
},
});
Duplex.prototype._destroy = function (err, cb) {
@ -128,4 +138,4 @@ Duplex.prototype._destroy = function (err, cb) {
this.end();
pna.nextTick(cb, err);
};
};

View File

@ -44,4 +44,4 @@ function PassThrough(options) {
PassThrough.prototype._transform = function (chunk, encoding, cb) {
cb(null, chunk);
};
};

View File

@ -53,7 +53,12 @@ var Stream = require('./internal/streams/stream');
/*<replacement>*/
var Buffer = require('safe-buffer').Buffer;
var OurUint8Array = (typeof global !== 'undefined' ? global : typeof window !== 'undefined' ? window : typeof self !== 'undefined' ? self : {}).Uint8Array || function () {};
var OurUint8Array =
(typeof global !== 'undefined' ? global
: typeof window !== 'undefined' ? window
: typeof self !== 'undefined' ? self
: {}
).Uint8Array || function () {};
function _uint8ArrayToBuffer(chunk) {
return Buffer.from(chunk);
}
@ -89,13 +94,16 @@ var kProxyEvents = ['error', 'close', 'destroy', 'pause', 'resume'];
function prependListener(emitter, event, fn) {
// Sadly this is not cacheable as some libraries bundle their own
// event emitter implementation with them.
if (typeof emitter.prependListener === 'function') return emitter.prependListener(event, fn);
if (typeof emitter.prependListener === 'function')
return emitter.prependListener(event, fn);
// This is a hack to make sure that our error handler is attached before any
// userland ones. NEVER DO THIS. This is here only because this code needs
// to continue to work with older versions of Node.js that do not include
// the prependListener() method. The goal is to eventually remove this hack.
if (!emitter._events || !emitter._events[event]) emitter.on(event, fn);else if (isArray(emitter._events[event])) emitter._events[event].unshift(fn);else emitter._events[event] = [fn, emitter._events[event]];
if (!emitter._events || !emitter._events[event]) emitter.on(event, fn);
else if (isArray(emitter._events[event])) emitter._events[event].unshift(fn);
else emitter._events[event] = [fn, emitter._events[event]];
}
function ReadableState(options, stream) {
@ -114,7 +122,8 @@ function ReadableState(options, stream) {
// make all the buffer merging and length checks go away
this.objectMode = !!options.objectMode;
if (isDuplex) this.objectMode = this.objectMode || !!options.readableObjectMode;
if (isDuplex)
this.objectMode = this.objectMode || !!options.readableObjectMode;
// the point at which it stops calling _read() to fill the buffer
// Note: 0 is a valid value, means "don't call _read preemptively ever"
@ -122,7 +131,10 @@ function ReadableState(options, stream) {
var readableHwm = options.readableHighWaterMark;
var defaultHwm = this.objectMode ? 16 : 16 * 1024;
if (hwm || hwm === 0) this.highWaterMark = hwm;else if (isDuplex && (readableHwm || readableHwm === 0)) this.highWaterMark = readableHwm;else this.highWaterMark = defaultHwm;
if (hwm || hwm === 0) this.highWaterMark = hwm;
else if (isDuplex && (readableHwm || readableHwm === 0))
this.highWaterMark = readableHwm;
else this.highWaterMark = defaultHwm;
// cast to ints.
this.highWaterMark = Math.floor(this.highWaterMark);
@ -169,7 +181,8 @@ function ReadableState(options, stream) {
this.decoder = null;
this.encoding = null;
if (options.encoding) {
if (!StringDecoder) StringDecoder = require('string_decoder/').StringDecoder;
if (!StringDecoder)
StringDecoder = require('string_decoder/').StringDecoder;
this.decoder = new StringDecoder(options.encoding);
this.encoding = options.encoding;
}
@ -211,7 +224,7 @@ Object.defineProperty(Readable.prototype, 'destroyed', {
// backward compatibility, the user is explicitly
// managing destroyed
this._readableState.destroyed = value;
}
},
});
Readable.prototype.destroy = destroyImpl.destroy;
@ -260,20 +273,28 @@ function readableAddChunk(stream, chunk, encoding, addToFront, skipChunkCheck) {
if (!skipChunkCheck) er = chunkInvalid(state, chunk);
if (er) {
stream.emit('error', er);
} else if (state.objectMode || chunk && chunk.length > 0) {
if (typeof chunk !== 'string' && !state.objectMode && Object.getPrototypeOf(chunk) !== Buffer.prototype) {
} else if (state.objectMode || (chunk && chunk.length > 0)) {
if (
typeof chunk !== 'string' &&
!state.objectMode &&
Object.getPrototypeOf(chunk) !== Buffer.prototype
) {
chunk = _uint8ArrayToBuffer(chunk);
}
if (addToFront) {
if (state.endEmitted) stream.emit('error', new Error('stream.unshift() after end event'));else addChunk(stream, state, chunk, true);
if (state.endEmitted)
stream.emit('error', new Error('stream.unshift() after end event'));
else addChunk(stream, state, chunk, true);
} else if (state.ended) {
stream.emit('error', new Error('stream.push() after EOF'));
} else {
state.reading = false;
if (state.decoder && !encoding) {
chunk = state.decoder.write(chunk);
if (state.objectMode || chunk.length !== 0) addChunk(stream, state, chunk, false);else maybeReadMore(stream, state);
if (state.objectMode || chunk.length !== 0)
addChunk(stream, state, chunk, false);
else maybeReadMore(stream, state);
} else {
addChunk(stream, state, chunk, false);
}
@ -293,7 +314,8 @@ function addChunk(stream, state, chunk, addToFront) {
} else {
// update the buffer info.
state.length += state.objectMode ? 1 : chunk.length;
if (addToFront) state.buffer.unshift(chunk);else state.buffer.push(chunk);
if (addToFront) state.buffer.unshift(chunk);
else state.buffer.push(chunk);
if (state.needReadable) emitReadable(stream);
}
@ -302,7 +324,12 @@ function addChunk(stream, state, chunk, addToFront) {
function chunkInvalid(state, chunk) {
var er;
if (!_isUint8Array(chunk) && typeof chunk !== 'string' && chunk !== undefined && !state.objectMode) {
if (
!_isUint8Array(chunk) &&
typeof chunk !== 'string' &&
chunk !== undefined &&
!state.objectMode
) {
er = new TypeError('Invalid non-string/buffer chunk');
}
return er;
@ -316,7 +343,12 @@ function chunkInvalid(state, chunk) {
// needReadable was set, then we ought to push more, so that another
// 'readable' event will be triggered.
function needMoreData(state) {
return !state.ended && (state.needReadable || state.length < state.highWaterMark || state.length === 0);
return (
!state.ended &&
(state.needReadable ||
state.length < state.highWaterMark ||
state.length === 0)
);
}
Readable.prototype.isPaused = function () {
@ -353,11 +385,12 @@ function computeNewHighWaterMark(n) {
// This function is designed to be inlinable, so please take care when making
// changes to the function body.
function howMuchToRead(n, state) {
if (n <= 0 || state.length === 0 && state.ended) return 0;
if (n <= 0 || (state.length === 0 && state.ended)) return 0;
if (state.objectMode) return 1;
if (n !== n) {
// Only flow one buffer at a time
if (state.flowing && state.length) return state.buffer.head.data.length;else return state.length;
if (state.flowing && state.length) return state.buffer.head.data.length;
else return state.length;
}
// If we're asking for more than the current hwm, then raise the hwm.
if (n > state.highWaterMark) state.highWaterMark = computeNewHighWaterMark(n);
@ -382,9 +415,14 @@ Readable.prototype.read = function (n) {
// if we're doing read(0) to trigger a readable event, but we
// already have a bunch of data in the buffer, then just trigger
// the 'readable' event and move on.
if (n === 0 && state.needReadable && (state.length >= state.highWaterMark || state.ended)) {
if (
n === 0 &&
state.needReadable &&
(state.length >= state.highWaterMark || state.ended)
) {
debug('read: emitReadable', state.length, state.ended);
if (state.length === 0 && state.ended) endReadable(this);else emitReadable(this);
if (state.length === 0 && state.ended) endReadable(this);
else emitReadable(this);
return null;
}
@ -448,7 +486,8 @@ Readable.prototype.read = function (n) {
}
var ret;
if (n > 0) ret = fromList(n, state);else ret = null;
if (n > 0) ret = fromList(n, state);
else ret = null;
if (ret === null) {
state.needReadable = true;
@ -495,7 +534,8 @@ function emitReadable(stream) {
if (!state.emittedReadable) {
debug('emitReadable', state.flowing);
state.emittedReadable = true;
if (state.sync) pna.nextTick(emitReadable_, stream);else emitReadable_(stream);
if (state.sync) pna.nextTick(emitReadable_, stream);
else emitReadable_(stream);
}
}
@ -520,12 +560,18 @@ function maybeReadMore(stream, state) {
function maybeReadMore_(stream, state) {
var len = state.length;
while (!state.reading && !state.flowing && !state.ended && state.length < state.highWaterMark) {
while (
!state.reading &&
!state.flowing &&
!state.ended &&
state.length < state.highWaterMark
) {
debug('maybeReadMore read 0');
stream.read(0);
if (len === state.length)
// didn't get any data, stop spinning.
break;else len = state.length;
break;
else len = state.length;
}
state.readingMore = false;
}
@ -556,10 +602,14 @@ Readable.prototype.pipe = function (dest, pipeOpts) {
state.pipesCount += 1;
debug('pipe count=%d opts=%j', state.pipesCount, pipeOpts);
var doEnd = (!pipeOpts || pipeOpts.end !== false) && dest !== process.stdout && dest !== process.stderr;
var doEnd =
(!pipeOpts || pipeOpts.end !== false) &&
dest !== process.stdout &&
dest !== process.stderr;
var endFn = doEnd ? onend : unpipe;
if (state.endEmitted) pna.nextTick(endFn);else src.once('end', endFn);
if (state.endEmitted) pna.nextTick(endFn);
else src.once('end', endFn);
dest.on('unpipe', onunpipe);
function onunpipe(readable, unpipeInfo) {
@ -604,7 +654,11 @@ Readable.prototype.pipe = function (dest, pipeOpts) {
// flowing again.
// So, if this is awaiting a drain, then we just call it now.
// If we don't know, then assume that we are waiting for one.
if (state.awaitDrain && (!dest._writableState || dest._writableState.needDrain)) ondrain();
if (
state.awaitDrain &&
(!dest._writableState || dest._writableState.needDrain)
)
ondrain();
}
// If the user pushes more data while we're writing to dest then we'll end up
@ -622,7 +676,11 @@ Readable.prototype.pipe = function (dest, pipeOpts) {
// to get stuck in a permanently paused state if that write
// also returned false.
// => Check whether `dest` is still a piping destination.
if ((state.pipesCount === 1 && state.pipes === dest || state.pipesCount > 1 && indexOf(state.pipes, dest) !== -1) && !cleanedUp) {
if (
((state.pipesCount === 1 && state.pipes === dest) ||
(state.pipesCount > 1 && indexOf(state.pipes, dest) !== -1)) &&
!cleanedUp
) {
debug('false write response, pause', state.awaitDrain);
state.awaitDrain++;
increasedAwaitDrain = true;
@ -719,7 +777,8 @@ Readable.prototype.unpipe = function (dest) {
for (var i = 0; i < len; i++) {
dests[i].emit('unpipe', this, { hasUnpiped: false });
}return this;
}
return this;
}
// try to find the right one.
@ -837,7 +896,8 @@ Readable.prototype.wrap = function (stream) {
if (state.decoder) chunk = state.decoder.write(chunk);
// don't skip over falsy values in objectMode
if (state.objectMode && (chunk === null || chunk === undefined)) return;else if (!state.objectMode && (!chunk || !chunk.length)) return;
if (state.objectMode && (chunk === null || chunk === undefined)) return;
else if (!state.objectMode && (!chunk || !chunk.length)) return;
var ret = _this.push(chunk);
if (!ret) {
@ -850,11 +910,11 @@ Readable.prototype.wrap = function (stream) {
// important when wrapping filters and duplexes.
for (var i in stream) {
if (this[i] === undefined && typeof stream[i] === 'function') {
this[i] = function (method) {
this[i] = (function (method) {
return function () {
return stream[method].apply(stream, arguments);
};
}(i);
})(i);
}
}
@ -883,7 +943,7 @@ Object.defineProperty(Readable.prototype, 'readableHighWaterMark', {
enumerable: false,
get: function () {
return this._readableState.highWaterMark;
}
},
});
// exposed for testing purposes only.
@ -898,9 +958,12 @@ function fromList(n, state) {
if (state.length === 0) return null;
var ret;
if (state.objectMode) ret = state.buffer.shift();else if (!n || n >= state.length) {
if (state.objectMode) ret = state.buffer.shift();
else if (!n || n >= state.length) {
// read it all, truncate the list
if (state.decoder) ret = state.buffer.join('');else if (state.buffer.length === 1) ret = state.buffer.head.data;else ret = state.buffer.concat(state.length);
if (state.decoder) ret = state.buffer.join('');
else if (state.buffer.length === 1) ret = state.buffer.head.data;
else ret = state.buffer.concat(state.length);
state.buffer.clear();
} else {
// read part of list
@ -938,15 +1001,17 @@ function copyFromBufferString(n, list) {
var c = 1;
var ret = p.data;
n -= ret.length;
while (p = p.next) {
while ((p = p.next)) {
var str = p.data;
var nb = n > str.length ? str.length : n;
if (nb === str.length) ret += str;else ret += str.slice(0, n);
if (nb === str.length) ret += str;
else ret += str.slice(0, n);
n -= nb;
if (n === 0) {
if (nb === str.length) {
++c;
if (p.next) list.head = p.next;else list.head = list.tail = null;
if (p.next) list.head = p.next;
else list.head = list.tail = null;
} else {
list.head = p;
p.data = str.slice(nb);
@ -968,7 +1033,7 @@ function copyFromBuffer(n, list) {
var c = 1;
p.data.copy(ret);
n -= p.data.length;
while (p = p.next) {
while ((p = p.next)) {
var buf = p.data;
var nb = n > buf.length ? buf.length : n;
buf.copy(ret, ret.length - n, 0, nb);
@ -976,7 +1041,8 @@ function copyFromBuffer(n, list) {
if (n === 0) {
if (nb === buf.length) {
++c;
if (p.next) list.head = p.next;else list.head = list.tail = null;
if (p.next) list.head = p.next;
else list.head = list.tail = null;
} else {
list.head = p;
p.data = buf.slice(nb);
@ -994,7 +1060,8 @@ function endReadable(stream) {
// If we get here before consuming all the bytes, then that is a
// bug in node. Should never happen.
if (state.length > 0) throw new Error('"endReadable()" called on non-empty stream');
if (state.length > 0)
throw new Error('"endReadable()" called on non-empty stream');
if (!state.endEmitted) {
state.ended = true;
@ -1016,4 +1083,4 @@ function indexOf(xs, x) {
if (xs[i] === x) return i;
}
return -1;
}
}

View File

@ -81,13 +81,17 @@ function afterTransform(er, data) {
var cb = ts.writecb;
if (!cb) {
return this.emit('error', new Error('write callback called multiple times'));
return this.emit(
'error',
new Error('write callback called multiple times')
);
}
ts.writechunk = null;
ts.writecb = null;
if (data != null) // single equals check for both `null` and `undefined`
if (data != null)
// single equals check for both `null` and `undefined`
this.push(data);
cb(er);
@ -110,7 +114,7 @@ function Transform(options) {
transforming: false,
writecb: null,
writechunk: null,
writeencoding: null
writeencoding: null,
};
// start out asking for a readable event once data is transformed.
@ -122,7 +126,8 @@ function Transform(options) {
this._readableState.sync = false;
if (options) {
if (typeof options.transform === 'function') this._transform = options.transform;
if (typeof options.transform === 'function')
this._transform = options.transform;
if (typeof options.flush === 'function') this._flush = options.flush;
}
@ -169,7 +174,8 @@ Transform.prototype._write = function (chunk, encoding, cb) {
ts.writeencoding = encoding;
if (!ts.transforming) {
var rs = this._readableState;
if (ts.needTransform || rs.needReadable || rs.length < rs.highWaterMark) this._read(rs.highWaterMark);
if (ts.needTransform || rs.needReadable || rs.length < rs.highWaterMark)
this._read(rs.highWaterMark);
}
};
@ -201,14 +207,17 @@ Transform.prototype._destroy = function (err, cb) {
function done(stream, er, data) {
if (er) return stream.emit('error', er);
if (data != null) // single equals check for both `null` and `undefined`
if (data != null)
// single equals check for both `null` and `undefined`
stream.push(data);
// if there's nothing in the write buffer, then that means
// that nothing more will ever be provided
if (stream._writableState.length) throw new Error('Calling transform done when ws.length != 0');
if (stream._writableState.length)
throw new Error('Calling transform done when ws.length != 0');
if (stream._transformState.transforming) throw new Error('Calling transform done when still transforming');
if (stream._transformState.transforming)
throw new Error('Calling transform done when still transforming');
return stream.push(null);
}
}

View File

@ -54,7 +54,13 @@ function CorkedRequest(state) {
/* </replacement> */
/*<replacement>*/
var asyncWrite = !process.browser && ['v0.10', 'v0.9.'].indexOf(process.version.slice(0, 5)) > -1 ? setImmediate : pna.nextTick;
var asyncWrite =
(
!process.browser &&
['v0.10', 'v0.9.'].indexOf(process.version.slice(0, 5)) > -1
) ?
setImmediate
: pna.nextTick;
/*</replacement>*/
/*<replacement>*/
@ -70,7 +76,7 @@ util.inherits = require('inherits');
/*<replacement>*/
var internalUtil = {
deprecate: require('util-deprecate')
deprecate: require('util-deprecate'),
};
/*</replacement>*/
@ -81,7 +87,12 @@ var Stream = require('./internal/streams/stream');
/*<replacement>*/
var Buffer = require('safe-buffer').Buffer;
var OurUint8Array = (typeof global !== 'undefined' ? global : typeof window !== 'undefined' ? window : typeof self !== 'undefined' ? self : {}).Uint8Array || function () {};
var OurUint8Array =
(typeof global !== 'undefined' ? global
: typeof window !== 'undefined' ? window
: typeof self !== 'undefined' ? self
: {}
).Uint8Array || function () {};
function _uint8ArrayToBuffer(chunk) {
return Buffer.from(chunk);
}
@ -113,7 +124,8 @@ function WritableState(options, stream) {
// contains buffers or objects.
this.objectMode = !!options.objectMode;
if (isDuplex) this.objectMode = this.objectMode || !!options.writableObjectMode;
if (isDuplex)
this.objectMode = this.objectMode || !!options.writableObjectMode;
// the point at which write() starts returning false
// Note: 0 is a valid value, means that we always return false if
@ -122,7 +134,10 @@ function WritableState(options, stream) {
var writableHwm = options.writableHighWaterMark;
var defaultHwm = this.objectMode ? 16 : 16 * 1024;
if (hwm || hwm === 0) this.highWaterMark = hwm;else if (isDuplex && (writableHwm || writableHwm === 0)) this.highWaterMark = writableHwm;else this.highWaterMark = defaultHwm;
if (hwm || hwm === 0) this.highWaterMark = hwm;
else if (isDuplex && (writableHwm || writableHwm === 0))
this.highWaterMark = writableHwm;
else this.highWaterMark = defaultHwm;
// cast to ints.
this.highWaterMark = Math.floor(this.highWaterMark);
@ -221,9 +236,14 @@ WritableState.prototype.getBuffer = function getBuffer() {
(function () {
try {
Object.defineProperty(WritableState.prototype, 'buffer', {
get: internalUtil.deprecate(function () {
return this.getBuffer();
}, '_writableState.buffer is deprecated. Use _writableState.getBuffer ' + 'instead.', 'DEP0003')
get: internalUtil.deprecate(
function () {
return this.getBuffer();
},
'_writableState.buffer is deprecated. Use _writableState.getBuffer ' +
'instead.',
'DEP0003'
),
});
} catch (_) {}
})();
@ -231,7 +251,11 @@ WritableState.prototype.getBuffer = function getBuffer() {
// Test _writableState for inheritance to account for Duplex streams,
// whose prototype chain only points to Readable.
var realHasInstance;
if (typeof Symbol === 'function' && Symbol.hasInstance && typeof Function.prototype[Symbol.hasInstance] === 'function') {
if (
typeof Symbol === 'function' &&
Symbol.hasInstance &&
typeof Function.prototype[Symbol.hasInstance] === 'function'
) {
realHasInstance = Function.prototype[Symbol.hasInstance];
Object.defineProperty(Writable, Symbol.hasInstance, {
value: function (object) {
@ -239,7 +263,7 @@ if (typeof Symbol === 'function' && Symbol.hasInstance && typeof Function.protot
if (this !== Writable) return false;
return object && object._writableState instanceof WritableState;
}
},
});
} else {
realHasInstance = function (object) {
@ -300,7 +324,11 @@ function validChunk(stream, state, chunk, cb) {
if (chunk === null) {
er = new TypeError('May not write null values to stream');
} else if (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) {
@ -325,11 +353,13 @@ Writable.prototype.write = function (chunk, encoding, cb) {
encoding = null;
}
if (isBuf) 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 (isBuf || 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, isBuf, chunk, encoding, cb);
}
@ -349,20 +379,47 @@ Writable.prototype.uncork = function () {
if (state.corked) {
state.corked--;
if (!state.writing && !state.corked && !state.bufferProcessing && state.bufferedRequest) clearBuffer(this, state);
if (
!state.writing &&
!state.corked &&
!state.bufferProcessing &&
state.bufferedRequest
)
clearBuffer(this, state);
}
};
Writable.prototype.setDefaultEncoding = function setDefaultEncoding(encoding) {
// node::ParseEncoding() requires lower case.
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);
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') {
if (
!state.objectMode &&
state.decodeStrings !== false &&
typeof chunk === 'string'
) {
chunk = Buffer.from(chunk, encoding);
}
return chunk;
@ -375,7 +432,7 @@ Object.defineProperty(Writable.prototype, 'writableHighWaterMark', {
enumerable: false,
get: function () {
return this._writableState.highWaterMark;
}
},
});
// if we're already writing something, then just put this
@ -405,7 +462,7 @@ function writeOrBuffer(stream, state, isBuf, chunk, encoding, cb) {
encoding: encoding,
isBuf: isBuf,
callback: cb,
next: null
next: null,
};
if (last) {
last.next = state.lastBufferedRequest;
@ -425,7 +482,8 @@ function doWrite(stream, state, writev, len, chunk, encoding, cb) {
state.writecb = cb;
state.writing = true;
state.sync = true;
if (writev) stream._writev(chunk, state.onwrite);else stream._write(chunk, encoding, state.onwrite);
if (writev) stream._writev(chunk, state.onwrite);
else stream._write(chunk, encoding, state.onwrite);
state.sync = false;
}
@ -467,11 +525,17 @@ function onwrite(stream, er) {
onwriteStateUpdate(state);
if (er) onwriteError(stream, state, sync, er, cb);else {
if (er) onwriteError(stream, state, sync, er, cb);
else {
// Check if we're actually ready to finish, but don't emit yet
var finished = needFinish(state);
if (!finished && !state.corked && !state.bufferProcessing && state.bufferedRequest) {
if (
!finished &&
!state.corked &&
!state.bufferProcessing &&
state.bufferedRequest
) {
clearBuffer(stream, state);
}
@ -595,7 +659,13 @@ Writable.prototype.end = function (chunk, encoding, cb) {
};
function needFinish(state) {
return state.ending && state.length === 0 && state.bufferedRequest === null && !state.finished && !state.writing;
return (
state.ending &&
state.length === 0 &&
state.bufferedRequest === null &&
!state.finished &&
!state.writing
);
}
function callFinal(stream, state) {
stream._final(function (err) {
@ -637,7 +707,8 @@ function endWritable(stream, state, cb) {
state.ending = true;
finishMaybe(stream, state);
if (cb) {
if (state.finished) pna.nextTick(cb);else stream.once('finish', cb);
if (state.finished) pna.nextTick(cb);
else stream.once('finish', cb);
}
state.ended = true;
stream.writable = false;
@ -674,7 +745,7 @@ Object.defineProperty(Writable.prototype, 'destroyed', {
// backward compatibility, the user is explicitly
// managing destroyed
this._writableState.destroyed = value;
}
},
});
Writable.prototype.destroy = destroyImpl.destroy;
@ -682,4 +753,4 @@ Writable.prototype._undestroy = destroyImpl.undestroy;
Writable.prototype._destroy = function (err, cb) {
this.end();
cb(err);
};
};

View File

@ -1,6 +1,10 @@
'use strict';
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
function _classCallCheck(instance, Constructor) {
if (!(instance instanceof Constructor)) {
throw new TypeError('Cannot call a class as a function');
}
}
var Buffer = require('safe-buffer').Buffer;
var util = require('util');
@ -9,7 +13,7 @@ function copyBuffer(src, target, offset) {
src.copy(target, offset);
}
module.exports = function () {
module.exports = (function () {
function BufferList() {
_classCallCheck(this, BufferList);
@ -20,7 +24,8 @@ module.exports = function () {
BufferList.prototype.push = function push(v) {
var entry = { data: v, next: null };
if (this.length > 0) this.tail.next = entry;else this.head = entry;
if (this.length > 0) this.tail.next = entry;
else this.head = entry;
this.tail = entry;
++this.length;
};
@ -35,7 +40,8 @@ module.exports = function () {
BufferList.prototype.shift = function shift() {
if (this.length === 0) return;
var ret = this.head.data;
if (this.length === 1) this.head = this.tail = null;else this.head = this.head.next;
if (this.length === 1) this.head = this.tail = null;
else this.head = this.head.next;
--this.length;
return ret;
};
@ -49,9 +55,10 @@ module.exports = function () {
if (this.length === 0) return '';
var p = this.head;
var ret = '' + p.data;
while (p = p.next) {
while ((p = p.next)) {
ret += s + p.data;
}return ret;
}
return ret;
};
BufferList.prototype.concat = function concat(n) {
@ -68,11 +75,11 @@ module.exports = function () {
};
return BufferList;
}();
})();
if (util && util.inspect && util.inspect.custom) {
module.exports.prototype[util.inspect.custom] = function () {
var obj = util.inspect({ length: this.length });
return this.constructor.name + ' ' + obj;
};
}
}

View File

@ -80,5 +80,5 @@ function emitErrorNT(self, err) {
module.exports = {
destroy: destroy,
undestroy: undestroy
};
undestroy: undestroy,
};

View File

@ -1 +1 @@
module.exports = require('./readable').PassThrough
module.exports = require('./readable').PassThrough;

View File

@ -1 +1 @@
module.exports = require('./readable').Transform
module.exports = require('./readable').Transform;

View File

@ -1,8 +1,8 @@
var Stream = require("stream")
var Writable = require("./lib/_stream_writable.js")
var Stream = require('stream');
var Writable = require('./lib/_stream_writable.js');
if (process.env.READABLE_STREAM === 'disable') {
module.exports = Stream && Stream.Writable || Writable
module.exports = (Stream && Stream.Writable) || Writable;
} else {
module.exports = Writable
module.exports = Writable;
}