Ende.Root
class ยท experimental
class Ende.Root implements Disposable, AsyncDisposableUNSTABLE: New API, yet to be vetted.
A directory that file names are resolved under without leaving it,
returned by Ende.openRoot and Ende.openRootSync.
Names are relative to the root. .. and symlinks are allowed while they
stay inside it. An absolute name, .. that climbs above the root, or a
symlink that points outside it (an absolute symlink target included)
throws Ende.errors.PathEscape. On Windows, reserved device
names such as NUL and COM1, and NTFS stream names such as a:b or
a::$DATA, throw it too.
The root holds the directory open, so renaming or moving the directory after opening it doesn't redirect later calls. On Windows the directory can't be renamed or removed while a root holds it.
Every call is still checked against Ende's permissions where it really
lands: a root never grants access the program doesn't already have, and
--deny-read/--deny-write rules under the root still apply. A name is
checked before it is looked up too, so a denied name fails the same way
whether or not it exists. Renaming a directory needs write access to
everything inside it, as Ende.Root.remove with recursive
does.
Calls that create, write, truncate, rename or remove don't follow a final symlink, even one that stays inside the root: they act on the link itself, or fail. To write through a link, open its target.
Not covered: a mount point or bind mount inside the root, and a hard link that already exists inside it to a file outside, are followed like any other directory or file.
Requires the --unstable-fs flag, or "unstable": ["fs"] in
ende.json.
Methods
open
open(path: string | URL, options?: OpenOptions): Promise<FsFile>Opens a file under the root. A final symlink is followed only when
the file is opened just for reading. See Ende.open.
openSync
openSync(path: string | URL, options?: OpenOptions): FsFileSynchronously opens a file under the root. See
Ende.openSync.
create
create(path: string | URL): Promise<FsFile>Creates a file under the root, or truncates an existing one. See
Ende.create.
createSync
createSync(path: string | URL): FsFileSynchronously creates a file under the root, or truncates an existing
one. See Ende.createSync.
openRoot
openRoot(path: string | URL): Promise<Root>Opens a directory under the root as a root of its own, opened for the same access. Names under it can't leave it, even into the rest of this root.
openRootSync
openRootSync(path: string | URL): RootSynchronously opens a directory under the root as a root of its own.
See Ende.Root.openRoot.
readFile
readFile(path: string | URL, options?: ReadFileOptions): Promise<Uint8Array<ArrayBuffer>>Reads a file under the root. See Ende.readFile.
readFileSync
readFileSync(path: string | URL): Uint8Array<ArrayBuffer>Synchronously reads a file under the root. See
Ende.readFileSync.
readTextFile
readTextFile(path: string | URL, options?: ReadFileOptions): Promise<string>Reads a file under the root as UTF-8 text. See
Ende.readTextFile.
readTextFileSync
readTextFileSync(path: string | URL): stringSynchronously reads a file under the root as UTF-8 text. See
Ende.readTextFileSync.
writeFile
writeFile(path: string | URL, data: Uint8Array | ReadableStream<Uint8Array>, options?: WriteFileOptions): Promise<void>Writes data to a file under the root. See Ende.writeFile.
Requires the root to be opened with write: true.
writeFileSync
writeFileSync(path: string | URL, data: Uint8Array, options?: WriteFileOptions): voidSynchronously writes data to a file under the root. See
Ende.writeFileSync.
Requires the root to be opened with write: true.
writeTextFile
writeTextFile(path: string | URL, data: string | ReadableStream<string>, options?: WriteFileOptions): Promise<void>Writes data to a file under the root as UTF-8 text. See
Ende.writeTextFile.
Requires the root to be opened with write: true.
writeTextFileSync
writeTextFileSync(path: string | URL, data: string, options?: WriteFileOptions): voidSynchronously writes data to a file under the root as UTF-8 text.
See Ende.writeTextFileSync.
Requires the root to be opened with write: true.
mkdir
mkdir(path: string | URL, options?: MkdirOptions): Promise<void>Creates a directory under the root. See Ende.mkdir.
Requires the root to be opened with write: true.
mkdirSync
mkdirSync(path: string | URL, options?: MkdirOptions): voidSynchronously creates a directory under the root. See
Ende.mkdirSync.
Requires the root to be opened with write: true.
remove
remove(path: string | URL, options?: RemoveOptions): Promise<void>Removes a file, symlink or directory under the root. A symlink is
removed, not its target. See Ende.remove.
Requires the root to be opened with write: true.
removeSync
removeSync(path: string | URL, options?: RemoveOptions): voidSynchronously removes a file, symlink or directory under the root.
See Ende.removeSync.
Requires the root to be opened with write: true.
stat
stat(path: string | URL): Promise<FileInfo>Gets information about a file under the root, following a final
symlink that stays inside. See Ende.stat.
A file the operating system won't open for reading (no read access, a
socket) is still stat'ed, unless it is reached through a symlink: then
the call fails. Ende.Root.readDir and
Ende.Root.openRoot need to open their directory.
statSync
statSync(path: string | URL): FileInfoSynchronously gets information about a file under the root. See
Ende.statSync.
lstat
lstat(path: string | URL): Promise<FileInfo>Gets information about a file under the root without following a
final symlink. See Ende.lstat.
lstatSync
lstatSync(path: string | URL): FileInfoSynchronously gets information about a file under the root without
following a final symlink. See Ende.lstatSync.
readDir
readDir(path: string | URL): AsyncIterable<DirEntry>Lists a directory under the root. See Ende.readDir.
readDirSync
readDirSync(path: string | URL): IteratorObject<DirEntry>Synchronously lists a directory under the root. See
Ende.readDirSync.
rename
rename(oldpath: string | URL, newpath: string | URL): Promise<void>Renames a file or directory; both names are under the root. See
Ende.rename.
Requires the root to be opened with write: true.
renameSync
renameSync(oldpath: string | URL, newpath: string | URL): voidSynchronously renames a file or directory; both names are under the
root. See Ende.renameSync.
Requires the root to be opened with write: true.
close
close(): voidCloses the root. Later calls throw Ende.errors.BadResource.
[Symbol.dispose]
[Symbol.dispose](): void[Symbol.asyncDispose]
[Symbol.asyncDispose](): Promise<void>