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

Loading…
Cancel
Save