Skip to content

Commit 121725f

Browse files
committed
lib: call normalizeEncoding in fs.writeFileSync and fs.readFileSync
1 parent f46152f commit 121725f

File tree

2 files changed

+4
-3
lines changed

2 files changed

+4
-3
lines changed

benchmark/fs/bench-writeFileSync.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ tmpdir.refresh();
77

88
// Some variants are commented out as they do not show a change and just slow
99
const bench = common.createBenchmark(main, {
10-
encoding: ['utf8'],
10+
encoding: ['utf8', 'UTF8'],
1111
useFd: ['true', 'false'],
1212
length: [1024, 102400, 1024 * 1024],
1313

lib/fs.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@ const {
9292
custom: kCustomPromisifiedSymbol,
9393
},
9494
SideEffectFreeRegExpPrototypeExec,
95+
normalizeEncoding,
9596
defineLazyProperties,
9697
isWindows,
9798
isMacOS,
@@ -428,7 +429,7 @@ function tryReadSync(fd, isUserFd, buffer, pos, len) {
428429
function readFileSync(path, options) {
429430
options = getOptions(options, { flag: 'r' });
430431

431-
if (options.encoding === 'utf8' || options.encoding === 'utf-8') {
432+
if (normalizeEncoding(options.encoding) === 'utf8') {
432433
if (!isInt32(path)) {
433434
path = getValidatedPath(path);
434435
}
@@ -2383,7 +2384,7 @@ function writeFileSync(path, data, options) {
23832384
const flag = options.flag || 'w';
23842385

23852386
// C++ fast path for string data and UTF8 encoding
2386-
if (typeof data === 'string' && (options.encoding === 'utf8' || options.encoding === 'utf-8')) {
2387+
if (typeof data === 'string' && normalizeEncoding(options.encoding) === 'utf8') {
23872388
if (!isInt32(path)) {
23882389
path = getValidatedPath(path);
23892390
}

0 commit comments

Comments
 (0)