Way data is stored for this database For a Node.js/Node Webkit database it's the file system For a browser-side database it's localforage, which uses the best backend available (IndexedDB then WebSQL then localStorage) For a react-native database, we use @react-native-async-storage/async-storage
This version is the Node.js/Node Webkit version It's essentially fs, mkdirp and crash safe write and read functions
* [storage](#module_storage) * _static_ * [.exists(file, cb)](#module_storage.exists) * [.existsAsync(file)](#module_storage.existsAsync) ⇒Promise.<boolean>
* [.rename(oldPath, newPath, c)](#module_storage.rename) ⇒ void
* [.renameAsync(oldPath, newPath)](#module_storage.renameAsync) ⇒ Promise.<void>
* [.writeFile(path, data, options, callback)](#module_storage.writeFile)
* [.writeFileAsync(path, data, [options])](#module_storage.writeFileAsync) ⇒ Promise.<void>
* [.writeFileStream(path, [options])](#module_storage.writeFileStream) ⇒ fs.WriteStream
* [.unlink(path, callback)](#module_storage.unlink)
* [.unlinkAsync(path)](#module_storage.unlinkAsync) ⇒ Promise.<void>
* [.appendFile(path, data, options, callback)](#module_storage.appendFile)
* [.appendFileAsync(path, data, [options])](#module_storage.appendFileAsync) ⇒ Promise.<void>
* [.readFile(path, options, callback)](#module_storage.readFile)
* [.readFileAsync(path, [options])](#module_storage.readFileAsync) ⇒ Promise.<Buffer>
* [.readFileStream(path, [options])](#module_storage.readFileStream) ⇒ fs.ReadStream
* [.mkdir(path, options, callback)](#module_storage.mkdir)
* [.mkdirAsync(path, options)](#module_storage.mkdirAsync) ⇒ Promise.<(void\|string)>
* [.ensureFileDoesntExistAsync(file)](#module_storage.ensureFileDoesntExistAsync) ⇒ Promise.<void>
* [.ensureFileDoesntExist(file, callback)](#module_storage.ensureFileDoesntExist)
* [.flushToStorage(options, callback)](#module_storage.flushToStorage)
* [.flushToStorageAsync(options)](#module_storage.flushToStorageAsync) ⇒ Promise.<void>
* [.writeFileLines(filename, lines, callback)](#module_storage.writeFileLines)
* [.writeFileLinesAsync(filename, lines)](#module_storage.writeFileLinesAsync) ⇒ Promise.<void>
* [.crashSafeWriteFileLines(filename, lines, [callback])](#module_storage.crashSafeWriteFileLines)
* [.crashSafeWriteFileLinesAsync(filename, lines)](#module_storage.crashSafeWriteFileLinesAsync) ⇒ Promise.<void>
* [.ensureDatafileIntegrity(filename, callback)](#module_storage.ensureDatafileIntegrity)
* [.ensureDatafileIntegrityAsync(filename)](#module_storage.ensureDatafileIntegrityAsync) ⇒ Promise.<void>
* _inner_
* [~existsCallback](#module_storage..existsCallback) : function
### storage.exists(file, cb)
Callback returns true if file exists
**Kind**: static method of [storage
](#module_storage)
| Param | Type |
| --- | --- |
| file | string
|
| cb | [existsCallback
](#module_storage..existsCallback) |
### storage.existsAsync(file) ⇒ Promise.<boolean>
Returns Promise
storage
](#module_storage)
| Param | Type |
| --- | --- |
| file | string
|
### storage.rename(oldPath, newPath, c) ⇒ void
Node.js' fs.rename
**Kind**: static method of [storage
](#module_storage)
| Param | Type |
| --- | --- |
| oldPath | string
|
| newPath | string
|
| c | [NoParamCallback
](#NoParamCallback) |
### storage.renameAsync(oldPath, newPath) ⇒ Promise.<void>
Node.js' fs.promises.rename
**Kind**: static method of [storage
](#module_storage)
| Param | Type |
| --- | --- |
| oldPath | string
|
| newPath | string
|
### storage.writeFile(path, data, options, callback)
Node.js' fs.writeFile
**Kind**: static method of [storage
](#module_storage)
| Param | Type |
| --- | --- |
| path | string
|
| data | string
|
| options | object
|
| callback | function
|
### storage.writeFileAsync(path, data, [options]) ⇒ Promise.<void>
Node.js' fs.promises.writeFile
**Kind**: static method of [storage
](#module_storage)
| Param | Type |
| --- | --- |
| path | string
|
| data | string
|
| [options] | object
|
### storage.writeFileStream(path, [options]) ⇒ fs.WriteStream
Node.js' fs.createWriteStream
**Kind**: static method of [storage
](#module_storage)
| Param | Type |
| --- | --- |
| path | string
|
| [options] | Object
|
### storage.unlink(path, callback)
Node.js' fs.unlink
**Kind**: static method of [storage
](#module_storage)
| Param | Type |
| --- | --- |
| path | string
|
| callback | function
|
### storage.unlinkAsync(path) ⇒ Promise.<void>
Node.js' fs.promises.unlink
**Kind**: static method of [storage
](#module_storage)
| Param | Type |
| --- | --- |
| path | string
|
### storage.appendFile(path, data, options, callback)
Node.js' fs.appendFile
**Kind**: static method of [storage
](#module_storage)
| Param | Type |
| --- | --- |
| path | string
|
| data | string
|
| options | object
|
| callback | function
|
### storage.appendFileAsync(path, data, [options]) ⇒ Promise.<void>
Node.js' fs.promises.appendFile
**Kind**: static method of [storage
](#module_storage)
| Param | Type |
| --- | --- |
| path | string
|
| data | string
|
| [options] | object
|
### storage.readFile(path, options, callback)
Node.js' fs.readFile
**Kind**: static method of [storage
](#module_storage)
| Param | Type |
| --- | --- |
| path | string
|
| options | object
|
| callback | function
|
### storage.readFileAsync(path, [options]) ⇒ Promise.<Buffer>
Node.js' fs.promises.readFile
**Kind**: static method of [storage
](#module_storage)
| Param | Type |
| --- | --- |
| path | string
|
| [options] | object
|
### storage.readFileStream(path, [options]) ⇒ fs.ReadStream
Node.js' fs.createReadStream
**Kind**: static method of [storage
](#module_storage)
| Param | Type |
| --- | --- |
| path | string
|
| [options] | Object
|
### storage.mkdir(path, options, callback)
Node.js' fs.mkdir
**Kind**: static method of [storage
](#module_storage)
| Param | Type |
| --- | --- |
| path | string
|
| options | object
|
| callback | function
|
### storage.mkdirAsync(path, options) ⇒ Promise.<(void\|string)>
Node.js' fs.promises.mkdir
**Kind**: static method of [storage
](#module_storage)
| Param | Type |
| --- | --- |
| path | string
|
| options | object
|
### storage.ensureFileDoesntExistAsync(file) ⇒ Promise.<void>
**Kind**: static method of [storage
](#module_storage)
| Param | Type |
| --- | --- |
| file | string
|
### storage.ensureFileDoesntExist(file, callback)
**Kind**: static method of [storage
](#module_storage)
| Param | Type |
| --- | --- |
| file | string
|
| callback | [NoParamCallback
](#NoParamCallback) |
### storage.flushToStorage(options, callback)
Flush data in OS buffer to storage if corresponding option is set
**Kind**: static method of [storage
](#module_storage)
| Param | Type | Default | Description |
| --- | --- | --- | --- |
| options | object
\| string
| | If options is a string, it is assumed that the flush of the file (not dir) called options was requested
| | [options.filename] |string
| | |
| [options.isDir] | boolean
| false
| Optional, defaults to false
| | callback | [NoParamCallback
](#NoParamCallback) | | |
### storage.flushToStorageAsync(options) ⇒ Promise.<void>
Flush data in OS buffer to storage if corresponding option is set
**Kind**: static method of [storage
](#module_storage)
| Param | Type | Default | Description |
| --- | --- | --- | --- |
| options | object
\| string
| | If options is a string, it is assumed that the flush of the file (not dir) called options was requested
| | [options.filename] |string
| | |
| [options.isDir] | boolean
| false
| Optional, defaults to false
| ### storage.writeFileLines(filename, lines, callback)Fully write or rewrite the datafile
**Kind**: static method of [storage
](#module_storage)
| Param | Type |
| --- | --- |
| filename | string
|
| lines | Array.<string>
|
| callback | [NoParamCallback
](#NoParamCallback) |
### storage.writeFileLinesAsync(filename, lines) ⇒ Promise.<void>
Fully write or rewrite the datafile
**Kind**: static method of [storage
](#module_storage)
| Param | Type |
| --- | --- |
| filename | string
|
| lines | Array.<string>
|
### storage.crashSafeWriteFileLines(filename, lines, [callback])
Fully write or rewrite the datafile, immune to crashes during the write operation (data will not be lost)
**Kind**: static method of [storage
](#module_storage)
| Param | Type | Description |
| --- | --- | --- |
| filename | string
| |
| lines | Array.<string>
| |
| [callback] | [NoParamCallback
](#NoParamCallback) | Optional callback, signature: err
| ### storage.crashSafeWriteFileLinesAsync(filename, lines) ⇒Promise.<void>
Fully write or rewrite the datafile, immune to crashes during the write operation (data will not be lost)
**Kind**: static method of [storage
](#module_storage)
| Param | Type |
| --- | --- |
| filename | string
|
| lines | Array.<string>
|
### storage.ensureDatafileIntegrity(filename, callback)
Ensure the datafile contains all the data, even if there was a crash during a full file write
**Kind**: static method of [storage
](#module_storage)
| Param | Type | Description |
| --- | --- | --- |
| filename | string
| |
| callback | [NoParamCallback
](#NoParamCallback) | signature: err
| ### storage.ensureDatafileIntegrityAsync(filename) ⇒Promise.<void>
Ensure the datafile contains all the data, even if there was a crash during a full file write
**Kind**: static method of [storage
](#module_storage)
| Param | Type |
| --- | --- |
| filename | string
|
### storage~existsCallback : function
**Kind**: inner typedef of [storage
](#module_storage)
| Param | Type |
| --- | --- |
| exists | boolean
|