@@ -323,7 +323,7 @@ Writable.prototype.write = function(chunk, encoding, cb) {
323323 errorOrDestroy ( this , err ) ;
324324 } else if ( 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 return ret ;
@@ -367,15 +367,6 @@ ObjectDefineProperty(Writable.prototype, 'writableBuffer', {
367367 }
368368} ) ;
369369
370- function decodeChunk ( state , chunk , encoding ) {
371- if ( ! state . objectMode &&
372- state . decodeStrings !== false &&
373- typeof chunk === 'string' ) {
374- chunk = Buffer . from ( chunk , encoding ) ;
375- }
376- return chunk ;
377- }
378-
379370ObjectDefineProperty ( 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- function writeOrBuffer ( stream , state , isBuf , chunk , encoding , cb ) {
413- if ( ! isBuf ) {
414- var newChunk = decodeChunk ( state , chunk , encoding ) ;
415- if ( chunk !== newChunk ) {
416- isBuf = true ;
417- encoding = 'buffer' ;
418- chunk = newChunk ;
419- }
403+ function writeOrBuffer ( stream , state , chunk , encoding , cb ) {
404+ if ( ! state . objectMode &&
405+ state . decodeStrings !== false &&
406+ encoding !== 'buffer' &&
407+ typeof chunk === 'string' ) {
408+ chunk = Buffer . from ( chunk , encoding ) ;
409+ encoding = 'buffer' ;
420410 }
421411 const len = 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 } ;
@@ -561,7 +550,7 @@ function clearBuffer(stream, state) {
561550 var allBuffers = true ;
562551 while ( entry ) {
563552 buffer [ count ] = entry ;
564- if ( ! entry . isBuf )
553+ if ( entry . encoding !== 'buffer' )
565554 allBuffers = false ;
566555 entry = entry . next ;
567556 count += 1 ;
0 commit comments