Skip to content

@caido/quickjs-types / llrt/fs

llrt/fs ​

Namespaces ​

NamespaceDescription
constants-

Classes ​

Dirent ​

A representation of a directory entry, which can be a file or a subdirectory within the directory. A directory entry is a combination of the file name and file type pairs.

Additionally, when promises.readdir or readdirSync is called with the withFileTypes option set to true, the resulting array is filled with fs.Dirent objects, rather than strings.

Constructors ​

Constructor ​

new Dirent(): Dirent

Returns ​

Dirent

Properties ​

name ​

name: string

The file name that this fs.Dirent object refers to.

parentPath ​

parentPath: string

The base path that this fs.Dirent object refers to.

Methods ​

isBlockDevice() ​

isBlockDevice(): boolean

Returns true if the fs.Dirent object describes a block device.

Returns ​

boolean

isCharacterDevice() ​

isCharacterDevice(): boolean

Returns true if the fs.Dirent object describes a character device.

Returns ​

boolean

isDirectory() ​

isDirectory(): boolean

Returns true if the fs.Dirent object describes a file system directory.

Returns ​

boolean

isFIFO() ​

isFIFO(): boolean

Returns true if the fs.Dirent object describes a first-in-first-out (FIFO) pipe.

Returns ​

boolean

isFile() ​

isFile(): boolean

Returns true if the fs.Dirent object describes a regular file.

Returns ​

boolean

isSocket() ​

isSocket(): boolean

Returns true if the fs.Dirent object describes a socket.

Returns ​

boolean

isSymbolicLink(): boolean

Returns true if the fs.Dirent object describes a symbolic link.

Returns ​

boolean


Stats ​

A fs.Stats object provides information about a file.

Stat objects are not to be created directly using the new keyword.

console
Stats {
  dev: 2114,
  ino: 48064969,
  mode: 33188,
  nlink: 1,
  uid: 85,
  gid: 100,
  rdev: 0,
  size: 527,
  blksize: 4096,
  blocks: 8,
  atimeMs: 1318289051000.1,
  mtimeMs: 1318289051000.1,
  ctimeMs: 1318289051000.1,
  birthtimeMs: 1318289051000.1,
  atime: Mon, 10 Oct 2011 23:24:11 GMT,
  mtime: Mon, 10 Oct 2011 23:24:11 GMT,
  ctime: Mon, 10 Oct 2011 23:24:11 GMT,
  birthtime: Mon, 10 Oct 2011 23:24:11 GMT }

Extends ​

Constructors ​

Constructor ​

new Stats(): Stats

Returns ​

Stats

Inherited from ​

StatsBase<number>.constructor

Properties ​

atime ​

atime: Date

Inherited from ​

StatsBase.atime

atimeMs ​

atimeMs: number

Inherited from ​

StatsBase.atimeMs

birthtime ​

birthtime: Date

Inherited from ​

StatsBase.birthtime

birthtimeMs ​

birthtimeMs: number

Inherited from ​

StatsBase.birthtimeMs

blksize ​

blksize: number

Inherited from ​

StatsBase.blksize

blocks ​

blocks: number

Inherited from ​

StatsBase.blocks

ctime ​

ctime: Date

Inherited from ​

StatsBase.ctime

ctimeMs ​

ctimeMs: number

Inherited from ​

StatsBase.ctimeMs

dev ​

dev: number

Inherited from ​

StatsBase.dev

gid ​

gid: number

Inherited from ​

StatsBase.gid

ino ​

ino: number

Inherited from ​

StatsBase.ino

mode ​

mode: number

Inherited from ​

StatsBase.mode

mtime ​

mtime: Date

Inherited from ​

StatsBase.mtime

mtimeMs ​

mtimeMs: number

Inherited from ​

StatsBase.mtimeMs

nlink: number

Inherited from ​

StatsBase.nlink

rdev ​

rdev: number

Inherited from ​

StatsBase.rdev

size ​

size: number

Inherited from ​

StatsBase.size

uid ​

uid: number

Inherited from ​

StatsBase.uid

Methods ​

isBlockDevice() ​

isBlockDevice(): boolean

Returns ​

boolean

Inherited from ​

StatsBase.isBlockDevice

isCharacterDevice() ​

isCharacterDevice(): boolean

Returns ​

boolean

Inherited from ​

StatsBase.isCharacterDevice

isDirectory() ​

isDirectory(): boolean

Returns ​

boolean

Inherited from ​

StatsBase.isDirectory

isFIFO() ​

isFIFO(): boolean

Returns ​

boolean

Inherited from ​

StatsBase.isFIFO

isFile() ​

isFile(): boolean

Returns ​

boolean

Inherited from ​

StatsBase.isFile

isSocket() ​

isSocket(): boolean

Returns ​

boolean

Inherited from ​

StatsBase.isSocket

isSymbolicLink(): boolean

Returns ​

boolean

Inherited from ​

StatsBase.isSymbolicLink

Interfaces ​

MakeDirectoryOptions ​

Properties ​

mode? ​

optional mode: number

A file mode. If not specified

Default ​
ts
0o777
recursive? ​

optional recursive: boolean

Indicates whether parent folders should be created. If a folder was created, the path to the first created folder will be returned.

Default ​
ts
false

RmDirOptions ​

Properties ​

recursive? ​

optional recursive: boolean

Deprecated ​

Use fs.rm(path, { recursive: true, force: true }) instead.

If true, perform a recursive directory removal. In recursive mode, operations are retried on failure.

Default ​
ts
false

RmOptions ​

Properties ​

force? ​

optional force: boolean

When true, exceptions will be ignored if path does not exist.

Default ​
ts
false
recursive? ​

optional recursive: boolean

If true, perform a recursive directory removal. In recursive mode, operations are retried on failure.

Default ​
ts
false

StatsBase ​

Extended by ​

Type Parameters ​

Type Parameter
T

Properties ​

atime ​

atime: Date

atimeMs ​

atimeMs: T

birthtime ​

birthtime: Date

birthtimeMs ​

birthtimeMs: T

blksize ​

blksize: T

blocks ​

blocks: T

ctime ​

ctime: Date

ctimeMs ​

ctimeMs: T

dev ​

dev: T

gid ​

gid: T

ino ​

ino: T

mode ​

mode: T

mtime ​

mtime: Date

mtimeMs ​

mtimeMs: T

nlink: T

rdev ​

rdev: T

size ​

size: T

uid ​

uid: T

Methods ​

isBlockDevice() ​

isBlockDevice(): boolean

Returns ​

boolean

isCharacterDevice() ​

isCharacterDevice(): boolean

Returns ​

boolean

isDirectory() ​

isDirectory(): boolean

Returns ​

boolean

isFIFO() ​

isFIFO(): boolean

Returns ​

boolean

isFile() ​

isFile(): boolean

Returns ​

boolean

isSocket() ​

isSocket(): boolean

Returns ​

boolean

isSymbolicLink(): boolean

Returns ​

boolean


StatSyncFn() ​

Extends ​

  • Function

StatSyncFn(path: string): Stats

Parameters ​

ParameterType
pathstring

Returns ​

Stats

Type Aliases ​

Mode ​

Mode = number


PathLike ​

PathLike = string

Valid types for path values in "fs".

Variables ​

statSync ​

const statSync: StatSyncFn

Synchronous stat - Get file status.

Param ​

A path to a file.

Functions ​

accessSync() ​

accessSync(path: string, mode?: number): void

Synchronously tests a user's permissions for the file or directory specified by path. The mode argument is an optional integer that specifies the accessibility checks to be performed. mode should be either the value fs.constants.F_OK or a mask consisting of the bitwise OR of any of fs.constants.R_OK, fs.constants.W_OK, and fs.constants.X_OK (e.g.fs.constants.W_OK | fs.constants.R_OK). Check File access constants for possible values of mode.

If any of the accessibility checks fail, an Error will be thrown. Otherwise, the method will return undefined.

js
import { accessSync, constants } from 'fs';

try {
  accessSync('etc/passwd', constants.R_OK | constants.W_OK);
  console.log('can read/write');
} catch (err) {
  console.error('no access!');
}

Parameters ​

ParameterTypeDescription
pathstring-
mode?number

Returns ​

void


chmodSync() ​

chmodSync(path: string, mode: number): void

For detailed information, see the documentation of the asynchronous version of this API: chmod.

See the POSIX chmod(2) documentation for more detail.

Parameters ​

ParameterType
pathstring
modenumber

Returns ​

void


mkdirSync() ​

mkdirSync(path: string, options?: MakeDirectoryOptions): string

Synchronously creates a directory. Returns the path.

See the POSIX mkdir(2) documentation for more details.

Parameters ​

ParameterType
pathstring
options?MakeDirectoryOptions

Returns ​

string


mkdtempSync() ​

mkdtempSync(prefix: string): string

Returns the created directory path.

For detailed information, see the documentation of the asynchronous version of this API: promises.mkdtemp.

Parameters ​

ParameterType
prefixstring

Returns ​

string


readdirSync() ​

Call Signature ​

readdirSync(path: string, options?: object): string[]

Reads the contents of the directory.

See the POSIX readdir(3) documentation for more details.

If options.withFileTypes is set to true, the result will contain fs.Dirent objects.

Parameters ​
ParameterType
pathstring
options?{ recursive?: boolean; withFileTypes?: false; }
options.recursive?boolean
options.withFileTypes?false
Returns ​

string[]

Call Signature ​

readdirSync(path: string, options: object): Dirent[]

Synchronous readdir (2) - read a directory.

Parameters ​
ParameterTypeDescription
pathstringA path to a file. If a URL is provided, it must use the file: protocol.
options{ recursive?: boolean; withFileTypes: true; }If called with withFileTypes: true the result data will be an array of Dirent.
options.recursive?boolean-
options.withFileTypestrue-
Returns ​

Dirent[]


readFileSync() ​

Call Signature ​

readFileSync(path: string, options?: { encoding?: null; } | null): Buffer

Returns the contents of the path.

For detailed information, see the documentation of the asynchronous version of this API: promises.readFile.

If the encoding option is specified then this function returns a string. Otherwise it returns a buffer.

Parameters ​
ParameterTypeDescription
pathstringA path to a file.
options?{ encoding?: null; } | null-
Returns ​

Buffer

Call Signature ​

readFileSync(path: string, options: BufferEncoding | { encoding: BufferEncoding; }): string

Synchronously reads the entire contents of a file.

Parameters ​
ParameterTypeDescription
pathstringA path to a file.
optionsBufferEncoding | { encoding: BufferEncoding; }Either the encoding for the result, or an object that contains the encoding.
Returns ​

string


renameSync() ​

renameSync(oldPath: string, newPath: string): void

Synchronously renames a file or directory from oldPath to newPath.

For detailed information, see the documentation of the asynchronous version of this API: promises.rename.

Parameters ​

ParameterType
oldPathstring
newPathstring

Returns ​

void


rmdirSync() ​

rmdirSync(path: string, options?: RmDirOptions): void

Synchronous rmdir(2). Returns undefined.

Using fs.rmdirSync() on a file (not a directory) results in an ENOENT error on Windows and an ENOTDIR error on POSIX.

To get a behavior similar to the rm -rf Unix command, use rmSync with options { recursive: true, force: true }.

Parameters ​

ParameterType
pathstring
options?RmDirOptions

Returns ​

void


rmSync() ​

rmSync(path: string, options?: RmOptions): void

Synchronously removes files and directories (modeled on the standard POSIX rm utility). Returns undefined.

Parameters ​

ParameterType
pathstring
options?RmOptions

Returns ​

void


symlinkSync() ​

symlinkSync(target: string, path: string, type?: "dir" | "file" | "junction" | null): void

Synchronous symlink(2) - Create a new symbolic link to an existing file.

Parameters ​

ParameterTypeDescription
targetstringA path to an existing file. If a URL is provided, it must use the file: protocol.
pathstringA path to the new symlink. If a URL is provided, it must use the file: protocol.
type?"dir" | "file" | "junction" | null

Returns ​

void


writeFileSync() ​

writeFileSync(file: string, data: string | ArrayBufferView | Buffer | ArrayBuffer | SharedArrayBuffer, options?: object): void

Returns undefined.

For detailed information, see the documentation of the asynchronous version of this API: promises.writeFile.

Parameters ​

ParameterTypeDescription
filestringA path to a file.
datastring | ArrayBufferView | Buffer | ArrayBuffer | SharedArrayBuffer-
options?{ mode?: number; }-
options.mode?number-

Returns ​

void

References ​

promises ​

Renames and re-exports llrt/fs/promises