fix for fs.readFile to return string when encoding specified on zero length read
authorMarco Rogers <marco.rogers@gmail.com>
Wed, 25 Aug 2010 04:36:08 +0000 (00:36 -0400)
committerRyan Dahl <ry@tinyclouds.org>
Mon, 30 Aug 2010 21:08:18 +0000 (14:08 -0700)
lib/fs.js
test/simple/test-fs-readfile-empty.js

index adaf5a4..7c8b38c 100644 (file)
--- a/lib/fs.js
+++ b/lib/fs.js
@@ -56,7 +56,7 @@ fs.readFile = function (path, encoding_, callback) {
       function doRead() {
         if (size < 1) {
           binding.close(fd);
-          callback(null, buffer);
+          callback(null, encoding ? '' : buffer);
           return;
         }
         // position is offset or null so we can read files on unseekable mediums
index 770d5e4..7b3ab1f 100644 (file)
@@ -9,3 +9,7 @@ var
 fs.readFile(fn, function(err, data) {
   assert.ok(data);
 });
+
+fs.readFile(fn, 'utf8', function(err, data) {
+  assert.strictEqual('', data);
+});
\ No newline at end of file