The JavaScript Database, for Node.js, nw.js, electron and the browser
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
nedb/docs/storage.md

13 KiB

storage

Way data is stored for this database. This version is the Node.js/Node Webkit version. It's essentially fs, mkdirp and crash safe write and read functions.

See

  • module:storageBrowser
  • module:storageReactNative

storage.exists(file, cb)

Callback returns true if file exists.

Kind: static method of storage
Params

storage.existsAsync(file) ⇒ Promise.<boolean>

Async version of [exists](#module_storage.exists).

Kind: static method of storage
See: module:storage.exists
Params

  • file string

storage.rename(oldPath, newPath, c) ⇒ void

Node.js' [fs.rename](https://nodejs.org/api/fs.html#fsrenameoldpath-newpath-callback).

Kind: static method of storage
Params

storage.renameAsync(oldPath, newPath) ⇒ Promise.<void>

Async version of [rename](#module_storage.rename).

Kind: static method of storage
See: module:storage.rename
Params

  • oldPath string
  • newPath string

storage.writeFile(path, data, options, callback)

Node.js' [fs.writeFile](https://nodejs.org/api/fs.html#fswritefilefile-data-options-callback).

Kind: static method of storage
Params

  • path string
  • data string
  • options object
  • callback function

storage.writeFileAsync(path, data, [options]) ⇒ Promise.<void>

Async version of [writeFile](#module_storage.writeFile).

Kind: static method of storage
See: module:storage.writeFile
Params

  • path string
  • data string
  • [options] object

storage.writeFileStream(path, [options]) ⇒ fs.WriteStream

Node.js' [fs.createWriteStream](https://nodejs.org/api/fs.html#fscreatewritestreampath-options).

Kind: static method of storage
Params

  • path string
  • [options] Object

Node.js' [fs.unlink](https://nodejs.org/api/fs.html#fsunlinkpath-callback).

Kind: static method of storage
Params

  • path string
  • callback function

storage.unlinkAsync(path) ⇒ Promise.<void>

Async version of [unlink](#module_storage.unlink).

Kind: static method of storage
See: module:storage.unlink
Params

  • path string

storage.appendFile(path, data, options, callback)

Node.js' [fs.appendFile](https://nodejs.org/api/fs.html#fsappendfilepath-data-options-callback).

Kind: static method of storage
Params

  • path string
  • data string
  • options object
  • callback function

storage.appendFileAsync(path, data, [options]) ⇒ Promise.<void>

Async version of [appendFile](#module_storage.appendFile).

Kind: static method of storage
See: module:storage.appendFile
Params

  • path string
  • data string
  • [options] object

storage.readFile(path, options, callback)

Node.js' [fs.readFile](https://nodejs.org/api/fs.html#fsreadfilepath-options-callback)

Kind: static method of storage
Params

  • path string
  • options object
  • callback function

storage.readFileAsync(path, [options]) ⇒ Promise.<Buffer>

Async version of [readFile](#module_storage.readFile).

Kind: static method of storage
See: module:storage.readFile
Params

  • path string
  • [options] object

storage.readFileStream(path, [options]) ⇒ fs.ReadStream

Node.js' [fs.createReadStream](https://nodejs.org/api/fs.html#fscreatereadstreampath-options).

Kind: static method of storage
Params

  • path string
  • [options] Object

storage.mkdir(path, options, callback)

Node.js' [fs.mkdir](https://nodejs.org/api/fs.html#fsmkdirpath-options-callback).

Kind: static method of storage
Params

  • path string
  • options object
  • callback function

storage.mkdirAsync(path, options) ⇒ Promise.<(void|string)>

Async version of [mkdir](#module_storage.mkdir).

Kind: static method of storage
See: module:storage.mkdir
Params

  • path string
  • options object

storage.ensureFileDoesntExistAsync(file) ⇒ Promise.<void>

Async version of [ensureFileDoesntExist](#module_storage.ensureFileDoesntExist)

Kind: static method of storage
See: module:storage.ensureFileDoesntExist
Params

  • file string

storage.ensureFileDoesntExist(file, callback)

Removes file if it exists.

Kind: static method of storage
Params

storage.flushToStorage(options, callback)

Flush data in OS buffer to storage if corresponding option is set.

Kind: static method of storage
Params

  • options object | string -

    If options is a string, it is assumed that the flush of the file (not dir) called options was requested

    • [.filename] string
    • [.isDir] boolean = false -

      Optional, defaults to false

  • callback NoParamCallback

storage.flushToStorageAsync(options) ⇒ Promise.<void>

Async version of [flushToStorage](#module_storage.flushToStorage).

Kind: static method of storage
See: module:storage.flushToStorage
Params

  • options object | string
    • [.filename] string
    • [.isDir] boolean = false

storage.writeFileLines(filename, lines, [callback])

Fully write or rewrite the datafile.

Kind: static method of storage
Params

  • filename string
  • lines Array.<string>
  • [callback] NoParamCallback = () => {}

storage.writeFileLinesAsync(filename, lines) ⇒ Promise.<void>

Async version of [writeFileLines](#module_storage.writeFileLines).

Kind: static method of storage
See: module:storage.writeFileLines
Params

  • 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
Params

  • filename string
  • lines Array.<string>
  • [callback] NoParamCallback -

    Optional callback, signature: err

storage.crashSafeWriteFileLinesAsync(filename, lines) ⇒ Promise.<void>

Async version of [crashSafeWriteFileLines](#module_storage.crashSafeWriteFileLines).

Kind: static method of storage
See: module:storage.crashSafeWriteFileLines
Params

  • 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
Params

storage.ensureDatafileIntegrityAsync(filename) ⇒ Promise.<void>

Async version of [ensureDatafileIntegrity](#module_storage.ensureDatafileIntegrity).

Kind: static method of storage
See: module:storage.ensureDatafileIntegrity
Params

  • filename string

storage~existsCallback : function

Kind: inner typedef of storage
Params

  • exists boolean