From 9c7c6e93e1c11be8ed1d1a123d64d6499767b361 Mon Sep 17 00:00:00 2001 From: Marco Rogers Date: Tue, 24 Aug 2010 23:46:37 -0400 Subject: [PATCH] Fixed async fs writes with length 0, it should fire the callback --- lib/fs.js | 10 +++++++++- test/simple/test-fs-write.js | 2 +- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/lib/fs.js b/lib/fs.js index 1e081c8793..adaf5a4281 100644 --- a/lib/fs.js +++ b/lib/fs.js @@ -211,7 +211,15 @@ fs.write = function (fd, buffer, offset, length, position, callback) { offset = 0; length = buffer.length; } - if(!length) return; + + if (!length) { + if (typeof callback == 'function') { + process.nextTick(function() { + callback(undefined, 0); + }); + } + return; + } binding.write(fd, buffer, offset, length, position, callback || noop); }; diff --git a/test/simple/test-fs-write.js b/test/simple/test-fs-write.js index c371c06792..d47d0254dd 100644 --- a/test/simple/test-fs-write.js +++ b/test/simple/test-fs-write.js @@ -11,7 +11,7 @@ fs.open(fn, 'w', 0644, function (err, fd) { if (err) throw err; console.log('open done'); fs.write(fd, '', 0, 'utf8', function(err, written) { - assert.fail('zero length write should not go through to callback'); + assert.equal(0, written); }); fs.write(fd, expected, 0, "utf8", function (err, written) { console.log('write done');