node-archiver: Streaming to res not working, getting empty errored file
Hello, I run in quite the same issue (when streaming to file it works, when streaming to http client it gives corrupt files.), #161 seems to have same issues, but i’m runing on local with nodejs and nodemon, on windows. version of node is 4.2.1, archiver 0.17.0 here is my code. the res ‘end’ event is not raised. Nor is the res ‘data’ event.
var archive = archiver('zip');
archive.on('error', function(err) {
console.error(err);
res.status(500).send({error: err.message});
});
//on stream closed we can end the request
res.on('close', function() {
console.log('Archive wrote %d bytes', archive.pointer());
return res.status(200).send('OK').end();
});
res.attachment('myzip.zip');
//this is the streaming magic
archive.pipe(res);
archive.append('hello zip1',{name : 'text1.txt'});
archive.append('hellooooo zip2',{ name : 'test2.txt'});
archive.finalize(function(err, bytes) {
if (err) {
throw err;
}
console.log(bytes + ' total bytes');
});
);
here is what i get as a file :
the example i’m inspired by is this one : http://stackoverflow.com/questions/20107303/dynamically-create-and-stream-zip-to-client/25210806#25210806
About this issue
- Original URL
- State: closed
- Created 9 years ago
- Comments: 23 (10 by maintainers)
This is the fix: app.use(require(‘connect-livereload’)({ ignore: [‘download’] }));
By using
on('end')
event. See this example with expressjs. Le dim. 29 nov. 2015 à 00:35, Sky Lightna notifications@github.com a écrit :