From 78c61000c20e0456a3d887bc397fe29815f2f9e5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Felix=20Geisend=C3=B6rfer?= Date: Fri, 5 Mar 2010 19:53:59 +0100 Subject: [PATCH] Properly handle read errors Also set readable to false if the initial fs.open call failed. --- lib/fs.js | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/lib/fs.js b/lib/fs.js index 165ece8155..56c739389b 100644 --- a/lib/fs.js +++ b/lib/fs.js @@ -409,6 +409,12 @@ var FileReadStream = exports.FileReadStream = function(path, options) { } 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) { self.emit('end'); self.forceClose(); @@ -434,6 +440,7 @@ var FileReadStream = exports.FileReadStream = function(path, options) { fs.open(this.path, this.flags, this.mode, function(err, fd) { if (err) { self.emit('error', err); + self.readable = false; return; }