From f56db6902ac1bcde6f8657e3fda7b417c05bba84 Mon Sep 17 00:00:00 2001 From: Joe Hand Date: Tue, 2 May 2017 14:46:40 -0700 Subject: [PATCH] use stats for download --- cli.js | 7 ------- ui.js | 9 +++++---- 2 files changed, 5 insertions(+), 11 deletions(-) diff --git a/cli.js b/cli.js index 61b1bb1..fb97d59 100755 --- a/cli.js +++ b/cli.js @@ -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 () { diff --git a/ui.js b/ui.js index d4edcd3..365e668 100644 --- a/ui.js +++ b/ui.js @@ -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) { @@ -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)}%` } }) }