Skip to content

Commit b5305d0

Browse files
committed
fs: use w flag for writeFileSync when flag not specified
1 parent 2f40652 commit b5305d0

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

lib/fs.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2343,6 +2343,8 @@ function writeFileSync(path, data, options) {
23432343

23442344
validateBoolean(flush, 'options.flush');
23452345

2346+
const flag = options.flag || 'w';
2347+
23462348
// C++ fast path for string data and UTF8 encoding
23472349
if (typeof data === 'string' && (options.encoding === 'utf8' || options.encoding === 'utf-8')) {
23482350
if (!isInt32(path)) {
@@ -2351,7 +2353,7 @@ function writeFileSync(path, data, options) {
23512353

23522354
return binding.writeFileUtf8(
23532355
path, data,
2354-
stringToFlags(options.flag),
2356+
stringToFlags(flag),
23552357
parseFileMode(options.mode, 'mode', 0o666),
23562358
);
23572359
}
@@ -2361,8 +2363,6 @@ function writeFileSync(path, data, options) {
23612363
data = Buffer.from(data, options.encoding || 'utf8');
23622364
}
23632365

2364-
const flag = options.flag || 'w';
2365-
23662366
const isUserFd = isFd(path); // File descriptor ownership
23672367
const fd = isUserFd ? path : fs.openSync(path, flag, options.mode);
23682368

0 commit comments

Comments
 (0)