GeezerVison is showing github.com — stream: avoid getter for defaultEncoding · nodejs/node@b338f3d
File tree
Expand file treeCollapse file tree
Open diff view settings
Expand file treeCollapse file tree
Open diff view settings
Collapse file
Copy file name to clipboardExpand all lines: lib/internal/streams/writable.js +9-8Lines changed: 9 additions & 8 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -445,16 +445,17 @@ function _write(stream, chunk, encoding, cb) { |
445 | 445 |
|
446 | 446 | if (typeof encoding === 'function') { |
447 | 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; |
| 448 | + encoding = null; |
456 | 449 | } |
457 | 450 |
|
| 451 | + if (!encoding) |
| 452 | + encoding = (state[kState] & kDefaultUTF8Encoding) !== 0 ? 'utf8' : state[kDefaultEncodingValue]; |
| 453 | + else if (encoding !== 'buffer' && !Buffer.isEncoding(encoding)) |
| 454 | + throw new ERR_UNKNOWN_ENCODING(encoding); |
| 455 | + |
| 456 | + if (cb == null || typeof cb !== 'function') |
| 457 | + cb = nop; |
| 458 | + |
458 | 459 | if (chunk === null) { |
459 | 460 | throw new ERR_STREAM_NULL_VALUES(); |
460 | 461 | } else if ((state[kState] & kObjectMode) === 0) { |
|