Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions lib/fs.js
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ const {
SideEffectFreeRegExpPrototypeExec,
defineLazyProperties,
isWindows,
normalizeEncoding,
isMacOS,
} = require('internal/util');
const {
Expand Down Expand Up @@ -489,7 +490,8 @@ function readFileSync(path, options) {
}
options = getOptions(options, { flag: 'r' });

if (options.encoding === 'utf8' || options.encoding === 'utf-8') {
const encoding = normalizeEncoding(options.encoding) || options.encoding;
if (encoding === 'utf8') {
Comment on lines +493 to +494
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
const encoding = normalizeEncoding(options.encoding) || options.encoding;
if (encoding === 'utf8') {
if (options.encoding && normalizeEncoding(options.encoding) === 'utf8') {

user sended a real utf8 encoding only use fast path, otherwise we return string instead of a buffer, thats add a null condition better

if (!isInt32(path)) {
path = getValidatedPath(path);
}
Expand Down Expand Up @@ -2845,7 +2847,8 @@ 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')) {
const encoding = normalizeEncoding(options.encoding) || options.encoding;
if (typeof data === 'string' && encoding === 'utf8') {
Comment on lines +2850 to +2851
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ditto

if (!isInt32(path)) {
path = getValidatedPath(path);
}
Expand Down
Loading