@@ -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-
369360ObjectDefineProperty ( 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