@@ -270,12 +270,6 @@ Writable.prototype.pipe = function() {
270270
271271Writable . prototype . write = function ( chunk , encoding , cb ) {
272272 const state = this . _writableState ;
273- const isBuf = ! state . objectMode && Stream . _isUint8Array ( chunk ) ;
274-
275- // Do not use Object.getPrototypeOf as it is slower since V8 7.3.
276- if ( isBuf && ! ( chunk instanceof Buffer ) ) {
277- chunk = Stream . _uint8ArrayToBuffer ( chunk ) ;
278- }
279273
280274 if ( typeof encoding === 'function' ) {
281275 cb = encoding ;
@@ -287,34 +281,38 @@ Writable.prototype.write = function(chunk, encoding, cb) {
287281 cb = nop ;
288282 }
289283
290- if ( isBuf )
291- encoding = 'buffer' ;
292-
293284 let err ;
294285 if ( state . ending ) {
295286 err = new ERR_STREAM_WRITE_AFTER_END ( ) ;
296287 } else if ( state . destroyed ) {
297288 err = new ERR_STREAM_DESTROYED ( 'write' ) ;
298289 } else if ( chunk === null ) {
299290 err = new ERR_STREAM_NULL_VALUES ( ) ;
300- } else {
301- if ( ! isBuf && ! state . objectMode ) {
302- if ( typeof chunk !== 'string' ) {
303- err = new ERR_INVALID_ARG_TYPE ( 'chunk' , [ 'string' , 'Buffer' ] , chunk ) ;
304- } else if ( encoding !== 'buffer' && state . decodeStrings !== false ) {
291+ } else if ( ! state . objectMode ) {
292+ if ( typeof chunk === 'string' ) {
293+ if ( state . decodeStrings !== false ) {
305294 chunk = Buffer . from ( chunk , encoding ) ;
306295 encoding = 'buffer' ;
307296 }
308- }
309- if ( err === undefined ) {
310- state . pendingcb ++ ;
311- return writeOrBuffer ( this , state , chunk , encoding , cb ) ;
297+ } else if ( chunk instanceof Buffer ) {
298+ encoding = 'buffer' ;
299+ } else if ( Stream . _isUint8Array ( chunk ) ) {
300+ chunk = Stream . _uint8ArrayToBuffer ( chunk ) ;
301+ encoding = 'buffer' ;
302+ } else {
303+ err = new ERR_INVALID_ARG_TYPE (
304+ 'chunk' , [ 'string' , 'Buffer' , 'Uint8Array' ] , chunk ) ;
312305 }
313306 }
314307
315- process . nextTick ( cb , err ) ;
316- errorOrDestroy ( this , err , true ) ;
317- return false ;
308+ if ( err ) {
309+ process . nextTick ( cb , err ) ;
310+ errorOrDestroy ( this , err , true ) ;
311+ return false ;
312+ } else {
313+ state . pendingcb ++ ;
314+ return writeOrBuffer ( this , state , chunk , encoding , cb ) ;
315+ }
318316} ;
319317
320318Writable . prototype . cork = function ( ) {
0 commit comments