Module: iowa

Methods

(inner) createIfNotExists(path, seed, json) → {Promise}

Creates a file if the file does not exist, populating the file with an optional seed value.
Parameters:
Name Type Description
path string The path to the file.
seed object what to put into the file initially.
json boolean true if the data we are persisting to the file is meant to be saved as JSON, false otherwise.
Source:
Returns:
a Promise that resolves with { existedBefore, created, error, reason }; where…
  • existedBefore is true if the file was there before.
  • created is true if file was created successfully.
  • error and reason are populated if something bad happens.
Type
Promise

(inner) directories(rootDir) → {Promise}

Returns a Promise that resolves witha directory list in the form of [ { directory, path } ] given a rootDir.
Parameters:
Name Type Description
rootDir string The path to the root directory.
Source:
Returns:
A Promise taht resolves with an [] of { stat, path } objects where…
  • stat is a Node.JS file stat object.
  • path is the path to the file.
Type
Promise

(inner) exists(filePath) → {Promise}

Checks whether the file in filePath exists. The Promise that this function returns always resolves; it never rejects. — When the file is not found, it will resolve with a { exists: false }.
Parameters:
Name Type Description
filePath string The path to the file.
Source:
See:
  • stat
Returns:
a Promise that resolves with { exists, path }, where…
  • exists is true if the file exists.
  • path contains the path to the file.
Type
Promise

(inner) missingFiles(paths) → {Promise}

Takes a collection of paths and returns which of those paths do not point to files on the filesystem (i.e., which of those files are missing).
Parameters:
Name Type Description
paths Array.<string> The list of paths to validate.
Source:
Returns:
A Promise that resolves with a string[] of all the missing paths (which will be a subset of the input array paths).
Type
Promise

(inner) readBinary(path) → {Promise}

Reads the given file at path as a binary blob and returns a Promise that resolves with the content of the file as a Buffer.
Parameters:
Name Type Description
path string The path to the file.
Source:
Returns:
A Promise that resolves with the content of the file as a Buffer.
Type
Promise

(inner) readFile(path, options) → {Promise}

Reads the given file at path and returns a Promise that resolves with the content of the file.
Parameters:
Name Type Description
path string The path to the file to read.
options object (Optional) configuration options, defaults to { json: true, createIfNotExists: true, encoding: 'utf8', seed: '' }, where…
  • json is a flag to parse the file as JSON,
  • createIfNotExists creates the file, if it does not exists with the provided seed value (the default seed is an empty string),
  • And encoding is the input encoding of the file (defaults to "utf8").
Source:
See:
  • readTextFile
Returns:
A Promise that resolves with the content of the file.
Type
Promise

(inner) readTextFile(path, options) → {Promise}

Reads the given file at path with an assumption that it is a non-JSON text file and returns a Promise that resolves with the content of the file.
Parameters:
Name Type Description
path string The path to the file to read.
options object (Optional) configuration options, defaults to { json: false, createIfNotExists: true, encoding: 'utf8', seed: '' }, where…
  • json is a flag to parse the file as JSON,
  • createIfNotExists creates the file, if it does not exists with the provided seed value (the default seed is an empty string),
  • And encoding is the input encoding of the file (defaults to "utf8").
Source:
See:
  • readFile
Returns:
A Promise that resolves with the content of the file.
Type
Promise

(inner) stat(filePath) → {Promise}

Gets the stats of the file and resolves with a Promise that wraps the stats.
Parameters:
Name Type Description
filePath string The path to the file.
Source:
See:
  • exists
Returns:
a Promise that resolves with { stats, path } where…
  • stat is a Node.JS file stat object.
  • path is the path to the file.
Type
Promise

(inner) writeBinary(path, data, options) → {Promise}

Takes a binary Buffer (data) and writes it to the given file at path and then returns a Promise that resolves with the written data itself. Note that this operation truncates the file and overwrites it with data.
Parameters:
Name Type Description
path string The path to the file.
data Buffer What to write.
options object (Optional) configuration options, defaults to { json: true, encoding: 'utf8' }, where…
  • json is a flag to push the data as stringified JSON to the file,
  • And encoding is the output encoding of the file (defaults to "utf8").
Source:
Returns:
A Promise that resolves with the content of the file.
Type
Promise

(inner) writeFile(path, data, options) → {Promise}

Writes to the given file at path and returns a Promise that resolves with the written data itself. Note that this operation truncates the file and overwrites it with data.
Parameters:
Name Type Description
path string The path to file.
data object What to write.
options object (Optional) configuration options, defaults to { json: true, encoding: 'utf8' }, where…
  • json is a `boolean` flag that indicates whether the data is written as a stringified JSON to the file,
  • And encoding is the output encoding of the file (defaults to "utf8").
Source:
See:
  • writeTextFile
Returns:
a Promise that resolves with the content of the file.
Type
Promise

(inner) writeTextFile(path, data, options) → {Promise}

Writes a file with an assumption that the `data` passed is a plain UTF-8 text and not JSON.
Parameters:
Name Type Description
path string The path to file.
data object What to write.
options object (Optional) configuration options, defaults to { json: false, encoding: 'utf8' }, where…
  • json is a `boolean` flag that indicates whether the data is written as a stringified JSON to the file,
  • And encoding is the output encoding of the file (defaults to "utf8").
Source:
See:
  • writeFile
Returns:
a Promise that resolves with the content of the file.
Type
Promise