Yeah, ReadStream can't do it without re-opening the file, because you need seek() to be able to get rid of the EOF flag, and Node doesn't implement seek() (partly because of the integer problem with getting up to 64 bits, but that's a bit of a cop-out since createReadStream can take start/end params, so why was it ok there?). The "tail" module on npm just re-opens the file if the size changes using fs.watchFile().
Probably easier (and faster) to open a childprocess to tail -f, since opening and closing a file all those times has an overhead. Matt. On Thu, Feb 2, 2012 at 8:54 AM, Diogo Resende <[email protected]>wrote: > I think that's because of readstream reaching EOF. I don't know if > you can avoid this. One way could be knowing and having the size > updated for you and pausing readstream to avoid reaching EOF. > > Not sure if it's feasible.. :) > > --- > Diogo R. > > > On Thu, 2 Feb 2012 02:30:07 -0800 (PST), 宓俊 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/ [1] >> Posting guidelines: >> https://github.com/joyent/**node/wiki/Mailing-List-**Posting-Guidelines<https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines> >> [2] >> >> 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 >> nodejs+unsubscribe@**googlegroups.com<nodejs%[email protected]> >> For more options, visit this group at >> >> http://groups.google.com/**group/nodejs?hl=en?hl=en<http://groups.google.com/group/nodejs?hl=en?hl=en>[3] >> >> >> Links: >> ------ >> [1] http://jobs.nodejs.org/ >> [2] https://github.com/joyent/**node/wiki/Mailing-List-** >> Posting-Guidelines<https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines> >> [3] >> http://groups.google.com/**group/nodejs?hl=en?hl=en<http://groups.google.com/group/nodejs?hl=en?hl=en> >> > > -- > Job Board: http://jobs.nodejs.org/ > Posting guidelines: https://github.com/joyent/**node/wiki/Mailing-List-** > 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 > nodejs+unsubscribe@**googlegroups.com<nodejs%[email protected]> > For more options, visit this group at > http://groups.google.com/**group/nodejs?hl=en?hl=en<http://groups.google.com/group/nodejs?hl=en?hl=en> > -- 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
