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
[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
 [email protected]
 For more options, visit this group at
 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
[3] 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

Reply via email to