-
Notifications
You must be signed in to change notification settings - Fork 5.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(unstable): add Deno.fsyncSync and fsync (#6411)
- Loading branch information
1 parent
f24aab8
commit 40866d7
Showing
6 changed files
with
119 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 }); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
// Copyright 2018-2020 the Deno authors. All rights reserved. MIT license. | ||
import { unitTest, assertEquals } from "./test_util.ts"; | ||
|
||
unitTest( | ||
{ perms: { read: true, write: true } }, | ||
function fsyncSyncSuccess(): void { | ||
const filename = Deno.makeTempDirSync() + "/test_fsyncSync.txt"; | ||
const file = Deno.openSync(filename, { | ||
read: true, | ||
write: true, | ||
create: true, | ||
}); | ||
const size = 64; | ||
Deno.ftruncateSync(file.rid, size); | ||
Deno.fsyncSync(file.rid); | ||
assertEquals(Deno.statSync(filename).size, size); | ||
Deno.close(file.rid); | ||
Deno.removeSync(filename); | ||
} | ||
); | ||
|
||
unitTest( | ||
{ perms: { read: true, write: true } }, | ||
async function fsyncSuccess(): Promise<void> { | ||
const filename = (await Deno.makeTempDir()) + "/test_fsync.txt"; | ||
const file = await Deno.open(filename, { | ||
read: true, | ||
write: true, | ||
create: true, | ||
}); | ||
const size = 64; | ||
await Deno.ftruncate(file.rid, size); | ||
await Deno.fsync(file.rid); | ||
assertEquals((await Deno.stat(filename)).size, size); | ||
Deno.close(file.rid); | ||
await Deno.remove(filename); | ||
} | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters