Created
January 3, 2014 02:59
-
-
Save indexzero/8231840 to your computer and use it in GitHub Desktop.
A simple remote download script for pkgcloud and rackspace
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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