Skip to content

Commit 1463214

Browse files
ronagBridgeAR
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 9141366 commit 1463214

1 file changed

Lines changed: 9 additions & 20 deletions

File tree

‎lib/_stream_writable.js‎

Lines changed: 9 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -323,7 +323,7 @@ Writable.prototype.write = function(chunk, encoding, cb) {
323323
errorOrDestroy(this,err);
324324
}elseif(isBuf||validChunk(this,state,chunk,cb)){
325325
state.pendingcb++;
326-
ret=writeOrBuffer(this,state,isBuf,chunk,encoding,cb);
326+
ret=writeOrBuffer(this,state,chunk,encoding,cb);
327327
}
328328

329329
returnret;
@@ -367,15 +367,6 @@ ObjectDefineProperty(Writable.prototype, 'writableBuffer', {
367367
}
368368
});
369369

370-
functiondecodeChunk(state,chunk,encoding){
371-
if(!state.objectMode&&
372-
state.decodeStrings!==false&&
373-
typeofchunk==='string'){
374-
chunk=Buffer.from(chunk,encoding);
375-
}
376-
returnchunk;
377-
}
378-
379370
ObjectDefineProperty(Writable.prototype,'writableEnded',{
380371
// Making it explicit this property is not enumerable
381372
// because otherwise some prototype manipulation in
@@ -409,14 +400,13 @@ ObjectDefineProperty(Writable.prototype, 'writableCorked', {
409400
// If we're already writing something, then just put this
410401
// in the queue, and wait our turn. Otherwise, call _write
411402
// If we return false, then we need a drain event, so set that flag.
412-
functionwriteOrBuffer(stream,state,isBuf,chunk,encoding,cb){
413-
if(!isBuf){
414-
varnewChunk=decodeChunk(state,chunk,encoding);
415-
if(chunk!==newChunk){
416-
isBuf=true;
417-
encoding='buffer';
418-
chunk=newChunk;
419-
}
403+
functionwriteOrBuffer(stream,state,chunk,encoding,cb){
404+
if(!state.objectMode&&
405+
state.decodeStrings!==false&&
406+
encoding!=='buffer'&&
407+
typeofchunk==='string'){
408+
chunk=Buffer.from(chunk,encoding);
409+
encoding='buffer';
420410
}
421411
constlen=state.objectMode ? 1 : chunk.length;
422412

@@ -432,7 +422,6 @@ function writeOrBuffer(stream, state, isBuf, chunk, encoding, cb) {
432422
state.lastBufferedRequest={
433423
chunk,
434424
encoding,
435-
isBuf,
436425
callback: cb,
437426
next: null
438427
};
@@ -559,7 +548,7 @@ function clearBuffer(stream, state) {
559548
varallBuffers=true;
560549
while(entry){
561550
buffer[count]=entry;
562-
if(!entry.isBuf)
551+
if(entry.encoding!=='buffer')
563552
allBuffers=false;
564553
entry=entry.next;
565554
count+=1;

0 commit comments

Comments
 (0)