mirror of https://github.com/nodejs/node.git
Fix: fs.readFile would execute callbacks twice
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.pull/22966/head
parent
55d7352189
commit
55e964ec19
|
@ -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);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue