@@ -60,6 +60,7 @@ const {
6060
6161const pathModule = require ( 'path' ) ;
6262const { isAbsolute } = pathModule ;
63+
6364const { isArrayBufferView } = require ( 'internal/util/types' ) ;
6465
6566const binding = internalBinding ( 'fs' ) ;
@@ -92,6 +93,7 @@ const {
9293 custom : kCustomPromisifiedSymbol ,
9394 } ,
9495 SideEffectFreeRegExpPrototypeExec,
96+ normalizeEncoding,
9597 defineLazyProperties,
9698 isWindows,
9799 isMacOS,
@@ -428,7 +430,7 @@ function tryReadSync(fd, isUserFd, buffer, pos, len) {
428430function readFileSync ( path , options ) {
429431 options = getOptions ( options , { flag : 'r' } ) ;
430432
431- if ( options . encoding === 'utf8' || options . encoding === 'utf-8 ') {
433+ if ( normalizeEncoding ( options . encoding ) === 'utf8' ) {
432434 if ( ! isInt32 ( path ) ) {
433435 path = getValidatedPath ( path ) ;
434436 }
@@ -2383,7 +2385,7 @@ function writeFileSync(path, data, options) {
23832385 const flag = options . flag || 'w' ;
23842386
23852387 // C++ fast path for string data and UTF8 encoding
2386- if ( typeof data === 'string' && ( options . encoding === 'utf8' || options . encoding === 'utf-8' ) ) {
2388+ if ( typeof data === 'string' && normalizeEncoding ( options . encoding ) === 'utf8' ) {
23872389 if ( ! isInt32 ( path ) ) {
23882390 path = getValidatedPath ( path ) ;
23892391 }
0 commit comments