javascript - How to end() a file stream -


i having weird issue piece of sample code got here, central part being this:

server.on('request', function(request, response) {   var file = fs.createwritestream('copy.csv');   var filesize = request.headers['content-length'];   var uploadedsize = 0;    request.on('data', function (chunk) {     uploadedsize += chunk.length;     uploadprogress = (uploadedsize/filesize) * 100;     response.write(math.round(uploadprogress) + "%" + " uploaded\n" );     var bufferstore = file.write(chunk);     console.log(bufferstore);     console.log(chunk);      if(!bufferstore)      {       request.pause();     }   });    file.on('drain', function() {     request.resume();   });    request.on('end', function() {     response.write('upload done!');     response.end();   }); }); 

the problem is, file copy.csv not contain after process finished.
tried add file.end(); in request.on('end'-callback, did not trick. however, if add faulty code in said callback causes exception, file being written fine (although ofc can't final solution).

to notify stream there no more chunks read, can call your_stream.push(null). can read more streams , push(null) from excellent substack's stream guide.


Comments

Popular posts from this blog

css - Which browser returns the correct result for getBoundingClientRect of an SVG element? -

gcc - Calling fftR4() in c from assembly -

.htaccess - Matching full URL in RewriteCond -