Skip to content

Instantly share code, notes, and snippets.

@Evangenieur
Last active December 16, 2015 19:19
Show Gist options
  • Save Evangenieur/5484570 to your computer and use it in GitHub Desktop.
Save Evangenieur/5484570 to your computer and use it in GitHub Desktop.
zipStream in Node.js
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