openSync
import { openSync } from "jsr:@ende/fs/unstable-open";function · experimental · requires --allow-read, --allow-write
function openSync(path: string | URL, options?: OpenOptions): FsFileSynchronously open a file and return an instance of FsFile.
The file does not need to previously exist if using the create or
createNew open options. The caller may have the resulting file
automatically closed by the runtime once it's out of scope by declaring the
file variable with the using keyword.
Requires allow-read and/or allow-write permissions depending on
options.
path: string | URLThe path to the opened file.
options?: OpenOptionsOptions to open a file. See
OpenOptions.
Returns
A FsFile instance.
Example: Automatic closing a file with using TypeScript Only
import { openSync } from "@ende/fs/unstable-open";
using file = openSync("/foo/bar.txt", { read: true, write: true });
// Do work with file.
Example: Manually closing an opened file
import { openSync } from "@ende/fs/unstable-open";
const file = openSync("/foo/bar.txt", { read: true, write: true });
// Do work with file.
file.close();