@@ -443,21 +443,21 @@ Writable.prototype.pipe = function() {
443
443
function _write ( stream , chunk , encoding , cb ) {
444
444
const state = stream . _writableState ;
445
445
446
- if ( typeof encoding === 'function' ) {
447
- cb = encoding ;
448
- encoding = ( state [ kState ] & kDefaultUTF8Encoding ) !== 0 ? 'utf8' : state . defaultEncoding ;
449
- } else {
450
- if ( ! encoding )
451
- encoding = ( state [ kState ] & kDefaultUTF8Encoding ) !== 0 ? 'utf8' : state . defaultEncoding ;
452
- else if ( encoding !== 'buffer' && ! Buffer . isEncoding ( encoding ) )
453
- throw new ERR_UNKNOWN_ENCODING ( encoding ) ;
454
- if ( typeof cb !== 'function' )
455
- cb = nop ;
446
+ if ( cb == null || typeof cb !== 'function' ) {
447
+ cb = nop ;
456
448
}
457
449
458
450
if ( chunk === null ) {
459
451
throw new ERR_STREAM_NULL_VALUES ( ) ;
460
- } else if ( ( state [ kState ] & kObjectMode ) === 0 ) {
452
+ }
453
+
454
+ if ( ( state [ kState ] & kObjectMode ) === 0 ) {
455
+ if ( ! encoding ) {
456
+ encoding = ( state [ kState ] & kDefaultUTF8Encoding ) !== 0 ? 'utf8' : state . defaultEncoding ;
457
+ } else if ( encoding !== 'buffer' && ! Buffer . isEncoding ( encoding ) ) {
458
+ throw new ERR_UNKNOWN_ENCODING ( encoding ) ;
459
+ }
460
+
461
461
if ( typeof chunk === 'string' ) {
462
462
if ( ( state [ kState ] & kDecodeStrings ) !== 0 ) {
463
463
chunk = Buffer . from ( chunk , encoding ) ;
@@ -486,11 +486,17 @@ function _write(stream, chunk, encoding, cb) {
486
486
errorOrDestroy ( stream , err , true ) ;
487
487
return err ;
488
488
}
489
+
489
490
state . pendingcb ++ ;
490
491
return writeOrBuffer ( stream , state , chunk , encoding , cb ) ;
491
492
}
492
493
493
494
Writable . prototype . write = function ( chunk , encoding , cb ) {
495
+ if ( encoding != null && typeof encoding === 'function' ) {
496
+ cb = encoding ;
497
+ encoding = null ;
498
+ }
499
+
494
500
return _write ( this , chunk , encoding , cb ) === true ;
495
501
} ;
496
502
0 commit comments