| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 1c4f4cc commit 9d1b1a3
2 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -270,12 +270,6 @@ Writable.prototype.pipe = function() { | |||
| 270 | 270 | ||
| 271 | 271 | Writable.prototype.write = function(chunk, encoding, cb) { | |
| 272 | 272 | 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 | - } | ||
| 279 | 273 | ||
| 280 | 274 | if (typeof encoding === 'function') { | |
| 281 | 275 | cb = encoding; | |
@@ -287,34 +281,38 @@ Writable.prototype.write = function(chunk, encoding, cb) { | |||
| 287 | 281 | cb = nop; | |
| 288 | 282 | } | |
| 289 | 283 | ||
| 290 | - if (isBuf) | ||
| 291 | - encoding = 'buffer'; | ||
| 292 | - | ||
| 293 | 284 | let err; | |
| 294 | 285 | if (state.ending) { | |
| 295 | 286 | err = new ERR_STREAM_WRITE_AFTER_END(); | |
| 296 | 287 | } else if (state.destroyed) { | |
| 297 | 288 | err = new ERR_STREAM_DESTROYED('write'); | |
| 298 | 289 | } else if (chunk === null) { | |
| 299 | 290 | 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) { | ||
| 305 | 294 | chunk = Buffer.from(chunk, encoding); | |
| 306 | 295 | encoding = 'buffer'; | |
| 307 | 296 | } | |
| 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); | ||
| 312 | 305 | } | |
| 313 | 306 | } | |
| 314 | 307 | ||
| 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 | + } | ||
| 318 | 316 | }; | |
| 319 | 317 | ||
| 320 | 318 | Writable.prototype.cork = function() { | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -29,6 +29,6 @@ assert.throws(() => socket.write(null), | |||
| 29 | 29 | code: 'ERR_INVALID_ARG_TYPE', | |
| 30 | 30 | name: 'TypeError', | |
| 31 | 31 | message: 'The "chunk" argument must be of type string or an instance of ' + | |
| 32 | - `Buffer.${common.invalidArgTypeHelper(value)}` | ||
| 32 | + `Buffer or Uint8Array.${common.invalidArgTypeHelper(value)}` | ||
| 33 | 33 | })); | |
| 34 | 34 | }); | |
| Back | FazBrowse Home | New Git URL |
0 commit comments