@@ -262,12 +262,6 @@ Writable.prototype.pipe = function() {
262
262
263
263
Writable . prototype . write = function ( chunk , encoding , cb ) {
264
264
const state = this . _writableState ;
265
- const isBuf = ! state . objectMode && Stream . _isUint8Array ( chunk ) ;
266
-
267
- // Do not use Object.getPrototypeOf as it is slower since V8 7.3.
268
- if ( isBuf && ! ( chunk instanceof Buffer ) ) {
269
- chunk = Stream . _uint8ArrayToBuffer ( chunk ) ;
270
- }
271
265
272
266
if ( typeof encoding === 'function' ) {
273
267
cb = encoding ;
@@ -279,34 +273,38 @@ Writable.prototype.write = function(chunk, encoding, cb) {
279
273
cb = nop ;
280
274
}
281
275
282
- if ( isBuf )
283
- encoding = 'buffer' ;
284
-
285
276
let err ;
286
277
if ( state . ending ) {
287
278
err = new ERR_STREAM_WRITE_AFTER_END ( ) ;
288
279
} else if ( state . destroyed ) {
289
280
err = new ERR_STREAM_DESTROYED ( 'write' ) ;
290
281
} else if ( chunk === null ) {
291
282
err = new ERR_STREAM_NULL_VALUES ( ) ;
292
- } else {
293
- if ( ! isBuf && ! state . objectMode ) {
294
- if ( typeof chunk !== 'string' ) {
295
- err = new ERR_INVALID_ARG_TYPE ( 'chunk' , [ 'string' , 'Buffer' ] , chunk ) ;
296
- } else if ( encoding !== 'buffer' && state . decodeStrings !== false ) {
283
+ } else if ( ! state . objectMode ) {
284
+ if ( typeof chunk === 'string' ) {
285
+ if ( state . decodeStrings !== false ) {
297
286
chunk = Buffer . from ( chunk , encoding ) ;
298
287
encoding = 'buffer' ;
299
288
}
300
- }
301
- if ( err === undefined ) {
302
- state . pendingcb ++ ;
303
- return writeOrBuffer ( this , state , chunk , encoding , cb ) ;
289
+ } else if ( chunk instanceof Buffer ) {
290
+ encoding = 'buffer' ;
291
+ } else if ( Stream . _isUint8Array ( chunk ) ) {
292
+ chunk = Stream . _uint8ArrayToBuffer ( chunk ) ;
293
+ encoding = 'buffer' ;
294
+ } else {
295
+ err = new ERR_INVALID_ARG_TYPE (
296
+ 'chunk' , [ 'string' , 'Buffer' , 'Uint8Array' ] , chunk ) ;
304
297
}
305
298
}
306
299
307
- process . nextTick ( cb , err ) ;
308
- errorOrDestroy ( this , err , true ) ;
309
- return false ;
300
+ if ( err ) {
301
+ process . nextTick ( cb , err ) ;
302
+ errorOrDestroy ( this , err , true ) ;
303
+ return false ;
304
+ } else {
305
+ state . pendingcb ++ ;
306
+ return writeOrBuffer ( this , state , chunk , encoding , cb ) ;
307
+ }
310
308
} ;
311
309
312
310
Writable . prototype . cork = function ( ) {
0 commit comments