axel-js
Version:
A lightweight download accelerator. Similar to axel.
56 lines (50 loc) • 1.86 kB
JavaScript
;
var optParser = new(require('option-parser'))();
var axel = require('../lib/axel');
var constants = require('../lib/constants');
var fmt = require('../lib/fmt');
var options = {
numConnections: constants.DEFAULT_NUM_CONNECTIONS,
verbose: false,
quiet: false,
output: null,
header: []
},
link;
optParser.addOption('n', 'num-connections', 'Specify maximum number of connections').argument('<NUM-CONNECTION>').action((value) => {
if (!isNaN(value)) {
options.numConnections = parseInt(value);
}
});
optParser.addOption('o', 'output', 'Specify local output file').argument('<OUTPUT>').action((value) => {
options.output = value;
});
optParser.addOption('H', 'header', 'Add header string').argument('<HEADER>').action((value) => {
options.header.push(value);
});
optParser.addOption('U', 'user-agent', 'Set user agent').argument('<USER-AGENT>').action((value) => {
options.header.push('User-Agent:' + value);
});
optParser.addOption('v', 'verbose', 'More status information').action(() => {
options.verbose = true;
});
optParser.addOption('q', 'quiet', ' No output to stdout').action(() => {
options.quiet = true;
});
optParser.addOption('h', 'help', 'Display this help message').action(optParser.helpAction('[options] url'));
optParser.addOption('V', 'version', 'Version information').action(() => {
console.log('axel-js version ' + constants.VERSION + ' (' + process.platform + ')');
process.exit(0);
});
link = optParser.parse();
if (link.length == 0) {
optParser.helpAction('[options] url')();
}
axel.download(link[0], options).then((data) => {
console.log(data)
fmt.printMessage('%s download finished!', link[0]);
}).catch((error) => {
console.log(error);
// fmt.printMessage('%s', error.toString());
});