Skip to content

Instantly share code, notes, and snippets.

@kenperkins
Forked from indexzero/remote-download.js
Last active January 2, 2016 01:59
Show Gist options
  • Save kenperkins/8233786 to your computer and use it in GitHub Desktop.
Save kenperkins/8233786 to your computer and use it in GitHub Desktop.
var fs = require('fs'),
zlib = require('zlib'),
tar = require('tar'),
pkgcloud = require('pkgcloud'),
log = require('../../common/logging'),
argv = require('optimist').argv;
var logger = log.getLogger('debug');
var client = pkgcloud.storage.createClient({
provider: argv.p,
username: argv.u,
apiKey: argv.k,
region: argv.R
});
client.on('log::*', log.logFunction);
if (!argv.r || !argv.p || !argv.u || !argv.k || !argv.c || !argv.R) {
return console.log('usage: remote-download -r remote-filename.tgz -p provider -u username -k api-key -c container -R region');
}
function onError(err) {
console.error(err);
}
client.download({
remote: argv.r,
container: argv.c
})
.pipe(zlib.Gunzip())
.on('error', onError)
.pipe(tar.Extract({ path: 'downloaded' }))
.on('error', onError)
.on('end', function () {
console.log('completed!');
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment