From 4f7b109b93a585d87dce28f328e838a1c196856a Mon Sep 17 00:00:00 2001 From: nasa Date: Mon, 5 Jun 2023 21:43:04 +0900 Subject: [PATCH] feat(node_compat): Add a close method to the FileHandle class. (#19357) ## WHY ref: https://github.com/denoland/deno/issues/19165 The FileHandle class has many missing methods compared to node. Add these. ## WHAT - Add close method --------- Co-authored-by: Matt Mastracci --- cli/tests/unit_node/_fs/_fs_handle_test.ts | 2 +- ext/node/polyfills/internal/fs/handle.ts | 5 +++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/cli/tests/unit_node/_fs/_fs_handle_test.ts b/cli/tests/unit_node/_fs/_fs_handle_test.ts index c1e5ef8713..165608e1ce 100644 --- a/cli/tests/unit_node/_fs/_fs_handle_test.ts +++ b/cli/tests/unit_node/_fs/_fs_handle_test.ts @@ -16,5 +16,5 @@ Deno.test("readFileSuccess", async function () { assert(data instanceof Uint8Array); assertEquals(new TextDecoder().decode(data as Uint8Array), "hello world"); - Deno.close(fileHandle.fd); + await fileHandle.close(); }); diff --git a/ext/node/polyfills/internal/fs/handle.ts b/ext/node/polyfills/internal/fs/handle.ts index a369a4a4d7..a1ee263ead 100644 --- a/ext/node/polyfills/internal/fs/handle.ts +++ b/ext/node/polyfills/internal/fs/handle.ts @@ -24,6 +24,11 @@ export class FileHandle extends EventEmitter { ): Promise { return promises.readFile(this, opt); } + + close(): Promise { + // Note that Deno.close is not async + return Promise.resolve(Deno.close(this.fd)); + } } export default {