mirror of
https://github.com/denoland/deno.git
synced 2025-08-03 10:33:54 +00:00
feat(unstable): add Deno.fsyncSync and fsync (#6411)
This commit is contained in:
parent
f24aab81c9
commit
40866d7cd5
6 changed files with 119 additions and 0 deletions
|
@ -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";
|
||||
|
|
24
cli/js/lib.deno.unstable.d.ts
vendored
24
cli/js/lib.deno.unstable.d.ts
vendored
|
@ -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>;
|
||||
}
|
||||
|
|
10
cli/js/ops/fs/sync.ts
Normal file
10
cli/js/ops/fs/sync.ts
Normal file
|
@ -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 });
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue