Integrate nicer progress bar for os:download

This commit is contained in:
Juan Cruz Viotti 2014-12-02 17:40:13 -04:00
parent 2b5d95af3a
commit ffdd44752a
3 changed files with 16 additions and 6 deletions

View File

@ -39,4 +39,4 @@ exports.download = (id) ->
], (error) ->
resin.errors.handle(error) if error?
console.log "\n\nFinished downloading #{outputFile}"
resin.log.info("\nFinished downloading #{outputFile}")

View File

@ -1,8 +1,8 @@
async = require('async')
pace = require('pace')
fs = require('fs')
widgets = require('../widgets/widgets')
server = require('../../server/server')
ProgressBar = require('progress')
exports.remove = (name, confirmAttribute, deleteFunction, outerCallback) ->
async.waterfall([
@ -21,6 +21,8 @@ exports.remove = (name, confirmAttribute, deleteFunction, outerCallback) ->
exports.downloadFile = (url, dest, callback) ->
bar = null
received = 0
server.request
method: 'GET'
url: url
@ -28,6 +30,14 @@ exports.downloadFile = (url, dest, callback) ->
, (error) ->
return callback(error)
, (state) ->
return if not state?
bar ?= pace(state.total)
bar.op(state.received)
bar ?= new ProgressBar 'Downloading device OS [:bar] :percent :etas',
complete: '='
incomplete: ' '
width: 40
total: state.total
return if bar.complete or not state?
bar.tick(state.received - received)
received = state.received

View File

@ -54,6 +54,6 @@
"pubnub": "~3.7.0",
"request-progress": "~0.3.1",
"progress-bar": "~0.1.1",
"pace": "0.0.4"
"progress": "~1.1.8"
}
}