fs: fix writev empty array error behavior

PR-URL: https://github.com/nodejs/node/pull/41919
Fixes: https://github.com/nodejs/node/issues/41910
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
Reviewed-By: Robert Nagy <ronagy@icloud.com>
Reviewed-By: Minwoo Jung <nodecorelab@gmail.com>
This commit is contained in:
Benjamin Gruenbaum authored and GitHub committed 2022-02-12 17:57:52 +00:00
1 parent 9651f44000
commit a137eca069
2 files changed
+13

No files matched your search

+4
View File
@@ -596,6 +596,10 @@ async function writev(handle, buffers, position) {
if (typeof position !== 'number')
position = null;
if (buffers.length === 0) {
return { bytesWritten: 0, buffers };
}
const bytesWritten = (await binding.writeBuffers(handle.fd, buffers, position,
kUsePromises)) || 0;
return { bytesWritten, buffers };
+9
View File
@@ -47,4 +47,13 @@ tmpdir.refresh();
assert(Buffer.concat(bufferArr).equals(await fs.readFile(filename)));
handle.close();
}
{
// Writev with empty array behavior
const handle = await fs.open(getFileName(), 'w');
const result = await handle.writev([]);
assert.strictEqual(result.bytesWritten, 0);
assert.strictEqual(result.buffers.length, 0);
handle.close();
}
})().then(common.mustCall());