Skip to content

Commit 43e6f91

Browse files
committed
squash! update fs.promises.open()
1 parent 4686ff9 commit 43e6f91

File tree

2 files changed

+21
-2
lines changed

2 files changed

+21
-2
lines changed

lib/internal/fs/promises.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -196,11 +196,12 @@ async function copyFile(src, dest, flags) {
196196
async function open(path, flags, mode) {
197197
path = toPathIfFileURL(path);
198198
validatePath(path);
199+
if (arguments.length < 2) flags = 'r';
200+
const flagsNumber = stringToFlags(flags);
199201
mode = validateMode(mode, 'mode', 0o666);
200202
return new FileHandle(
201203
await binding.openFileHandle(pathModule.toNamespacedPath(path),
202-
stringToFlags(flags),
203-
mode, kUsePromises));
204+
flagsNumber, mode, kUsePromises));
204205
}
205206

206207
async function read(handle, buffer, offset, length, position) {

test/parallel/test-fs-open.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,13 @@ fs.open(__filename, 'r', null, common.mustCall((err) => {
5858
assert.ifError(err);
5959
}));
6060

61+
async function promise() {
62+
await fs.promises.open(__filename);
63+
await fs.promises.open(__filename, 'r');
64+
}
65+
66+
promise().then(common.mustCall()).catch(common.mustNotCall());
67+
6168
common.expectsError(
6269
() => fs.open(__filename, 'r', 'boom', common.mustNotCall()),
6370
{
@@ -91,4 +98,15 @@ for (const extra of [[], ['r'], ['r', 0], ['r', 0, 'bad callback']]) {
9198
type: TypeError
9299
}
93100
);
101+
fs.promises.open(i, 'r')
102+
.then(common.mustNotCall())
103+
.catch(common.mustCall((err) => {
104+
common.expectsError(
105+
() => { throw err; },
106+
{
107+
code: 'ERR_INVALID_ARG_TYPE',
108+
type: TypeError
109+
}
110+
);
111+
}));
94112
});

0 commit comments

Comments
 (0)