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:
parent
3d582156b6
commit
d2047f1337
2 changed files with 6 additions and 1 deletions
|
@ -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();
|
||||||
});
|
});
|
||||||
|
|
|
@ -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 {
|
||||||
|
|
Loading…
Reference in a new issue