mirror of
https://github.com/zebrajr/node.git
synced 2026-01-15 12:15:26 +00:00
lib: move encodingsMap to internal/util
PR-URL: https://github.com/nodejs/node/pull/51044 Refs: https://github.com/nodejs/performance/issues/136 Reviewed-By: Vinícius Lourenço Claro Cardoso <contact@viniciusl.com.br> Reviewed-By: Yagiz Nizipli <yagiz.nizipli@sentry.io>
This commit is contained in:
@@ -38,15 +38,18 @@ const {
|
||||
kSize,
|
||||
decode,
|
||||
flush,
|
||||
encodings,
|
||||
} = internalBinding('string_decoder');
|
||||
const internalUtil = require('internal/util');
|
||||
const {
|
||||
kIsEncodingSymbol,
|
||||
encodingsMap,
|
||||
normalizeEncoding: _normalizeEncoding,
|
||||
} = require('internal/util');
|
||||
const {
|
||||
ERR_INVALID_ARG_TYPE,
|
||||
ERR_INVALID_THIS,
|
||||
ERR_UNKNOWN_ENCODING,
|
||||
} = require('internal/errors').codes;
|
||||
const isEncoding = Buffer[internalUtil.kIsEncodingSymbol];
|
||||
const isEncoding = Buffer[kIsEncodingSymbol];
|
||||
|
||||
const kNativeDecoder = Symbol('kNativeDecoder');
|
||||
|
||||
@@ -60,7 +63,7 @@ const kNativeDecoder = Symbol('kNativeDecoder');
|
||||
* @throws {TypeError} Throws an error when encoding is invalid
|
||||
*/
|
||||
function normalizeEncoding(enc) {
|
||||
const nenc = internalUtil.normalizeEncoding(enc);
|
||||
const nenc = _normalizeEncoding(enc);
|
||||
if (nenc === undefined) {
|
||||
if (Buffer.isEncoding === isEncoding || !Buffer.isEncoding(enc))
|
||||
throw new ERR_UNKNOWN_ENCODING(enc);
|
||||
@@ -69,10 +72,6 @@ function normalizeEncoding(enc) {
|
||||
return nenc;
|
||||
}
|
||||
|
||||
const encodingsMap = {};
|
||||
for (let i = 0; i < encodings.length; ++i)
|
||||
encodingsMap[encodings[i]] = i;
|
||||
|
||||
/**
|
||||
* StringDecoder provides an interface for efficiently splitting a series of
|
||||
* buffers into a series of JS strings without breaking apart multi-byte
|
||||
|
||||
Reference in New Issue
Block a user