open
import { open } from "jsr:@ende/fs/unstable-open";function · experimental · requires --allow-read, --allow-write
async function open(path: string | URL, options?: OpenOptions): Promise<FsFile>Open a file and resolve to 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 Promise that resolves to a FsFile instance.
Example: Automatic closing a file with using TypeScript Only
import { open } from "@ende/fs/unstable-open";
using file = await open("/foo/bar.txt", { read: true, write: true });
// Do work with file.
Example: Manually closing a file
import { open } from "@ende/fs/unstable-open";
const file = await open("/foo/bar.txt", { read: true, write: true });
// Do work with file.
file.close();