Skip to content

Instantly share code, notes, and snippets.

@sdockray
Created February 20, 2017 00:15
Show Gist options
  • Save sdockray/c60dbaeb2f5a17a19dc7773ca158962a to your computer and use it in GitHub Desktop.
Save sdockray/c60dbaeb2f5a17a19dc7773ca158962a to your computer and use it in GitHub Desktop.
Basic dat-node example to clone a dat
var path = require('path')
var Dat = require('dat-node')
var testDir = path.join(__dirname, 'test-dir')
opts = {
key: 'fbdf68b3d65bd1cb46057d9b014a8db269a969185e435f683222d05f0809570e',
}
Dat(testDir, opts, function (err, dat) {
var archive = dat.archive
archive.open(function () {
// Network needs to connect for archive.open to callback
archive.content.once('download-finished', function () {
setTimeout(done, 500) // issue w/ download-finished firing before stats updated
})
})
// Join the network
var network = dat.joinNetwork()
network.once('connection', function () {
console.log('connects via network')
})
// Track stats
var stats = dat.trackStats()
stats.once('update', function () {
console.log('stats updated')
})
function done () {
console.log('done!')
}
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment