File

File-System. File

A File object is an object wrapper for a numeric file descriptor.

Constructor

new File(path, modeopt) → {File}

Creates a new File instance given a file path.

Source:
Parameters:
Name Type Attributes Description
path String

The file path for the File instance.

mode String <optional>

The mode in which the file is to be opened.

Returns:
Type:
File

An instance of the File class.

Methods

(async) close()

Closes the file asynchronously.

Source:

closeSync()

Closes the file synchronously.

Source:

(async) open(mode)

Asynchronously opens the file.

Source:
Parameters:
Name Type Default Description
mode string r

The mode in which the file is to be opened.

openSync(mode)

Synchronously opens the file.

Source:
Parameters:
Name Type Default Description
mode string r

The mode in which the file is to be opened.

(async) read(size, offset) → {Promise.<Uint8Array>}

Reads asynchronously some bytes from the file.

Source:
Parameters:
Name Type Default Description
size Number

The maximum amount of bytes to read.

offset Number 0

The starting position in the file from which to begin reading data.

Returns:
Type:
Promise.<Uint8Array>
  • A Uint8Array containing the bytes read from the file.

readSync(size, offset) → {Uint8Array}

Reads synchronously some bytes from the file.

Source:
Parameters:
Name Type Default Description
size Number

The maximum amount of bytes to read.

offset Number 0

The starting position in the file from which to begin reading data.

Returns:
Type:
Uint8Array
  • A Uint8Array containing the bytes read from the file.

(async) stat() → {Promise.<FileStats>}

Retrieves asynchronously statistics for the file.

Source:
Returns:
Type:
Promise.<FileStats>

Useful information about the file.

statSync() → {FileStats}

Retrieves synchronously statistics for the file.

Source:
Returns:
Type:
FileStats

Useful information about the file.

(async) write(data)

Writes asynchronously a binary buffer to the file.

Source:
Parameters:
Name Type Description
data Uint8Array

The binary data to be written to the file.

writeSync(data)

Writes synchronously a binary buffer to the file.

Source:
Parameters:
Name Type Description
data Uint8Array

The binary data to be written to the file.