0
0
mirror of https://github.com/nodejs/node.git synced 2024-12-01 16:10:02 +01:00

Handle empty files with fs.readFile

This commit is contained in:
Elijah Insua 2010-05-13 12:42:17 -07:00 committed by Ryan Dahl
parent c6c77d535f
commit 976926376d
3 changed files with 14 additions and 0 deletions

View File

@ -51,6 +51,10 @@ fs.readFile = function (path, encoding_, callback) {
var buffer = new Buffer(size);
var offset = 0;
function doRead() {
if (size < 1) {
callback(null, buffer);
return;
}
// 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) {
if (err) {

0
test/fixtures/empty.txt vendored Normal file
View File

View File

@ -0,0 +1,10 @@
require('../common');
var
path = require('path'),
fs = require('fs'),
fn = path.join(fixturesDir, 'empty.txt');
fs.readFile(fn, function(err, data) {
assert.ok(data);
});