FilesystemAPI

interface FilesystemAPI

Node API: fs

Describes the API made available via Node's built-in fs module, which implements filesystem operations in both synchronous and asynchronous (callback) forms.

Facilities are provided for reading and writing files, as well as iterating over directories, handling links, and managing file descriptors.

In Elide, filesystem operations are implemented on top of VFS, and use GraalVM's embedded I/O isolation. The "view" of a filesystem available to a guest application is the composed form of the VFS and the host filesystem, modulo application permissions.

VFS sources can be things like the host filesystem, tarballs, in-memory or embedded data, or even remote filesystems. Other than Elide's implementation mechanics, the API behaves as identically as possible to Node's built-in module.

Each method is generally specified with two implementations: one for host-side use (with host types), and one for entirely guest-side use, which accepts either Value or Any objects.

 

I/O Isolation

Filesystem operations are subject to I/O isolation policy in Elide; this means that files may be visible on the host system, or may not be.

Additionally, filesystem operations may be restricted to read-only status, in which case the methods provided by the WritableFilesystemAPI will either not be available or will throw as if denied by the operating system.

 

Interaction with NIO

Most I/O operations under the hood are implemented with JDK NIO, including path translation, file reading and writing and directory traversal, and streams.

NIO documentation can be consulted for more information on the underlying behavior of these operations: Java NIO Docs.

 

Filesystem Paths

This module makes extensive use of the PathAPI to resolve filesystem paths; operating system-specific path behavior is defined in that module and documented there as well.

 

See Node's fs documentation for more information.

See also

for a promise-based alternative to this API, made available at fs/promises.

for writable extensions to this base API

Inheritors

Functions

Link copied to clipboard
abstract fun access(path: Value, callback: Value)

Tests a user's permissions for the file at the specified path; provides the results or an error to the callback. This variant specifies the default mode of F_OK.

abstract fun access(path: Path, mode: AccessMode = AccessMode.READ, callback: AccessCallback)

Tests a user's permissions for the file at the specified path; provides the results or an error to the callback. This is a host-side variant.

abstract fun access(path: Value, mode: Value, callback: Value)

Tests a user's permissions for the file at the specified path; provides the results or an error to the callback. This variant accepts a mode.

Link copied to clipboard
abstract fun accessSync(path: Value)

Tests a user's permissions for the file at the specified path; provides the results or an error to the callback. This variant specifies the default mode of F_OK and operates synchronously, raising an exception for failures.

abstract fun accessSync(path: Path, mode: AccessMode = AccessMode.READ)

Tests a user's permissions for the file at the specified path; provides the results or an error to the callback. This is a host-side variant that operates synchronously.

abstract fun accessSync(path: Value, mode: Value)

Tests a user's permissions for the file at the specified path; provides the results or an error to the callback. This variant accepts a mode and operates synchronously, raising an exception for failures.

Link copied to clipboard
abstract fun exists(path: Path, callback: (Boolean) -> Unit)
abstract fun exists(path: Value, callback: Value)

Tests whether the file at the specified path exists; provides the results or an error to the callback.

Link copied to clipboard
abstract fun existsSync(path: Path): Boolean
abstract fun existsSync(path: Value): Boolean

Tests whether the file at the specified path exists; provides the results or an error to the callback.

Link copied to clipboard
abstract fun readFile(path: Path, options: ReadFileOptions = ReadFileOptions.DEFAULTS, callback: ReadFileCallback)
abstract fun readFile(path: Value, options: Value?, callback: ReadFileCallback? = null)

Reads the contents of a file at the specified path; provides the results or an error to the callback. This variant accepts a polyglot Value.

Link copied to clipboard
abstract fun readFileSync(path: Path, options: ReadFileOptions = ReadFileOptions.DEFAULTS): StringOrBuffer
abstract fun readFileSync(path: Value, options: Value? = null): StringOrBuffer

Reads the contents of a file at the specified path and returns the results synchronously. This variant accepts a plain Value.