diff --git a/benchmark/fs/bench-writeFileSync.js b/benchmark/fs/bench-writeFileSync.js index 29c16f4aa2a12d..dfa8a19e6f0721 100644 --- a/benchmark/fs/bench-writeFileSync.js +++ b/benchmark/fs/bench-writeFileSync.js @@ -7,7 +7,7 @@ tmpdir.refresh(); // Some variants are commented out as they do not show a change and just slow const bench = common.createBenchmark(main, { - encoding: ['utf8'], + encoding: ['utf8', 'UTF8'], useFd: ['true', 'false'], length: [1024, 102400, 1024 * 1024], diff --git a/lib/fs.js b/lib/fs.js index 618e48a2b892be..2384a5202e5f42 100644 --- a/lib/fs.js +++ b/lib/fs.js @@ -92,6 +92,7 @@ const { custom: kCustomPromisifiedSymbol, }, SideEffectFreeRegExpPrototypeExec, + normalizeEncoding, defineLazyProperties, isWindows, isMacOS, @@ -428,7 +429,7 @@ function tryReadSync(fd, isUserFd, buffer, pos, len) { function readFileSync(path, options) { options = getOptions(options, { flag: 'r' }); - if (options.encoding === 'utf8' || options.encoding === 'utf-8') { + if (options.encoding && normalizeEncoding(options.encoding) === 'utf8') { if (!isInt32(path)) { path = getValidatedPath(path); } @@ -2383,7 +2384,7 @@ function writeFileSync(path, data, options) { const flag = options.flag || 'w'; // C++ fast path for string data and UTF8 encoding - if (typeof data === 'string' && (options.encoding === 'utf8' || options.encoding === 'utf-8')) { + if (typeof data === 'string' && normalizeEncoding(options.encoding) === 'utf8') { if (!isInt32(path)) { path = getValidatedPath(path); }