Fixed async fs writes with length 0, it should fire the callback

This commit is contained in:
Marco Rogers authored and Ryan Dahl committed 2010-09-08 17:45:21 -07:00
1 parent b39b15d53f
commit cdee88051d
2 files changed
+10 -2

No files matched your search

+9 -1
View File
@@ -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);
};
+1 -1
View File
@@ -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');