Skip to content

Commit

Permalink
update mirror folder to PR api
Browse files Browse the repository at this point in the history
  • Loading branch information
joehand committed Mar 27, 2017
1 parent 2dfdcd3 commit 0ca8b23
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 12 deletions.
2 changes: 1 addition & 1 deletion cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ dat(src, dest, argv, function (archive, swarm, importProgress) {
output[1][0] = bar(imported)
})

importProgress.on('chunk', function (chunk) {
importProgress.on('put-data', function (chunk) {
imported += chunk.length
if (bar) output[1][0] = bar(imported)
output[1][1] = pretty(indexSpeed(chunk.length)) + '/s'
Expand Down
25 changes: 15 additions & 10 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,12 @@ module.exports = run

function run (src, dest, opts, cb) {
var key
var importProgress
if (dest) {
key = src
src = null
mkdirp.sync(dest)
}

var dir = dest || src
opts = xtend({
storage: opts.sleep ? path.join(dir, '.dat') : ram
Expand All @@ -28,38 +28,43 @@ function run (src, dest, opts, cb) {

archive.on('ready', function () {
cast.emit('ready')
if (!key) importFiles()
var progress = importFiles()
var swarm = joinNetwork()
cb(archive, swarm, importProgress)
cb(archive, swarm, progress)
})

function importFiles () {
if (!archive.metadata.writable) return
var progress
var ignore = datIgnore(dir)
importProgress = mirror(dir, {name: '/', fs: archive}, {

progress = mirror(dir, {name: '/', fs: archive}, {
ignore: ignore
})

countDir(dir, { ignore: ignore }, function (err, data) {
if (err) throw err
cast.emit('import:count', data)
importProgress.emit('count', data)
progress.emit('count', data)
})

importProgress.on('put', function (src, dst) {
progress.on('put', function (src, dst) {
cast.emit('import:put', src, dst)
})
importProgress.on('chunk', function (chunk) {
progress.on('put-data', function (chunk) {
cast.emit('import:chunk', chunk)
})
importProgress.on('del', function (dst) {
progress.on('del', function (dst) {
cast.emit('import:del', dst)
})
importProgress.on('end', function () {
progress.on('end', function () {
cast.emit('import:end')
})
importProgress.on('error', function (err) {
progress.on('error', function (err) {
debug('IMPORT ERROR:', err)
})

return progress
}

function joinNetwork () {
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
"hyperdrive": "github:mafintosh/hyperdrive#v8",
"localcast": "^2.0.1",
"minimist": "^1.2.0",
"mirror-folder": "github:joehand/mirror-folder#add/through",
"mirror-folder": "^1.1.0",
"mkdirp": "^0.5.1",
"prettier-bytes": "^1.0.3",
"progress-string": "^1.2.1",
Expand Down

0 comments on commit 0ca8b23

Please sign in to comment.