Skip to main content
Version: Next

RsvimFs

The Rsvim.fs global object for file system and file IO.

Example

// Create a alias to 'Rsvim.fs'.
const fs = Rsvim.fs;

Methods

open()

open(path, options?): Promise<File>;

Open a file and resolve to an instance of RsvimFs.File. The file does not need to previously exist if using the create or createNew open options. The caller have to close the file to prevent resource leaking, see RsvimFs.File.close.

Parameters

ParameterTypeDescription

path

string

File path.

options?

OpenOptions

(Optional) Open options, by default is {read: true}. See RsvimFs.OpenOptions.

Returns

Promise<File>

It resolves to an instance of RsvimFs.File.

Throws

Throws TypeError if any parameters are invalid. Or throws Error if failed to open/create the file.

Example

const file = await Rsvim.fs.open("README.md");

openSync()

openSync(path, options?): File;

The sync version of open.

Parameters

ParameterTypeDescription

path

string

options?

OpenOptions

Returns

File

Throws

Example

const file = Rsvim.fs.openSync("README.md");

readFile()

readFile(path): Promise<Uint8Array<ArrayBufferLike>>;

Read a file in binary mode, i.e. into an array of bytes buffer, without open/close a file descriptor/handle.

Parameters

ParameterTypeDescription

path

string

File path to read.

Returns

Promise<Uint8Array<ArrayBufferLike>>

It resolves to Uint8Array that contains all the file contents as bytes array.

Throws

Throws TypeError if the file name is invalid. Or throws Error if failed to read the file.

Example

const buffer = await Rsvim.fs.readFile("README.md");

readFileSync()

readFileSync(path): Uint8Array;

The sync version of readFile.

Parameters

ParameterTypeDescription

path

string

Returns

Uint8Array

Throws

Example

const buffer = Rsvim.fs.readFileSync("README.md");

readTextFile()

readTextFile(path): Promise<string>;

Read a file in text mode, i.e. into a string, without open/close a file descriptor/handle.

Parameters

ParameterTypeDescription

path

string

File path to read.

Returns

Promise<string>

It resolves to text string that contains all the file contents.

Throws

Throws TypeError if the file name is invalid. Or throws Error if failed to read the file.

Example

const payload = await Rsvim.fs.readTextFile("README.md");

readTextFileSync()

readTextFileSync(path): string;

The sync version of readTextFile.

Parameters

ParameterTypeDescription

path

string

Returns

string

Throws

Example

const payload = Rsvim.fs.readTextFileSync("README.md");