V8 Javascript API

fs.async Class Reference

[File System]

Description

Asynchronous variant of the fs api. The functions take the same arguments as the synchronous versions and returns a Promise. These promises will reject or resolve with results.

Note:

Like all other asynchronous functionality any command using these functions must return a Promise.

Inner Classes

class 
A File_handle object is a wrapper for a File_descriptor for use in the asynchronous fs.async api. More...

Static Functions

Promise mkdir( String path)
Creates a directory inside content root. More...
Promise open( String filename, String flags)
Opens a file for reading or writing inside content root. More...
Promise readFile( String filename, Object options)
Reads the entire contents of a file from the filesystem inside content root. More...
Promise rmdir( String path)
Removes directory pointed to by path. More...
Promise stat( String path)
Returns file sytem information for a given path. More...
Promise unlink( String path)
Removes the file or symbolic link pointed to by path. More...
Promise writeFile( String filename, ArrayBuffer data, Object options)
Writes a file to the filesystem inside content root. More...

Functions

Promise fs.​async.mkdir( String path) [static]

Creates a directory inside content root. All required parents will be created automatically.

Parameters

path
the path to create to. Must be relative and will be resolved within content root.

Returns

A promise that resolves when the directory is created.

Promise fs.​async.open( String filename, String flags) [static]

Opens a file for reading or writing inside content root.

Parameters

filename
the filename to open. Must be a relative path and will be resolved within content root.
flags
mode to open in. One of:
  • 'r' : Open file for reading. An exception occurs if the file does not exist. (the default)
  • 'r+' : Open file for reading and writing. An exception occurs if the file does not exist.
  • 'w' : Open file for writing. The file is created (if it does not exist) or truncated (if it exists).
  • 'wx' : Like 'w' but fails if path exists.
  • 'w+' : Open file for reading and writing. The file is created (if it does not exist) or truncated (if it exists).
  • 'wx+': Like 'w+' but fails if path exists.
  • 'a' : Open file for appending. The file is created if it does not exist.
  • 'ax' : Like 'a' but fails if path exists.
  • 'a+' : Open file for reading and appending. The file is created if it does not exist.
  • 'ax+': Like 'a+' but fails if path exists.

Returns

A promise that resolves with a fs.async.File_handle when opened. Note this must be closed before the command returns otherwise the file descriptor is left dangling. Rejects if the file could not be opened.

Promise fs.​async.readFile( String filename, Object options) [static]

Reads the entire contents of a file from the filesystem inside content root.

Parameters

filename
the filename to read. Must be relative and will be resolved within content root.
options
Object containing options
  • flag String : Mode in which to open the file. See open. Default 'r'
  • encoding String : If set then the file is read using the given encoding and a String returned. The only supported value is 'utf8'.

Returns

The promise resolves with the file contents or rejects on error. Resolve argument will be a Uint8Array if no encoding is given, otherwise a String.

Promise fs.​async.rmdir( String path) [static]

Removes directory pointed to by path.

Parameters

path
the path to the directory to remove. Must be relative and will be resolved within content root. Directory must be empty otherwise removal will fail

Returns

A promise that resolves when the directory is removed.

Promise fs.​async.stat( String path) [static]

Returns file sytem information for a given path.

Parameters

path
the path to query. Must be relative and will be resolved within content root.

Returns

A promise that resolves with the fs.Stat details of the path or rejects on error.

Promise fs.​async.unlink( String path) [static]

Removes the file or symbolic link pointed to by path.

Parameters

path
the path to the file to remove. Must be relative and will be resolved within content root.

Returns

A promise that resolves when path is removed.

Promise fs.​async.writeFile( String filename, ArrayBuffer data, Object options) [static]

Writes a file to the filesystem inside content root.

Note:

Strings are always written using utf8 encoding.

Parameters

filename
the filename to write to. Must be relative and will be resolved within content root.
data
The data to write to disk. May be one of the following:
  • ArrayBuffer
  • Uint8Array
  • Binary
  • String
options
Object containing options
  • flag String : Mode in which to open the file. See fs.async.open. Default 'w'

Returns

A promise that resolves when the file is written or rejects on error.