1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2024-11-25 15:29:32 -05:00

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>
This commit is contained in:
nasa 2023-06-05 21:43:04 +09:00 committed by GitHub
parent 3d582156b6
commit d2047f1337
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 6 additions and 1 deletions

View file

@ -16,5 +16,5 @@ Deno.test("readFileSuccess", async function () {
assert(data instanceof Uint8Array); assert(data instanceof Uint8Array);
assertEquals(new TextDecoder().decode(data as Uint8Array), "hello world"); assertEquals(new TextDecoder().decode(data as Uint8Array), "hello world");
Deno.close(fileHandle.fd); await fileHandle.close();
}); });

View file

@ -24,6 +24,11 @@ export class FileHandle extends EventEmitter {
): Promise<string | Buffer> { ): Promise<string | Buffer> {
return promises.readFile(this, opt); return promises.readFile(this, opt);
} }
close(): Promise<void> {
// Note that Deno.close is not async
return Promise.resolve(Deno.close(this.fd));
}
} }
export default { export default {