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(buffer, offset) → {Promise.<Number>}

Reads asynchronously some bytes from the file.

Source:
Parameters:
Name Type Default Description
buffer Uint8Array

The buffer into which the data will be read.

offset Number 0

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

Returns:
Type:
Promise.<Number>
  • The amount of bytes read.

readSync(buffer, offset) → {Number}

Reads synchronously some bytes from the file.

Source:
Parameters:
Name Type Default Description
buffer Uint8Array

The buffer into which the data will be read.

offset Number 0

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

Returns:
Type:
Number
  • The amount of bytes read.

(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.