1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2024-11-28 16:20:57 -05:00

fix(ext/node): fix no arg call of fs.promises.readFile (#22030)

This commit is contained in:
Yoshiya Hinosawa 2024-01-23 12:59:39 +09:00 committed by GitHub
parent 7e4145df25
commit 2af0c0a3c6
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 18 additions and 7 deletions

View file

@ -1,6 +1,6 @@
// Copyright 2018-2024 the Deno authors. All rights reserved. MIT license. // Copyright 2018-2024 the Deno authors. All rights reserved. MIT license.
import { assertCallbackErrorUncaught } from "../_test_utils.ts"; import { assertCallbackErrorUncaught } from "../_test_utils.ts";
import { readFile, readFileSync } from "node:fs"; import { promises, readFile, readFileSync } from "node:fs";
import * as path from "../../../../test_util/std/path/mod.ts"; import * as path from "../../../../test_util/std/path/mod.ts";
import { assert, assertEquals } from "../../../../test_util/std/assert/mod.ts"; import { assert, assertEquals } from "../../../../test_util/std/assert/mod.ts";
@ -116,3 +116,8 @@ Deno.test("[std/node/fs] readFile callback isn't called twice if error is thrown
}, },
}); });
}); });
Deno.test("fs.promises.readFile with no arg call rejects with error correctly", async () => {
// @ts-ignore no arg call needs to be supported
await promises.readFile().catch((_e) => {});
});

View file

@ -18,7 +18,6 @@ import {
Encodings, Encodings,
TextEncodings, TextEncodings,
} from "ext:deno_node/_utils.ts"; } from "ext:deno_node/_utils.ts";
import { promisify } from "ext:deno_node/internal/util.mjs";
function maybeDecode(data: Uint8Array, encoding: TextEncodings): string; function maybeDecode(data: Uint8Array, encoding: TextEncodings): string;
function maybeDecode( function maybeDecode(
@ -91,11 +90,18 @@ export function readFile(
} }
} }
export const readFilePromise = promisify(readFile) as ( export function readFilePromise(
& ((path: Path, opt: TextOptionsArgument) => Promise<string>) path: Path,
& ((path: Path, opt?: BinaryOptionsArgument) => Promise<Buffer>) options?: FileOptionsArgument | null | undefined,
& ((path: Path, opt?: FileOptionsArgument) => Promise<Buffer>) // deno-lint-ignore no-explicit-any
); ): Promise<any> {
return new Promise((resolve, reject) => {
readFile(path, options, (err, data) => {
if (err) reject(err);
else resolve(data);
});
});
}
export function readFileSync( export function readFileSync(
path: string | URL, path: string | URL,