Skip to content

Commit

Permalink
use stats for download
Browse files Browse the repository at this point in the history
  • Loading branch information
joehand committed May 2, 2017
1 parent a1f1715 commit f56db69
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 11 deletions.
7 changes: 0 additions & 7 deletions cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,19 +83,12 @@ function trackProgress (state, bus) {
state.downloading = true
state.modified = false

var feed = state.archive.content
state.downloaded = 0
for (var i = 0; i < feed.length; i++) {
if (feed.has(i)) state.downloaded++
}

state.archive.content.on('clear', function () {
state.modified = true
})

state.archive.content.on('download', function (index, data) {
state.modified = true
state.downloaded++
})

state.archive.on('sync', function () {
Expand Down
9 changes: 5 additions & 4 deletions ui.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,8 @@ function downloadUI (state) {
${state.opts.live ? 'Waiting for changes...' : ''}
`
}
if (!state.downloaded) {
var stats = state.stats.get()
if (!stats.downloaded) {
return '' // no metadata yet
}
if (!state.downloadBar) {
Expand All @@ -80,15 +81,15 @@ function downloadUI (state) {
}
return output`
${state.downloadBar(state.downloaded)}
${state.downloadBar(stats.downloaded)}
`

function makeBar () {
var total = state.archive.content.length
var total = stats.length
state.downloadBar = progress({
total: total,
style: function (a, b) {
return `[${a}${b}] ${(100 * state.downloaded / total).toFixed(2)}%`
return `[${a}${b}] ${(100 * stats.downloaded / total).toFixed(2)}%`
}
})
}
Expand Down

0 comments on commit f56db69

Please sign in to comment.