mirror of https://github.com/nodejs/node.git
Properly handle read errors
Also set readable to false if the initial fs.open call failed.pull/22966/head
parent
145fac2b56
commit
78c61000c2
|
@ -409,6 +409,12 @@ 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 (err) {
|
||||||
|
self.emit('error', err);
|
||||||
|
self.readable = false;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (bytesRead === 0) {
|
if (bytesRead === 0) {
|
||||||
self.emit('end');
|
self.emit('end');
|
||||||
self.forceClose();
|
self.forceClose();
|
||||||
|
@ -434,6 +440,7 @@ var FileReadStream = exports.FileReadStream = function(path, options) {
|
||||||
fs.open(this.path, this.flags, this.mode, function(err, fd) {
|
fs.open(this.path, this.flags, this.mode, function(err, fd) {
|
||||||
if (err) {
|
if (err) {
|
||||||
self.emit('error', err);
|
self.emit('error', err);
|
||||||
|
self.readable = false;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue