Skip to content

Instantly share code, notes, and snippets.

@Siedrix
Last active December 18, 2015 18:29
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Siedrix/5825969 to your computer and use it in GitHub Desktop.
Save Siedrix/5825969 to your computer and use it in GitHub Desktop.
this.httpServer.get('/files/download/:organization/course/:course/class/:class', function(req, res){
var zip = zipstream.createZip({ level: 1 });
res.setHeader('Content-disposition', 'attachment; filename=' + req.params.course);
zip.on('data', function(data){
res.write(data);
});
Files.find({
organization: req.params.organization,
course: req.params.course,
class: req.params.class
}).exec(function (err, data) {
var files = data.map(function(item){
var file = new File(item);
return function(callback){
zip.addFile(fs.createReadStream( file.location() ), { name: file.name }, function() {
callback(null, true);
});
};
});
async.series(files, function(err, results){
zip.finalize(function(written) {
res.end();
});
});
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment