Last active
December 18, 2015 18:29
-
-
Save Siedrix/5825969 to your computer and use it in GitHub Desktop.
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
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