diff --git a/lib/fs.js b/lib/fs.js index 033b8b7a14..fcb89d29f5 100644 --- a/lib/fs.js +++ b/lib/fs.js @@ -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) { diff --git a/test/fixtures/empty.txt b/test/fixtures/empty.txt new file mode 100644 index 0000000000..e69de29bb2 diff --git a/test/simple/test-fs-readfile-empty.js b/test/simple/test-fs-readfile-empty.js new file mode 100644 index 0000000000..8073fb5938 --- /dev/null +++ b/test/simple/test-fs-readfile-empty.js @@ -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); +}); \ No newline at end of file