summaryrefslogtreecommitdiff
path: root/ext/node/polyfills/internal/fs
diff options
context:
space:
mode:
Diffstat (limited to 'ext/node/polyfills/internal/fs')
-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,
};