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. |
Returns:
a
Promise that resolves with { existedBefore, created, error, reason };
where…
existedBeforeistrueif the file was there before.createdistrueif file was created successfully.errorandreasonare 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. |
Returns:
A
Promise taht resolves with an [] of
{ stat, path } objects where…
statis a Node.JS file stat object.pathis 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. |
Returns:
a
Promise that resolves with { exists, path }, where…
existsistrueif the file exists.pathcontains 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. |
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. |
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…
|
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…
|
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. |
Returns:
a
Promise that resolves with { stats, path }
where…
statis a Node.JS file stat object.pathis 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…
|
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…
|
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…
|
Returns:
a
Promise that resolves with the content of the file.
- Type
- Promise