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