Browse Source

Updated file streams

Read streams now only support forceClose()

Write streams support close() and forceClose()
v0.7.4-release
Felix Geisendörfer 15 years ago
parent
commit
48562fa938
  1. 22
      lib/fs.js
  2. 3
      test/simple/test-file-write-stream.js

22
lib/fs.js

@ -405,7 +405,7 @@ var FileReadStream = exports.FileReadStream = function(path, options) {
fs.read(self.fd, self.bufferSize, undefined, self.encoding, function(err, data, bytesRead) {
if (bytesRead === 0) {
self.emit('end');
self.close();
self.forceClose();
return;
}
@ -415,6 +415,11 @@ var FileReadStream = exports.FileReadStream = function(path, options) {
return;
}
// do not emit events anymore after we declared the stream unreadable
if (!self.readable) {
return;
}
self.emit('data', data);
read();
});
@ -431,7 +436,7 @@ var FileReadStream = exports.FileReadStream = function(path, options) {
read();
});
this.close = function() {
this.forceClose = function() {
this.readable = false;
fs.close(this.fd, function(err) {
if (err) {
@ -544,6 +549,19 @@ var FileWriteStream = exports.FileWriteStream = function(path, options) {
flush();
};
this.forceClose = function() {
this.writeable = false;
fs.close(self.fd, function(err) {
if (err) {
self.emit('error', err);
return;
}
self.emit('close');
});
};
flush();
};
FileWriteStream.prototype.__proto__ = process.EventEmitter.prototype;

3
test/simple/test-file-write-stream.js

@ -17,6 +17,9 @@ file
callbacks.open++;
assert.equal('number', typeof fd);
})
.addListener('error', function(err) {
throw err;
})
.addListener('drain', function() {
callbacks.drain++;
if (callbacks.drain == -1) {

Loading…
Cancel
Save