From 2f47ec6c3a583c8323a06c386feeaee4fbf75edc Mon Sep 17 00:00:00 2001 From: Asher Gomez Date: Wed, 24 Jan 2024 10:31:52 +1100 Subject: feat: `Deno.FsFile.dataSync()` and `Deno.FsFile.dataSyncSync()` (#22019) This change: 1. Implements `Deno.FsFile.dataSync()` and `Deno.FsFile.dataSyncSync()`. 2. Deprecates `Deno.fdatasync()` and `Deno.fdatasyncSync()` for removal in Deno v2, in favour of the above corresponding methods. 3. Replaces use of `Deno.fdatasync()` and `Deno.fdatasyncSync()` with the above instance methods. Related #21995 --- cli/tsc/dts/lib.deno.ns.d.ts | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) (limited to 'cli/tsc/dts/lib.deno.ns.d.ts') diff --git a/cli/tsc/dts/lib.deno.ns.d.ts b/cli/tsc/dts/lib.deno.ns.d.ts index 83292f2dd..e32b90b41 100644 --- a/cli/tsc/dts/lib.deno.ns.d.ts +++ b/cli/tsc/dts/lib.deno.ns.d.ts @@ -2203,6 +2203,9 @@ declare namespace Deno { * console.log(await Deno.readTextFile("my_file.txt")); // Hello World * ``` * + * @deprecated Use {@linkcode Deno.FsFile.dataSync} instead. + * {@linkcode Deno.fdatasync} will be removed in v2.0.0. + * * @category I/O */ export function fdatasync(rid: number): Promise; @@ -2221,6 +2224,9 @@ declare namespace Deno { * console.log(Deno.readTextFileSync("my_file.txt")); // Hello World * ``` * + * @deprecated Use {@linkcode Deno.FsFile.dataSyncSync} instead. + * {@linkcode Deno.fdatasyncSync} will be removed in v2.0.0. + * * @category I/O */ export function fdatasyncSync(rid: number): void; @@ -2524,6 +2530,38 @@ declare namespace Deno { * ``` */ statSync(): FileInfo; + /** + * Flushes any pending data operations of the given file stream to disk. + * ```ts + * using file = await Deno.open( + * "my_file.txt", + * { read: true, write: true, create: true }, + * ); + * await file.write(new TextEncoder().encode("Hello World")); + * await file.dataSync(); + * console.log(await Deno.readTextFile("my_file.txt")); // Hello World + * ``` + * + * @category I/O + */ + dataSync(): Promise; + /** + * Synchronously flushes any pending data operations of the given file stream + * to disk. + * + * ```ts + * using file = Deno.openSync( + * "my_file.txt", + * { read: true, write: true, create: true }, + * ); + * file.writeSync(new TextEncoder().encode("Hello World")); + * file.dataSyncSync(); + * console.log(Deno.readTextFileSync("my_file.txt")); // Hello World + * ``` + * + * @category I/O + */ + dataSyncSync(): void; /** Close the file. Closing a file when you are finished with it is * important to avoid leaking resources. * -- cgit v1.2.3