Browse Source

fs: use stat.st_size only to read regular files

Using st_size to read non-regular files can lead to not reading all the
data.

PR-URL: https://github.com/iojs/io.js/pull/1074
Reviewed-By: Bert Belder <bertbelder@gmail.com>
v1.8.0-commit
Santiago Gimeno 10 years ago
committed by Bert Belder
parent
commit
a6af709489
  1. 6
      lib/fs.js

6
lib/fs.js

@ -317,7 +317,7 @@ function readFileAfterStat(err, st) {
if (err)
return context.close(err);
var size = context.size = st.size;
var size = context.size = st.isFile() ? st.size : 0;
if (size === 0) {
context.buffers = [];
@ -395,10 +395,12 @@ fs.readFileSync = function(path, options) {
var flag = options.flag || 'r';
var fd = fs.openSync(path, flag, 0o666);
var st;
var size;
var threw = true;
try {
size = fs.fstatSync(fd).size;
st = fs.fstatSync(fd);
size = st.isFile() ? st.size : 0;
threw = false;
} finally {
if (threw) fs.closeSync(fd);

Loading…
Cancel
Save