summaryrefslogtreecommitdiff
path: root/ext/node/polyfills/internal
diff options
context:
space:
mode:
authorYoshiya Hinosawa <stibium121@gmail.com>2024-09-11 18:08:40 +0900
committerGitHub <noreply@github.com>2024-09-11 11:08:40 +0200
commit8bdd364dd568f93097ecee41e66c74d16d75c015 (patch)
treeae124042299ed91ee81c0a9b455e1f972be1a9e9 /ext/node/polyfills/internal
parent87bc47b3bf9afe26e33450757b13c3b14b8703d8 (diff)
fix(ext/node): add `FileHandle#writeFile` (#25555)
This PR adds `writeFile` methods of `FileHandle` class https://nodejs.org/api/fs.html#filehandlewritefiledata-options
Diffstat (limited to 'ext/node/polyfills/internal')
-rw-r--r--ext/node/polyfills/internal/fs/handle.ts16
1 files changed, 16 insertions, 0 deletions
diff --git a/ext/node/polyfills/internal/fs/handle.ts b/ext/node/polyfills/internal/fs/handle.ts
index e422e2ba0..fc3a7ae20 100644
--- a/ext/node/polyfills/internal/fs/handle.ts
+++ b/ext/node/polyfills/internal/fs/handle.ts
@@ -133,12 +133,28 @@ export class FileHandle extends EventEmitter {
}
}
+ writeFile(data, options): Promise<void> {
+ return fsCall(promises.writeFile, this, data, options);
+ }
+
close(): Promise<void> {
// Note that Deno.close is not async
return Promise.resolve(core.close(this.fd));
}
}
+function fsCall(fn, handle, ...args) {
+ if (handle.fd === -1) {
+ const err = new Error("file closed");
+ throw Object.assign(err, {
+ code: "EBADF",
+ syscall: fn.name,
+ });
+ }
+
+ return fn(handle, ...args);
+}
+
export default {
FileHandle,
};