Created
March 14, 2011 23:38
-
-
Save aq1018/870085 to your computer and use it in GitHub Desktop.
Dynamic zip file archiving and streaming
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
#!/usr/bin/env node | |
var fs = require('fs'), | |
util = require('util'), | |
express = require('express'), | |
spawn = require('child_process').spawn, | |
app = express.createServer( | |
express.profiler(), | |
express.logger(), | |
express.bodyParser() | |
); | |
app.get('/', function(req, res){ | |
var files = req.param('files'), | |
args = ['-r', '-'].concat(files), | |
zip = spawn('zip', args); | |
if(!files) { | |
res.send('Bad Request', { 'Content-Type': 'text/plain' }, 400); | |
} else { | |
zip.stdout.pipe(res); | |
zip.stderr.on('data', function(data) { | |
console.log("stderr" + data); | |
}); | |
zip.on('exit', function (code) { | |
console.log("zip process exited with " + code); | |
// I guess I don't need end() | |
// since we are piping from zip process, it will end() anyway | |
//res.end(); | |
}); | |
} | |
}); | |
app.listen(3000); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Running apache bench on a MacBook Pro. ( 2.53 GHz i5, 4 GB memory )