2024-01-01 14:58:21 -05:00
|
|
|
// Copyright 2018-2024 the Deno authors. All rights reserved. MIT license.
|
2021-11-23 11:45:18 -05:00
|
|
|
import { assertEquals } from "./test_util.ts";
|
2020-06-21 09:29:44 -04:00
|
|
|
|
2021-11-23 11:45:18 -05:00
|
|
|
Deno.test(
|
2021-09-22 19:50:50 -04:00
|
|
|
{ permissions: { read: true, write: true } },
|
2021-08-05 07:08:58 -04:00
|
|
|
function fdatasyncSyncSuccess() {
|
2020-06-26 08:36:35 -04:00
|
|
|
const filename = Deno.makeTempDirSync() + "/test_fdatasyncSync.txt";
|
2024-01-24 09:59:55 -05:00
|
|
|
using file = Deno.openSync(filename, {
|
2020-06-26 08:36:35 -04:00
|
|
|
read: true,
|
|
|
|
write: true,
|
|
|
|
create: true,
|
|
|
|
});
|
|
|
|
const data = new Uint8Array(64);
|
2024-03-20 13:39:25 -04:00
|
|
|
file.writeSync(data);
|
2020-06-26 08:36:35 -04:00
|
|
|
Deno.fdatasyncSync(file.rid);
|
|
|
|
Deno.removeSync(filename);
|
2020-07-14 15:24:17 -04:00
|
|
|
},
|
2020-06-26 08:36:35 -04:00
|
|
|
);
|
|
|
|
|
2021-11-23 11:45:18 -05:00
|
|
|
Deno.test(
|
2021-09-22 19:50:50 -04:00
|
|
|
{ permissions: { read: true, write: true } },
|
2021-08-05 07:08:58 -04:00
|
|
|
async function fdatasyncSuccess() {
|
2020-06-26 08:36:35 -04:00
|
|
|
const filename = (await Deno.makeTempDir()) + "/test_fdatasync.txt";
|
2024-01-24 09:59:55 -05:00
|
|
|
using file = await Deno.open(filename, {
|
2020-06-26 08:36:35 -04:00
|
|
|
read: true,
|
|
|
|
write: true,
|
|
|
|
create: true,
|
|
|
|
});
|
|
|
|
const data = new Uint8Array(64);
|
2024-01-24 10:36:13 -05:00
|
|
|
await file.write(data);
|
2020-06-26 08:36:35 -04:00
|
|
|
await Deno.fdatasync(file.rid);
|
|
|
|
assertEquals(await Deno.readFile(filename), data);
|
|
|
|
await Deno.remove(filename);
|
2020-07-14 15:24:17 -04:00
|
|
|
},
|
2020-06-26 08:36:35 -04:00
|
|
|
);
|
|
|
|
|
2021-11-23 11:45:18 -05:00
|
|
|
Deno.test(
|
2021-09-22 19:50:50 -04:00
|
|
|
{ permissions: { read: true, write: true } },
|
2021-08-05 07:08:58 -04:00
|
|
|
function fsyncSyncSuccess() {
|
2020-06-21 09:29:44 -04:00
|
|
|
const filename = Deno.makeTempDirSync() + "/test_fsyncSync.txt";
|
2024-01-24 09:59:55 -05:00
|
|
|
using file = Deno.openSync(filename, {
|
2020-06-21 09:29:44 -04:00
|
|
|
read: true,
|
|
|
|
write: true,
|
|
|
|
create: true,
|
|
|
|
});
|
|
|
|
const size = 64;
|
2024-01-24 09:12:22 -05:00
|
|
|
file.truncateSync(size);
|
2020-06-21 09:29:44 -04:00
|
|
|
Deno.fsyncSync(file.rid);
|
|
|
|
assertEquals(Deno.statSync(filename).size, size);
|
|
|
|
Deno.removeSync(filename);
|
2020-07-14 15:24:17 -04:00
|
|
|
},
|
2020-06-21 09:29:44 -04:00
|
|
|
);
|
|
|
|
|
2021-11-23 11:45:18 -05:00
|
|
|
Deno.test(
|
2021-09-22 19:50:50 -04:00
|
|
|
{ permissions: { read: true, write: true } },
|
2021-08-05 07:08:58 -04:00
|
|
|
async function fsyncSuccess() {
|
2020-06-21 09:29:44 -04:00
|
|
|
const filename = (await Deno.makeTempDir()) + "/test_fsync.txt";
|
2024-01-24 09:59:55 -05:00
|
|
|
using file = await Deno.open(filename, {
|
2020-06-21 09:29:44 -04:00
|
|
|
read: true,
|
|
|
|
write: true,
|
|
|
|
create: true,
|
|
|
|
});
|
|
|
|
const size = 64;
|
2024-01-24 09:12:22 -05:00
|
|
|
await file.truncate(size);
|
2020-06-21 09:29:44 -04:00
|
|
|
await Deno.fsync(file.rid);
|
|
|
|
assertEquals((await Deno.stat(filename)).size, size);
|
|
|
|
await Deno.remove(filename);
|
2020-07-14 15:24:17 -04:00
|
|
|
},
|
2020-06-21 09:29:44 -04:00
|
|
|
);
|