node.js - Nodejs blocks and can't process next requests during ZIP file streaming -
i'm trying create simple app create zip on fly containg few files , stream them client. works. problem encountered nodejs blocks when streaming in progress. pendig requests processed after finishing current streaming. interesting, these pending requests processed concurrently! can this! don't understand, why nodejs (expressjs?) can't start processing next request during streaming 1 file , did wrong... :|
i'm using node-archiver stream source.
here's part of code:
var express = require('express'); var archiver = require('archiver'); var router = express.router(); router.get('/job/:id', function(req, res) { var job = req.jobs[req.params.id]; var archive = archiver('zip'); archive.pipe(res); (var n in job.files) { var f = job.files[n]; archive.file(job.path + f, {name: f}); } res.setheader("content-type", "application/zip"); res.setheader("content-disposition", 'attachment; filename="reports.zip"') archive.finalize(); }); module.exports = router;
any advices? thanks!
edit: i've noticed problem, not related archiver. have following basic app:
var http = require('http'); var fs = require('fs'); var server = http.createserver(function (req, res) { var stream = fs.createreadstream('file.blob'); stream.pipe(res); }); server.listen(31922);
tell me, why stuck in case? result absolutely same using archiver. os use smartos (based on open solaris), it's unix. maybe problem? ideas?
for of struggling similar problem. i'm being dumb perhaps. solution simple. testing method wrong. browser (and other tested have similar behaviour) blocks processing next request same host name when previous 1 not finished. , in case not finished request downloading still in progress. help!
Comments
Post a Comment