Skip to content
This repository has been archived by the owner on Apr 22, 2023. It is now read-only.

Commit

Permalink
Fix: fs.readFile would execute callbacks twice
Browse files Browse the repository at this point in the history
fs.readFile was executing a callback in a try..catch context, which is
a problem in itself. To make matters worse, it would re-execute the
same callback if there was an execution.

This patch fixes both of these problems.
  • Loading branch information
felixge authored and ry committed Jun 3, 2010
1 parent 55d7352 commit 55e964e
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion lib/fs.js
Expand Up @@ -73,10 +73,12 @@ fs.readFile = function (path, encoding_, callback) {
binding.close(fd);
if (encoding) {
try {
callback(null, buffer.toString(encoding));
var str = buffer.toString(encoding);
} catch (err) {
callback(err);
return;
}
callback(null, str);
} else {
callback(null, buffer);
}
Expand Down

0 comments on commit 55e964e

Please sign in to comment.