dat-node 1.0 alpha
Node module for Dat (replaces dat-js).
Create Dat Archives with a .dat
folder. Join the Dat Network. Track stats and import files.
Features
Usage
Use to create or read Dat Archives on the file system in Node applications.
var Dat = require('dat-node')
Dat(dir, opts, function (err, dat) {
console.log(dat.path)
var db = dat.db
var archive = dat.archive
var network = dat.network(opts)
network.swarm
var stats = dat.stats()
var importer = dat.importFiles(opts, cb)
})
API
`Dat(dir, [opts], cb)``
Initialize a Dat Archive in dir
. If there is an existing Dat Archive, the archive will be resumed.
Initial opts
can include:
opts = {
db: level(path/.dat),
key: '<dat-key>',
resume: Boolean,
live: Boolean,
file: raf(),
dbName: '.dat'
}
The callback includes a dat
object that has the following properties:
dat.archive
Hyperdrive archive instance.
dat.db
.dat
folder database
dat.path
Path of the Dat Archive
dat-node
provides an easy interface to common Dat modules for the created Dat Archive on the dat
object provided in the callback:
var network = dat.network([opts])
Join the Dat Network for your Dat Archive.
opts
are passed to the swarm module. See hyperdrive-archive-swarm for options.
network.swarm
discovery-swarm instance.
network.peers()
Get number of peers connected to you.
var importer = dat.importFiles([opts], [cb])
Import files to your Dat Archive from the directory using hyperdrive-import-files. Options are passed to the importer module. cb
is called when import is finished.
dat-node
provides a default ignore option, ignoring the .dat
folder and all hidden files or directories.
Returns the importer event emitter.
var stats = dat.stats()
hyperdrive-stats instance for the Dat Archive. Stats are stored in a sublevel database in the .dat
folder.