diff options
author | Casper Beyer <caspervonb@pm.me> | 2020-06-26 20:36:35 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-06-26 08:36:35 -0400 |
commit | e278c90d8a32f5b9e382956234cfd84b651e98d8 (patch) | |
tree | fa881249f293c882a15fceb1b8f8a1421348b13a /cli/js | |
parent | ed0b1d462718166143b67056c36c7db15cc736d7 (diff) |
feat(unstable): add Deno.fdatasyncSync and fdatasync (#6403)
Diffstat (limited to 'cli/js')
-rw-r--r-- | cli/js/deno_unstable.ts | 2 | ||||
-rw-r--r-- | cli/js/lib.deno.unstable.d.ts | 22 | ||||
-rw-r--r-- | cli/js/ops/fs/sync.ts | 8 |
3 files changed, 31 insertions, 1 deletions
diff --git a/cli/js/deno_unstable.ts b/cli/js/deno_unstable.ts index 2327b554d..e7a0510be 100644 --- a/cli/js/deno_unstable.ts +++ b/cli/js/deno_unstable.ts @@ -5,7 +5,7 @@ export { umask } from "./ops/fs/umask.ts"; export { linkSync, link } from "./ops/fs/link.ts"; export { fstatSync, fstat } from "./ops/fs/stat.ts"; -export { fsyncSync, fsync } from "./ops/fs/sync.ts"; +export { fdatasyncSync, fdatasync, 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 cc7dea987..f4a7b2786 100644 --- a/cli/js/lib.deno.unstable.d.ts +++ b/cli/js/lib.deno.unstable.d.ts @@ -1119,6 +1119,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 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.fdatasyncSync(file.rid); + * console.log(new TextDecoder().decode(Deno.readFileSync("my_file.txt"))); // Hello World + * ``` + */ + export function fdatasyncSync(rid: number): void; + + /** **UNSTABLE**: New API, yet to be vetted. + * Flushes any pending data 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.fdatasync(file.rid); + * console.log(new TextDecoder().decode(await Deno.readFile("my_file.txt"))); // Hello World + * ``` + */ + export function fdatasync(rid: 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 diff --git a/cli/js/ops/fs/sync.ts b/cli/js/ops/fs/sync.ts index 5d5de7242..567aab55b 100644 --- a/cli/js/ops/fs/sync.ts +++ b/cli/js/ops/fs/sync.ts @@ -1,6 +1,14 @@ // Copyright 2018-2020 the Deno authors. All rights reserved. MIT license. import { sendSync, sendAsync } from "../dispatch_json.ts"; +export function fdatasyncSync(rid: number): void { + sendSync("op_fdatasync", { rid }); +} + +export async function fdatasync(rid: number): Promise<void> { + await sendAsync("op_fdatasync", { rid }); +} + export function fsyncSync(rid: number): void { sendSync("op_fsync", { rid }); } |