|
@ -53,12 +53,17 @@ fs.readFile = function (path, encoding_, callback) { |
|
|
function doRead() { |
|
|
function doRead() { |
|
|
// position is offset or null so we can read files on unseekable mediums
|
|
|
// position is offset or null so we can read files on unseekable mediums
|
|
|
binding.read(fd, buffer, offset, size - offset, offset || null, function (err, amount) { |
|
|
binding.read(fd, buffer, offset, size - offset, offset || null, function (err, amount) { |
|
|
if (err) { callback(err); return; } |
|
|
if (err) { |
|
|
|
|
|
callback(err); |
|
|
|
|
|
binding.close(fd); |
|
|
|
|
|
return; |
|
|
|
|
|
} |
|
|
if (amount + offset < size) { |
|
|
if (amount + offset < size) { |
|
|
offset += amount; |
|
|
offset += amount; |
|
|
doRead(); |
|
|
doRead(); |
|
|
return; |
|
|
return; |
|
|
} |
|
|
} |
|
|
|
|
|
binding.close(fd); |
|
|
if (encoding) { |
|
|
if (encoding) { |
|
|
try { |
|
|
try { |
|
|
callback(null, buffer.toString(encoding)); |
|
|
callback(null, buffer.toString(encoding)); |
|
|