Better progress stats.
This commit is contained in:
parent
42bb3b5aca
commit
99985f4fab
@ -37,6 +37,7 @@
|
|||||||
"lodash.pairs": "^2.4.1",
|
"lodash.pairs": "^2.4.1",
|
||||||
"mkdirp": "^0.5.0",
|
"mkdirp": "^0.5.0",
|
||||||
"multiline": "^0.3.4",
|
"multiline": "^0.3.4",
|
||||||
|
"pretty-ms": "^1.0.0",
|
||||||
"progress-stream": "^0.5.0",
|
"progress-stream": "^0.5.0",
|
||||||
"sent": "^1.1.0",
|
"sent": "^1.1.0",
|
||||||
"xdg": "^0.1.1",
|
"xdg": "^0.1.1",
|
||||||
|
@ -20,6 +20,7 @@ var humanFormat = require('human-format');
|
|||||||
var isObject = require('lodash.isobject');
|
var isObject = require('lodash.isobject');
|
||||||
var multiline = require('multiline');
|
var multiline = require('multiline');
|
||||||
var pairs = require('lodash.pairs');
|
var pairs = require('lodash.pairs');
|
||||||
|
var prettyMs = require('pretty-ms');
|
||||||
var progressStream = require('progress-stream');
|
var progressStream = require('progress-stream');
|
||||||
var sent = promisify(require('sent'));
|
var sent = promisify(require('sent'));
|
||||||
var Xo = require('xo-lib');
|
var Xo = require('xo-lib');
|
||||||
@ -73,10 +74,19 @@ function pipeWithErrors(streams) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function printProgress(progress) {
|
function printProgress(progress) {
|
||||||
console.warn('%s downloaded at %s/s',
|
if (progress.length) {
|
||||||
humanFormat(progress.transferred),
|
console.warn('%s% of %s @ %s/s - ETA %s',
|
||||||
humanFormat(progress.speed)
|
Math.round(progress.percentage),
|
||||||
);
|
humanFormat(progress.length),
|
||||||
|
humanFormat(progress.speed),
|
||||||
|
prettyMs(progress.eta * 1e3)
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
console.warn('%s @ %s/s',
|
||||||
|
humanFormat(progress.transferred),
|
||||||
|
humanFormat(progress.speed)
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function wrap(val) {
|
function wrap(val) {
|
||||||
@ -274,14 +284,19 @@ function call(args) {
|
|||||||
url = resolveUrl(baseUrl, result[key]);
|
url = resolveUrl(baseUrl, result[key]);
|
||||||
|
|
||||||
return stat(file).then(function (stats) {
|
return stat(file).then(function (stats) {
|
||||||
|
var length = stats.size;
|
||||||
|
|
||||||
var input = pipeWithErrors([
|
var input = pipeWithErrors([
|
||||||
createReadStream(file),
|
createReadStream(file),
|
||||||
progressStream({ time: 1e3 }, printProgress),
|
progressStream({
|
||||||
|
length: length,
|
||||||
|
time: 1e3,
|
||||||
|
}, printProgress),
|
||||||
]);
|
]);
|
||||||
|
|
||||||
return sent(url, input, {
|
return sent(url, input, {
|
||||||
headers: {
|
headers: {
|
||||||
'content-length': stats.size,
|
'content-length': length,
|
||||||
},
|
},
|
||||||
method: 'POST'
|
method: 'POST'
|
||||||
}).get(0);
|
}).get(0);
|
||||||
|
Loading…
Reference in New Issue
Block a user