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;

Classes

ClassDescription

File

The File object that access to an open file on filesystem.

See

RsvimFs.open

Type Aliases

Type AliasDescription

FileInfo

File information, it contains 3 groups of properties:

  • Common properties that are available for all platforms.
  • Windows platforms only properties
  • Unix platforms only properties

MkdirOptions

Mkdir options.

OpenOptions

Open options.

tip

It is same with std::fs::OpenOptions in rust std library.

See

RsvimFs.open

SymlinkOptions

See

RsvimFs.symlink

Functions

FunctionDescription

link

Create hard link from a file path.

Throws

Throws TypeError if any parameter is invalid. Or throws Error if failed to create hard link from the file.

Example

try {
await Rsvim.fs.link("README.md", "linked-README.md");
Rsvim.cmd.echo(`Created hard link "linked-README.md" pointing to "README.md"`);
} catch (e) {
Rsvim.cmd.echo(`Failed to create hard link pointing to "README.md": ${e}`);
}

linkSync

Sync version of link.

Example

try {
Rsvim.fs.linkSync("README.md", "linked-README.md");
Rsvim.cmd.echo(`Created hard link "linked-README.md" pointing to "README.md"`);
} catch (e) {
Rsvim.cmd.echo(`Failed to create hard link pointing to "README.md": ${e}`);
}

lstat

Get the status of a file by path.

note

This api doesn't follow symbolic link.

See

RsvimFs.stat

Throws

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

Example

const fstat = await Rsvim.fs.lstat("README.md");

lstatSync

Sync version of lstat.

Example

const fstat = Rsvim.fs.lstatSync("README.md");

mkdir

Make a directory.

Throws

Throws TypeError if any parameter is invalid. Or throws Error if failed to create hard mkdir from the file.

Example

try {
await Rsvim.fs.mkdir(".rsvim");
Rsvim.cmd.echo(`Created directory ".rsvim"`);
} catch (e) {
Rsvim.cmd.echo(`Failed to create directory ".rsvim": ${e}`);
}

mkdirSync

Sync version of mkdir.

Example

try {
Rsvim.fs.mkdirSync(".rsvim");
Rsvim.cmd.echo(`Created directory ".rsvim"`);
} catch (e) {
Rsvim.cmd.echo(`Failed to create directory ".rsvim": ${e}`);
}

open

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.

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

Sync version of open.

Example

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

readFile

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

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

Sync version of readFile.

Example

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

readTextFile

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

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

Sync version of readTextFile.

Example

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

stat

Get the status of a file by path.

note

This api follows symbolic link.

See

RsvimFs.lstat

Throws

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

Example

const fstat = await Rsvim.fs.stat("README.md");

statSync

Sync version of stat.

Example

const fstat = Rsvim.fs.statSync("README.md");

symlink

Create symbolic link from a file path.

On Windows platforms, you should specify the 3rd parameter "options" with below 3 options:

  • "file" or "dir": Pointing to CreateSymbolicLinkW function.
  • "junction": NTFS v5+ features roughly equivalent to Unix directory symbolic links.

Throws

Throws TypeError if any parameter is invalid. Or throws Error if failed to create symbolic link from the file.

Example

try {
// Linux
await Rsvim.fs.symlink("README.md", "linked-README.md");
// Windows
await Rsvim.fs.symlink("README.md", "linked-README.md", "junction");
Rsvim.cmd.echo(`Created symbolic link "linked-README.md" pointing to "README.md"`);
} catch (e) {
Rsvim.cmd.echo(`Failed to create symbolic link pointing to "README.md": ${e}`);
}

symlinkSync

Sync version of symlink.

Example

try {
// Linux
Rsvim.fs.symlinkSync("README.md", "linked-README.md");
// Windows
Rsvim.fs.symlinkSync("README.md", "linked-README.md", "junction");
Rsvim.cmd.echo(`Created symbolic link "linked-README.md" pointing to "README.md"`);
} catch (e) {
Rsvim.cmd.echo(`Failed to create symbolic link pointing to "README.md": ${e}`);
}