stream: avoid getter for defaultEncoding

PR-URL: https://github.com/nodejs/node/pull/50203
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
This commit is contained in:
Robert Nagy 2023-10-23 14:08:26 +02:00 committed by GitHub
parent 45a0b153b3
commit 8e814e3b82
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 9 additions and 8 deletions

View File

@ -445,16 +445,17 @@ function _write(stream, chunk, encoding, cb) {
if (typeof encoding === 'function') {
cb = encoding;
encoding = (state[kState] & kDefaultUTF8Encoding) !== 0 ? 'utf8' : state.defaultEncoding;
} else {
if (!encoding)
encoding = (state[kState] & kDefaultUTF8Encoding) !== 0 ? 'utf8' : state.defaultEncoding;
else if (encoding !== 'buffer' && !Buffer.isEncoding(encoding))
throw new ERR_UNKNOWN_ENCODING(encoding);
if (typeof cb !== 'function')
cb = nop;
encoding = null;
}
if (!encoding)
encoding = (state[kState] & kDefaultUTF8Encoding) !== 0 ? 'utf8' : state[kDefaultEncodingValue];
else if (encoding !== 'buffer' && !Buffer.isEncoding(encoding))
throw new ERR_UNKNOWN_ENCODING(encoding);
if (cb == null || typeof cb !== 'function')
cb = nop;
if (chunk === null) {
throw new ERR_STREAM_NULL_VALUES();
} else if ((state[kState] & kObjectMode) === 0) {