Browse Source

Handle empty files with fs.readFile

v0.7.4-release
Elijah Insua 15 years ago
committed by Ryan Dahl
parent
commit
976926376d
  1. 4
      lib/fs.js
  2. 0
      test/fixtures/empty.txt
  3. 10
      test/simple/test-fs-readfile-empty.js

4
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) {

0
test/fixtures/empty.txt

10
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);
});
Loading…
Cancel
Save