Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit a0f5207

Browse filesBrowse files
ronagtargos
authored andcommitted
stream: simplify isBuf
PR-URL: #31067 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de> Reviewed-By: Denys Otrishko <shishugi@gmail.com>
1 parent 83f8939 commit a0f5207
Copy full SHA for a0f5207

File tree

Expand file treeCollapse file tree

1 file changed

+9
-20
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

1 file changed

+9
-20
lines changed
Open diff view settings
Collapse file

‎lib/_stream_writable.js‎

Copy file name to clipboardExpand all lines: lib/_stream_writable.js
+9-20Lines changed: 9 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -313,7 +313,7 @@ Writable.prototype.write = function(chunk, encoding, cb) {
313313
writeAfterEnd(this, cb);
314314
else if (isBuf || validChunk(this, state, chunk, cb)) {
315315
state.pendingcb++;
316-
ret = writeOrBuffer(this, state, isBuf, chunk, encoding, cb);
316+
ret = writeOrBuffer(this, state, chunk, encoding, cb);
317317
}
318318

319319
return ret;
@@ -357,15 +357,6 @@ ObjectDefineProperty(Writable.prototype, 'writableBuffer', {
357357
}
358358
});
359359

360-
function decodeChunk(state, chunk, encoding) {
361-
if (!state.objectMode &&
362-
state.decodeStrings !== false &&
363-
typeof chunk === 'string') {
364-
chunk = Buffer.from(chunk, encoding);
365-
}
366-
return chunk;
367-
}
368-
369360
ObjectDefineProperty(Writable.prototype, 'writableEnded', {
370361
// Making it explicit this property is not enumerable
371362
// because otherwise some prototype manipulation in
@@ -399,14 +390,13 @@ ObjectDefineProperty(Writable.prototype, 'writableCorked', {
399390
// If we're already writing something, then just put this
400391
// in the queue, and wait our turn. Otherwise, call _write
401392
// If we return false, then we need a drain event, so set that flag.
402-
function writeOrBuffer(stream, state, isBuf, chunk, encoding, cb) {
403-
if (!isBuf) {
404-
var newChunk = decodeChunk(state, chunk, encoding);
405-
if (chunk !== newChunk) {
406-
isBuf = true;
407-
encoding = 'buffer';
408-
chunk = newChunk;
409-
}
393+
function writeOrBuffer(stream, state, chunk, encoding, cb) {
394+
if (!state.objectMode &&
395+
state.decodeStrings !== false &&
396+
encoding !== 'buffer' &&
397+
typeof chunk === 'string') {
398+
chunk = Buffer.from(chunk, encoding);
399+
encoding = 'buffer';
410400
}
411401
const len = state.objectMode ? 1 : chunk.length;
412402

@@ -422,7 +412,6 @@ function writeOrBuffer(stream, state, isBuf, chunk, encoding, cb) {
422412
state.lastBufferedRequest = {
423413
chunk,
424414
encoding,
425-
isBuf,
426415
callback: cb,
427416
next: null
428417
};
@@ -558,7 +547,7 @@ function clearBuffer(stream, state) {
558547
var allBuffers = true;
559548
while (entry) {
560549
buffer[count] = entry;
561-
if (!entry.isBuf)
550+
if (entry.encoding !== 'buffer')
562551
allBuffers = false;
563552
entry = entry.next;
564553
count += 1;

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.