Skip to content

Instantly share code, notes, and snippets.

@dy-dx
Created October 5, 2017 23:07
Show Gist options
  • Save dy-dx/fcaad01dcd101cc9f5e0519af8bfd3ff to your computer and use it in GitHub Desktop.
Save dy-dx/fcaad01dcd101cc9f5e0519af8bfd3ff to your computer and use it in GitHub Desktop.
async download bundler
const http = require('http');
const archiver = require('archiver');
const request = require('request');
const urls = [
'http://www.colorado.edu/conflict/peace/download/peace.zip',
'http://www.colorado.edu/conflict/peace/download/peace_essay.ZIP',
'http://www.colorado.edu/conflict/peace/download/peace_example.ZIP',
];
http.createServer((req, response) => {
response.writeHead(200, {
'Content-Type': 'application/zip',
'Content-disposition': 'attachment; filename=bundle.zip'
});
const archive = archiver('zip');
archive
.on('error', console.error)
.pipe(response);
urls.forEach((url) => {
archive.append(request(url), { name: url.split('/').slice(-1)[0] })
});
archive.finalize();
}).listen(process.env.PORT || 3030);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment