mirror of
https://github.com/zebrajr/node.git
synced 2026-01-15 12:15:26 +00:00
stream: simplify isBuf
PR-URL: https://github.com/nodejs/node/pull/31067 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de> Reviewed-By: Denys Otrishko <shishugi@gmail.com>
This commit is contained in:
committed by
Ruben Bridgewater
parent
5661466921
commit
cd6b00df33
@@ -323,7 +323,7 @@ Writable.prototype.write = function(chunk, encoding, cb) {
|
||||
errorOrDestroy(this, err);
|
||||
} else if (isBuf || validChunk(this, state, chunk, cb)) {
|
||||
state.pendingcb++;
|
||||
ret = writeOrBuffer(this, state, isBuf, chunk, encoding, cb);
|
||||
ret = writeOrBuffer(this, state, chunk, encoding, cb);
|
||||
}
|
||||
|
||||
return ret;
|
||||
@@ -367,15 +367,6 @@ ObjectDefineProperty(Writable.prototype, 'writableBuffer', {
|
||||
}
|
||||
});
|
||||
|
||||
function decodeChunk(state, chunk, encoding) {
|
||||
if (!state.objectMode &&
|
||||
state.decodeStrings !== false &&
|
||||
typeof chunk === 'string') {
|
||||
chunk = Buffer.from(chunk, encoding);
|
||||
}
|
||||
return chunk;
|
||||
}
|
||||
|
||||
ObjectDefineProperty(Writable.prototype, 'writableEnded', {
|
||||
// Making it explicit this property is not enumerable
|
||||
// because otherwise some prototype manipulation in
|
||||
@@ -409,14 +400,13 @@ ObjectDefineProperty(Writable.prototype, 'writableCorked', {
|
||||
// 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, isBuf, chunk, encoding, cb) {
|
||||
if (!isBuf) {
|
||||
var newChunk = decodeChunk(state, chunk, encoding);
|
||||
if (chunk !== newChunk) {
|
||||
isBuf = true;
|
||||
encoding = 'buffer';
|
||||
chunk = newChunk;
|
||||
}
|
||||
function writeOrBuffer(stream, state, chunk, encoding, cb) {
|
||||
if (!state.objectMode &&
|
||||
state.decodeStrings !== false &&
|
||||
encoding !== 'buffer' &&
|
||||
typeof chunk === 'string') {
|
||||
chunk = Buffer.from(chunk, encoding);
|
||||
encoding = 'buffer';
|
||||
}
|
||||
const len = state.objectMode ? 1 : chunk.length;
|
||||
|
||||
@@ -432,7 +422,6 @@ function writeOrBuffer(stream, state, isBuf, chunk, encoding, cb) {
|
||||
state.lastBufferedRequest = {
|
||||
chunk,
|
||||
encoding,
|
||||
isBuf,
|
||||
callback: cb,
|
||||
next: null
|
||||
};
|
||||
@@ -561,7 +550,7 @@ function clearBuffer(stream, state) {
|
||||
var allBuffers = true;
|
||||
while (entry) {
|
||||
buffer[count] = entry;
|
||||
if (!entry.isBuf)
|
||||
if (entry.encoding !== 'buffer')
|
||||
allBuffers = false;
|
||||
entry = entry.next;
|
||||
count += 1;
|
||||
|
||||
Reference in New Issue
Block a user