summaryrefslogtreecommitdiff
path: root/cli/js
diff options
context:
space:
mode:
authorCasper Beyer <caspervonb@pm.me>2020-06-21 21:29:44 +0800
committerGitHub <noreply@github.com>2020-06-21 09:29:44 -0400
commit40866d7cd521a2f33ac60d841e1706c2f68ecc66 (patch)
treea0876c5dd3d63b814490a4a0ca6c511580e2170c /cli/js
parentf24aab81c9c97fe933a9c6d9a02fbc70df60af37 (diff)
feat(unstable): add Deno.fsyncSync and fsync (#6411)
Diffstat (limited to 'cli/js')
-rw-r--r--cli/js/deno_unstable.ts1
-rw-r--r--cli/js/lib.deno.unstable.d.ts24
-rw-r--r--cli/js/ops/fs/sync.ts10
3 files changed, 35 insertions, 0 deletions
diff --git a/cli/js/deno_unstable.ts b/cli/js/deno_unstable.ts
index d8624c675..967eafdcd 100644
--- a/cli/js/deno_unstable.ts
+++ b/cli/js/deno_unstable.ts
@@ -4,6 +4,7 @@
export { umask } from "./ops/fs/umask.ts";
export { linkSync, link } from "./ops/fs/link.ts";
+export { fsyncSync, fsync } from "./ops/fs/sync.ts";
export { symlinkSync, symlink } from "./ops/fs/symlink.ts";
export { loadavg, osRelease, hostname } from "./ops/os.ts";
export { openPlugin } from "./ops/plugins.ts";
diff --git a/cli/js/lib.deno.unstable.d.ts b/cli/js/lib.deno.unstable.d.ts
index 3339bfbac..daecf6604 100644
--- a/cli/js/lib.deno.unstable.d.ts
+++ b/cli/js/lib.deno.unstable.d.ts
@@ -1118,4 +1118,28 @@ declare namespace Deno {
* ```
*/
export function ftruncate(rid: number, len?: number): Promise<void>;
+
+ /** **UNSTABLE**: New API, yet to be vetted.
+ * Synchronously flushes any pending data and metadata operations of the given file stream to disk.
+ * ```ts
+ * const file = Deno.openSync("my_file.txt", { read: true, write: true, create: true });
+ * Deno.writeSync(file.rid, new TextEncoder().encode("Hello World"));
+ * Deno.ftruncateSync(file.rid, 1);
+ * Deno.fsyncSync(file.rid);
+ * console.log(new TextDecoder().decode(Deno.readFileSync("my_file.txt"))); // H
+ * ```
+ */
+ export function fsyncSync(rid: number): void;
+
+ /** **UNSTABLE**: New API, yet to be vetted.
+ * Flushes any pending data and metadata operations of the given file stream to disk.
+ * ```ts
+ * const file = await Deno.open("my_file.txt", { read: true, write: true, create: true });
+ * await Deno.write(file.rid, new TextEncoder().encode("Hello World"));
+ * await Deno.ftruncate(file.rid, 1);
+ * await Deno.fsync(file.rid);
+ * console.log(new TextDecoder().decode(await Deno.readFile("my_file.txt"))); // H
+ * ```
+ */
+ export function fsync(rid: number): Promise<void>;
}
diff --git a/cli/js/ops/fs/sync.ts b/cli/js/ops/fs/sync.ts
new file mode 100644
index 000000000..5d5de7242
--- /dev/null
+++ b/cli/js/ops/fs/sync.ts
@@ -0,0 +1,10 @@
+// Copyright 2018-2020 the Deno authors. All rights reserved. MIT license.
+import { sendSync, sendAsync } from "../dispatch_json.ts";
+
+export function fsyncSync(rid: number): void {
+ sendSync("op_fsync", { rid });
+}
+
+export async function fsync(rid: number): Promise<void> {
+ await sendAsync("op_fsync", { rid });
+}