diff options
author | nasa <htilcs1115@gmail.com> | 2023-06-05 21:43:04 +0900 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-06-05 06:43:04 -0600 |
commit | d2047f1337ccb5e27598308bf5fefa913eeaa34f (patch) | |
tree | c9d7199a31012a06eb79421f730968bb7d294173 | |
parent | 3d582156b6c17ef5adef1500cdfc80783f6afe68 (diff) |
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 <matthew@mastracci.com>
-rw-r--r-- | cli/tests/unit_node/_fs/_fs_handle_test.ts | 2 | ||||
-rw-r--r-- | ext/node/polyfills/internal/fs/handle.ts | 5 |
2 files changed, 6 insertions, 1 deletions
diff --git a/cli/tests/unit_node/_fs/_fs_handle_test.ts b/cli/tests/unit_node/_fs/_fs_handle_test.ts index c1e5ef871..165608e1c 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 a369a4a4d..a1ee263ea 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<string | Buffer> { return promises.readFile(this, opt); } + + close(): Promise<void> { + // Note that Deno.close is not async + return Promise.resolve(Deno.close(this.fd)); + } } export default { |