dat-folder-db

2.1.3 • Public • Published

dat-folder-db Travis npm

Make Dat CLI compatible databases. A database made with dat-folder-db can be resumed with the Dat CLI.

Wrapper of level to create/resume a .dat folder database. If there is an existing .dat folder, it will get the key of the existing dat, allowing it to be resumed.

Use in Dat applications using node and the file system to store the database.

Usage

var datDb = require('dat-folder-db')
datDb(dir, function (err, db, existingKey, putKey) {
  if (err) throw err
  var resume = !!existingKey // resume the dat if a key exists
 
  // use db with hyperdrive
  var drive = hyperdrive(db)
  var archive = drive.createArchive(existingKey)
 
  if (!resume) putkey(archive.key, function () {
    // key in db. can resume now
  })
})

This will create a .dat folder: my_folder/.dat and a level database in that folder.

See example.js for a full example.

API

datFolder(dir, [opts], cb)

Creates a level db in the .dat folder and checks if there is an existing key saved there.

  • dir is required. This is the base path for the dat folder.
  • cb is called with (err, db, existingKey, saveKey)
    • db is the level database in dir/.dat
    • existingKey is the key found in the database or null if nothing is found.
    • saveKey is a function to save the key back to the database.

opts include:

opts = {
  dbName : '.dat' // use a different name for the database
}

License

MIT

Readme

Keywords

none

Package Sidebar

Install

npm i dat-folder-db

Weekly Downloads

2

Version

2.1.3

License

MIT

Last publish

Collaborators

  • jhand