Browse Source

Simplify buffering

There is no way more than one read event would be buffered.
v0.7.4-release
Felix Geisendörfer 15 years ago
parent
commit
b4fba5fe8e
  1. 16
      lib/fs.js

16
lib/fs.js

@ -395,7 +395,7 @@ var FileReadStream = exports.FileReadStream = function(path, options) {
var
self = this,
buffer = [];
buffer = null;
function read() {
if (!self.readable || self.paused) {
@ -411,7 +411,7 @@ var FileReadStream = exports.FileReadStream = function(path, options) {
// do not emit events if the stream is paused
if (self.paused) {
buffer.push(data);
buffer = data;
return;
}
@ -450,15 +450,9 @@ var FileReadStream = exports.FileReadStream = function(path, options) {
this.resume = function() {
this.paused = false;
// emit any buffered read events before continuing
var data;
while (!this.paused) {
data = buffer.shift();
if (data === undefined) {
break;
}
self.emit('data', data);
if (buffer !== null) {
self.emit('data', buffer);
buffer = null;
}
read();

Loading…
Cancel
Save