Skip to content

Commit

Permalink
squash! update fs.promises.open()
Browse files Browse the repository at this point in the history
  • Loading branch information
bnoordhuis committed Oct 23, 2018
1 parent 4686ff9 commit 43e6f91
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 2 deletions.
5 changes: 3 additions & 2 deletions lib/internal/fs/promises.js
Original file line number Diff line number Diff line change
Expand Up @@ -196,11 +196,12 @@ async function copyFile(src, dest, flags) {
async function open(path, flags, mode) {
path = toPathIfFileURL(path);
validatePath(path);
if (arguments.length < 2) flags = 'r';
const flagsNumber = stringToFlags(flags);
mode = validateMode(mode, 'mode', 0o666);
return new FileHandle(
await binding.openFileHandle(pathModule.toNamespacedPath(path),
stringToFlags(flags),
mode, kUsePromises));
flagsNumber, mode, kUsePromises));
}

async function read(handle, buffer, offset, length, position) {
Expand Down
18 changes: 18 additions & 0 deletions test/parallel/test-fs-open.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,13 @@ fs.open(__filename, 'r', null, common.mustCall((err) => {
assert.ifError(err);
}));

async function promise() {
await fs.promises.open(__filename);
await fs.promises.open(__filename, 'r');
}

promise().then(common.mustCall()).catch(common.mustNotCall());

common.expectsError(
() => fs.open(__filename, 'r', 'boom', common.mustNotCall()),
{
Expand Down Expand Up @@ -91,4 +98,15 @@ for (const extra of [[], ['r'], ['r', 0], ['r', 0, 'bad callback']]) {
type: TypeError
}
);
fs.promises.open(i, 'r')
.then(common.mustNotCall())
.catch(common.mustCall((err) => {
common.expectsError(
() => { throw err; },
{
code: 'ERR_INVALID_ARG_TYPE',
type: TypeError
}
);
}));
});

0 comments on commit 43e6f91

Please sign in to comment.