diff options
Diffstat (limited to 'cli')
-rw-r--r-- | cli/js/40_testing.js | 2 | ||||
-rw-r--r-- | cli/tests/unit/files_test.ts | 36 | ||||
-rw-r--r-- | cli/tsc/dts/lib.deno.ns.d.ts | 42 |
3 files changed, 79 insertions, 1 deletions
diff --git a/cli/js/40_testing.js b/cli/js/40_testing.js index eb75a4d43..23a8da71b 100644 --- a/cli/js/40_testing.js +++ b/cli/js/40_testing.js @@ -101,7 +101,7 @@ const OP_DETAILS = { "op_flock_async": ["lock a file", "awaiting the result of a `Deno.flock` call"], "op_fs_events_poll": ["get the next file system event", "breaking out of a for await loop looping over `Deno.FsEvents`"], "op_fstat_async": ["get file metadata", "awaiting the result of a `Deno.File#fstat` call"], - "op_fsync_async": ["flush pending data operations for a file to disk", "awaiting the result of a `Deno.fsync` call"], + "op_fsync_async": ["flush pending data operations for a file to disk", "awaiting the result of a `file.fsync` call"], "op_ftruncate_async": ["truncate a file", "awaiting the result of a `Deno.ftruncate` call"], "op_funlock_async": ["unlock a file", "awaiting the result of a `Deno.funlock` call"], "op_futime_async": ["change file timestamps", "awaiting the result of a `Deno.futime` call"], diff --git a/cli/tests/unit/files_test.ts b/cli/tests/unit/files_test.ts index d02471b07..b38a798d7 100644 --- a/cli/tests/unit/files_test.ts +++ b/cli/tests/unit/files_test.ts @@ -860,3 +860,39 @@ Deno.test( await Deno.remove(filename); }, ); + +Deno.test( + { permissions: { read: true, write: true } }, + function fsFileSyncSyncSuccess() { + const filename = Deno.makeTempDirSync() + "/test_fsyncSync.txt"; + const file = Deno.openSync(filename, { + read: true, + write: true, + create: true, + }); + const size = 64; + file.truncateSync(size); + file.syncSync(); + assertEquals(file.statSync().size, size); + file.close(); + Deno.removeSync(filename); + }, +); + +Deno.test( + { permissions: { read: true, write: true } }, + async function fsFileSyncSuccess() { + const filename = (await Deno.makeTempDir()) + "/test_fsync.txt"; + const file = await Deno.open(filename, { + read: true, + write: true, + create: true, + }); + const size = 64; + await file.truncate(size); + await file.sync(); + assertEquals((await file.stat()).size, size); + file.close(); + await Deno.remove(filename); + }, +); diff --git a/cli/tsc/dts/lib.deno.ns.d.ts b/cli/tsc/dts/lib.deno.ns.d.ts index e32b90b41..2b82fa152 100644 --- a/cli/tsc/dts/lib.deno.ns.d.ts +++ b/cli/tsc/dts/lib.deno.ns.d.ts @@ -2168,6 +2168,9 @@ declare namespace Deno { * console.log(await Deno.readTextFile("my_file.txt")); // H * ``` * + * @deprecated Use `file.sync()` instead. {@linkcode Deno.fsync} will be + * removed in v2.0.0. + * * @category I/O */ export function fsync(rid: number): Promise<void>; @@ -2187,6 +2190,9 @@ declare namespace Deno { * console.log(Deno.readTextFileSync("my_file.txt")); // H * ``` * + * @deprecated Use `file.syncSync()` instead. {@linkcode Deno.fsyncSync} will + * be removed in v2.0.0. + * * @category I/O */ export function fsyncSync(rid: number): void; @@ -2531,6 +2537,42 @@ declare namespace Deno { */ statSync(): FileInfo; /** + * 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 file.write(new TextEncoder().encode("Hello World")); + * await file.truncate(1); + * await file.sync(); + * console.log(await Deno.readTextFile("my_file.txt")); // H + * ``` + * + * @category I/O + */ + sync(): Promise<void>; + /** + * 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 }, + * ); + * file.writeSync(new TextEncoder().encode("Hello World")); + * file.truncateSync(1); + * file.syncSync(); + * console.log(Deno.readTextFileSync("my_file.txt")); // H + * ``` + * + * @category I/O + */ + syncSync(): void; + /** * Flushes any pending data operations of the given file stream to disk. * ```ts * using file = await Deno.open( |