BTW, I was thinking of coding some type of service like this that lets users download files as they're being uploaded. Would like to see what you have if you don't mind.
On Feb 2, 3:30 am, 宓俊 <[email protected]> wrote: > I want the user to be able to download a file while it is uploading. So I > write this code to test. > > var fs = require('fs'); > > > > > > > > > > > var writeStream = fs.createWriteStream(__dirname + "/uploading.txt"); > > writeStream.on('open', function(){ > > console.log('Write stream has open'); > > //Write a number every 1 second. > > var i = 1; > > var repeat = function(){ > > writeStream.write(i); > > console.log('Number ' + i + ' has been write to the file'); > > i = i + 1; > > setTimeout(repeat, 1000); > > }; > > repeat(); > > var readStream = fs.ReadStream(__dirname + "/uploading.txt"); > > readStream.on('data', function(data){ > > console.log('Data is coming: ' + data); > > }); > > readStream.on('end', function(){ > > console.log('Stream END'); > > }); > > }); > > But the result is like this > > Write stream has open > > > Number 1 has been write to the file > > Data is coming: 1 > > Stream END > > Number 2 has been write to the file > > Number 3 has been write to the file > > Number 4 has been write to the file > > When the reading speed is faster than the writing speed, I will receive a > 'end' signal, rather than paused. > > So how to deal with this problem? -- Job Board: http://jobs.nodejs.org/ Posting guidelines: https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines You received this message because you are subscribed to the Google Groups "nodejs" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/nodejs?hl=en?hl=en
