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.
This commit is contained in:
parent
55d7352189
commit
55e964ec19
@ -73,10 +73,12 @@ fs.readFile = function (path, encoding_, callback) {
|
|||||||
binding.close(fd);
|
binding.close(fd);
|
||||||
if (encoding) {
|
if (encoding) {
|
||||||
try {
|
try {
|
||||||
callback(null, buffer.toString(encoding));
|
var str = buffer.toString(encoding);
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
callback(err);
|
callback(err);
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
callback(null, str);
|
||||||
} else {
|
} else {
|
||||||
callback(null, buffer);
|
callback(null, buffer);
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user