@@ -313,7 +313,7 @@ Writable.prototype.write = function(chunk, encoding, cb) {
313
313
writeAfterEnd ( this , cb ) ;
314
314
else if ( isBuf || validChunk ( this , state , chunk , cb ) ) {
315
315
state . pendingcb ++ ;
316
- ret = writeOrBuffer ( this , state , isBuf , chunk , encoding , cb ) ;
316
+ ret = writeOrBuffer ( this , state , chunk , encoding , cb ) ;
317
317
}
318
318
319
319
return ret ;
@@ -357,15 +357,6 @@ ObjectDefineProperty(Writable.prototype, 'writableBuffer', {
357
357
}
358
358
} ) ;
359
359
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
-
369
360
ObjectDefineProperty ( Writable . prototype , 'writableEnded' , {
370
361
// Making it explicit this property is not enumerable
371
362
// because otherwise some prototype manipulation in
@@ -399,14 +390,13 @@ ObjectDefineProperty(Writable.prototype, 'writableCorked', {
399
390
// If we're already writing something, then just put this
400
391
// in the queue, and wait our turn. Otherwise, call _write
401
392
// 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' ;
410
400
}
411
401
const len = state . objectMode ? 1 : chunk . length ;
412
402
@@ -422,7 +412,6 @@ function writeOrBuffer(stream, state, isBuf, chunk, encoding, cb) {
422
412
state . lastBufferedRequest = {
423
413
chunk,
424
414
encoding,
425
- isBuf,
426
415
callback : cb ,
427
416
next : null
428
417
} ;
@@ -558,7 +547,7 @@ function clearBuffer(stream, state) {
558
547
var allBuffers = true ;
559
548
while ( entry ) {
560
549
buffer [ count ] = entry ;
561
- if ( ! entry . isBuf )
550
+ if ( entry . encoding !== 'buffer' )
562
551
allBuffers = false ;
563
552
entry = entry . next ;
564
553
count += 1 ;
0 commit comments