Created
October 5, 2017 23:07
-
-
Save dy-dx/fcaad01dcd101cc9f5e0519af8bfd3ff to your computer and use it in GitHub Desktop.
async download bundler
This file contains 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
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