Skip to content

Instantly share code, notes, and snippets.

@indexzero
Created January 3, 2014 02:59
Show Gist options
  • Save indexzero/8231840 to your computer and use it in GitHub Desktop.
Save indexzero/8231840 to your computer and use it in GitHub Desktop.
A simple remote download script for pkgcloud and rackspace
var fs = require('fs'),
zlib = require('zlib'),
tar = require('tar'),
pkgcloud = require('pkgcloud'),
argv = require('optimist').argv;
var client = pkgcloud.storage.createClient({
provider: argv.p,
username: argv.u,
apiKey: argv.k
});
if (!argv.r || !argv.p || !argv.u || !argv.k || !argv.c) {
return console.log('usage: remote-download -r remote-filename.tgz -p provider -u username -k api-key -c container');
}
function onError(err) {
console.error(err);
}
client.auth(function () {
var stream = client.download({
remote: argv.r,
container: argv.c
});
stream
.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