Permalink
Browse files

Handle empty files with fs.readFile

  • Loading branch information...
1 parent c6c77d5 commit 976926376d249a92ee95cf585d58c31ccdd85545 @tmpvar tmpvar committed with ry May 13, 2010
Showing with 14 additions and 0 deletions.
  1. +4 −0 lib/fs.js
  2. 0 test/fixtures/empty.txt
  3. +10 −0 test/simple/test-fs-readfile-empty.js
View
@@ -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) {
No changes.
@@ -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);
+});

0 comments on commit 9769263

Please sign in to comment.