Skip to content

Commit

Permalink
basic hyperdb share and download
Browse files Browse the repository at this point in the history
  • Loading branch information
max-mapper committed Jun 7, 2018
1 parent 4965629 commit fa69ea9
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 49 deletions.
17 changes: 4 additions & 13 deletions cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ var argv = minimist(process.argv.slice(2), {
alias: {temp: 't', help: 'h', watch: 'w', sleep: 's'},
boolean: ['watch'],
default: {
'watch' : true
// 'watch' : true
}
})

Expand All @@ -45,21 +45,12 @@ function runDat () {
else {
network.once('connection', function () {
console.log('connected to peer!')
download()
dat.archive.db.source.on('sync', function () {
console.log('Downloaded')
})
})
}

function download () {
console.log(`Downloading: ${dat.key.toString('hex')}`)
console.log('to:', path.resolve(dest), '\n')
var progress = mirror({fs: dat.archive, name: '/'}, dest, function (err) {
if (err) throw err
console.log('Done')
})
progress.on('put', function (src) {
console.log('Downloading', src.name)
})
}

function share () {
network.on('connection', function () {
Expand Down
11 changes: 1 addition & 10 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,9 @@
var Dat = require('dat-node')
var encoding = require('dat-encoding')
// var debug = require('debug')('dat')
var storage = require('./storage')

module.exports = run

function run (src, dest, opts, cb) {
opts = Object.assign({
latest: false
}, opts)

if (dest) {
// Downloading
try {
Expand All @@ -19,12 +13,9 @@ function run (src, dest, opts, cb) {
return cb(new Error('Invalid dat link'))
}
src = null

opts.sparse = true
opts.temp= true // use memory for downloads right now
}

Dat(storage(src || dest, opts), opts, function (err, dat) {
Dat(src || dest, opts, function (err, dat) {
if (err) return cb(err)
if (!dat.owner && !dest) {
return cb(new Error('Not archive owner and no destination provided.'))
Expand Down
26 changes: 0 additions & 26 deletions storage.js

This file was deleted.

0 comments on commit fa69ea9

Please sign in to comment.