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 2022-02-12 19:57:52 +02:00 committed by GitHub
parent 9651f44000
commit a137eca069
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 13 additions and 0 deletions

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 };

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());