Last active
December 16, 2015 19:19
-
-
Save Evangenieur/5484570 to your computer and use it in GitHub Desktop.
zipStream in Node.js
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
fs = require "fs" | |
es = require('event-stream') | |
zipstream = require("zipstream") | |
app = require("express")() | |
files = ["rt_p2p_server.coffee", "rt_p2p_server.screen"] | |
addFile = (files) -> | |
unless files.length | |
zip.finalize -> | |
console.log "Done" | |
return | |
file = files.pop() | |
console.log "Zipping #{file}" | |
fileStream = fs.createReadStream(file) | |
zip.addFile fileStream, name: file, -> | |
console.log "End adding #{file}" | |
addFile(files) | |
app.get "/", (req, res) -> | |
zip = zipstream.createZip({ level: 1 }) | |
zip.pipe es.map (raw_data, cb) -> | |
console.log "Receiving raw_data" | |
cb() | |
zip.pipe res | |
addFile files | |
app.listen 3010 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment