Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- var
- https = require('https'),
- AdmZip = require('adm-zip'),
- app = require('express')();
- app.get("/*", function(req, res) {
- var
- parts = req.params[0].split('/'),
- owner = parts[0],
- repo = parts[1],
- branch = parts[2],
- top_dir = repo + '-' + branch + '/',
- zip_address = 'https://nodeload.github.com/' + owner + '/' + repo + '/zip/' + branch;
- https.get(zip_address, function(response) {
- var data = [], dataLen = 0;
- response.on('data', function(chunk) {
- data.push(chunk);
- dataLen += chunk.length;
- }).on('end', function() {
- var buf = new Buffer(dataLen);
- for (var i = 0, len = data.length, pos = 0; i < len; i++) {
- data[i].copy(buf, pos);
- pos += data[i].length;
- }
- var zip = new AdmZip(buf);
- // Modify zip file, to remove the top-level directory
- var out = zip.toBuffer();
- res.header('Content-Type', 'application/zip');
- res.header('Content-Disposition', 'attachment; filename="' + repo + '.zip"');
- res.send(out);
- });
- });
- });
- app.listen(3000);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement