Read streams now only support forceClose()

Write streams support close() and forceClose()
This commit is contained in:
Felix Geisendörfer 2010-03-04 22:06:06 +01:00
Родитель b4fba5fe8e
Коммит 48562fa938
2 изменённых файлов: 23 добавлений и 2 удалений

Просмотреть файл

@ -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;

Просмотреть файл

@ -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) {