Skip to content

Commit

Permalink
[v0.3.2][s]: Progress bar when uploading files to S3 (#31)
Browse files Browse the repository at this point in the history
* [progress bar][s]: now we show progress bar of each file being uploaded - refs datopian/data-cli#116

* [progress bar][xs]: clear a progress bar once completed - refs datopian/data-cli#116
  • Loading branch information
anuveyatsu authored Mar 6, 2018
1 parent f8f1942 commit 0055ad6
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
13 changes: 12 additions & 1 deletion lib/utils/datahub.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ const toArray = require('stream-to-array')
const infer = require('tableschema').infer
const YAML = require('yamljs')
const urljoin = require('url-join')
const ProgressBar = require('progress')

const {Agent} = require('./agent')
const {checkUrlIsOK} = require('./common')
Expand Down Expand Up @@ -86,7 +87,17 @@ class DataHub extends EventEmitter {
// https://github.com/datahq/datahub-qa/issues/60
throw new Error("> You can not push empty files, please add some data and try again:\n" + resource.path)
}

// Show the progress bar for each file being uploaded:
let bar = new ProgressBar(` Uploading [:bar] :percent (:etas left) ${resource.descriptor.path}`, {
complete: '*',
incomplete: ' ',
width: 30,
total: totalLength,
clear: true
})
formData.on('data', (chunk) => {
bar.tick(chunk.length)
})
// Use straight fetch as not interacting with API but with external object store
const res = await fetch(creds.upload_url, {
method: 'POST',
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "datahub-client",
"version": "0.3.1",
"version": "0.3.2",
"description": "APIs for interacting with DataHub",
"main": "index.js",
"scripts": {
Expand Down Expand Up @@ -51,7 +51,6 @@
"markdown-table": "^1.1.1",
"mkdirp": "^0.5.1",
"nconf": "^0.9.1",
"nock": "^9.1.0",
"node-fetch": "^1.7.3",
"opn": "^5.1.0",
"progress": "^2.0.0",
Expand All @@ -64,6 +63,7 @@
"devDependencies": {
"ava": "^0.19.1",
"inquirer-test": "^1.0.5",
"nock": "^9.1.0",
"sinon": "^4.1.2",
"stream-to-array": "^2.3.0",
"xo": "^0.18.2"
Expand Down

0 comments on commit 0055ad6

Please sign in to comment.