Ende.openRoot

function · experimental · requires --allow-read, --allow-write

function Ende.openRoot(path: string | URL, options?: OpenRootOptions): Promise<Root>

UNSTABLE: New API, yet to be vetted.

Opens a directory as an Ende.Root: names passed to the root's methods are resolved inside that directory and can't leave it, so code can take file names from untrusted input and still only touch files under the root.

await using out = await Ende.openRoot("./output", { write: true });
await out.writeTextFile("report/today.txt", "done"); // OK
await out.readTextFile("a/../b.txt"); // OK, stays inside
await out.readTextFile("../secret.txt"); // throws Ende.errors.PathEscape
await out.readTextFile("/etc/passwd"); // throws Ende.errors.PathEscape

Throws Ende.errors.NotFound if path doesn't exist, or Ende.errors.NotCapable if the permission for options has not been granted for path. A path inside the files embedded in a compiled executable throws Ende.errors.NotSupported.

Requires the --unstable-fs flag, or "unstable": ["fs"] in ende.json.