summaryrefslogtreecommitdiff
path: root/cli
diff options
context:
space:
mode:
Diffstat (limited to 'cli')
-rw-r--r--cli/js/40_testing.js2
-rw-r--r--cli/tests/unit/files_test.ts36
-rw-r--r--cli/tests/unit/utime_test.ts4
-rw-r--r--cli/tsc/dts/lib.deno.ns.d.ts38
4 files changed, 77 insertions, 3 deletions
diff --git a/cli/js/40_testing.js b/cli/js/40_testing.js
index 91d7f105f..eb75a4d43 100644
--- a/cli/js/40_testing.js
+++ b/cli/js/40_testing.js
@@ -94,7 +94,7 @@ const OP_DETAILS = {
"op_net_send_udp": ["send a datagram message via UDP", "awaiting the result of `Deno.DatagramConn#send` call"],
"op_net_send_unixpacket": ["send a datagram message via Unixpacket", "awaiting the result of `Deno.DatagramConn#send` call"],
"op_dns_resolve": ["resolve a DNS name", "awaiting the result of a `Deno.resolveDns` call"],
- "op_fdatasync_async": ["flush pending data operations for a file to disk", "awaiting the result of a `Deno.fdatasync` call"],
+ "op_fdatasync_async": ["flush pending data operations for a file to disk", "awaiting the result of a `file.fdatasync` call"],
"op_fetch_send": ["send a HTTP request", "awaiting the result of a `fetch` call"],
"op_ffi_call_nonblocking": ["do a non blocking ffi call", "awaiting the returned promise"],
"op_ffi_call_ptr_nonblocking": ["do a non blocking ffi call", "awaiting the returned promise"],
diff --git a/cli/tests/unit/files_test.ts b/cli/tests/unit/files_test.ts
index 977d6463d..d02471b07 100644
--- a/cli/tests/unit/files_test.ts
+++ b/cli/tests/unit/files_test.ts
@@ -824,3 +824,39 @@ Deno.test(
// calling [Symbol.dispose] after manual close is a no-op
},
);
+
+Deno.test(
+ { permissions: { read: true, write: true } },
+ function fsFileDatasyncSyncSuccess() {
+ const filename = Deno.makeTempDirSync() + "/test_fdatasyncSync.txt";
+ const file = Deno.openSync(filename, {
+ read: true,
+ write: true,
+ create: true,
+ });
+ const data = new Uint8Array(64);
+ file.writeSync(data);
+ file.dataSyncSync();
+ assertEquals(Deno.readFileSync(filename), data);
+ file.close();
+ Deno.removeSync(filename);
+ },
+);
+
+Deno.test(
+ { permissions: { read: true, write: true } },
+ async function fsFileDatasyncSuccess() {
+ const filename = (await Deno.makeTempDir()) + "/test_fdatasync.txt";
+ const file = await Deno.open(filename, {
+ read: true,
+ write: true,
+ create: true,
+ });
+ const data = new Uint8Array(64);
+ await file.write(data);
+ await file.dataSync();
+ assertEquals(await Deno.readFile(filename), data);
+ file.close();
+ await Deno.remove(filename);
+ },
+);
diff --git a/cli/tests/unit/utime_test.ts b/cli/tests/unit/utime_test.ts
index 02566bad6..48f4f405a 100644
--- a/cli/tests/unit/utime_test.ts
+++ b/cli/tests/unit/utime_test.ts
@@ -19,7 +19,7 @@ Deno.test(
const atime = 1000;
const mtime = 50000;
await Deno.futime(file.rid, atime, mtime);
- await Deno.fdatasync(file.rid);
+ await file.dataSync();
const fileInfo = Deno.statSync(filename);
assertEquals(fileInfo.atime, new Date(atime * 1000));
@@ -40,7 +40,7 @@ Deno.test(
const atime = 1000;
const mtime = 50000;
Deno.futimeSync(file.rid, atime, mtime);
- Deno.fdatasyncSync(file.rid);
+ file.dataSyncSync();
const fileInfo = Deno.statSync(filename);
assertEquals(fileInfo.atime, new Date(atime * 1000));
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<void>;
@@ -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<void>;
+ /**
+ * 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.
*