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:
parent
9651f44000
commit
a137eca069
@ -596,6 +596,10 @@ async function writev(handle, buffers, position) {
|
|||||||
if (typeof position !== 'number')
|
if (typeof position !== 'number')
|
||||||
position = null;
|
position = null;
|
||||||
|
|
||||||
|
if (buffers.length === 0) {
|
||||||
|
return { bytesWritten: 0, buffers };
|
||||||
|
}
|
||||||
|
|
||||||
const bytesWritten = (await binding.writeBuffers(handle.fd, buffers, position,
|
const bytesWritten = (await binding.writeBuffers(handle.fd, buffers, position,
|
||||||
kUsePromises)) || 0;
|
kUsePromises)) || 0;
|
||||||
return { bytesWritten, buffers };
|
return { bytesWritten, buffers };
|
||||||
|
@ -47,4 +47,13 @@ tmpdir.refresh();
|
|||||||
assert(Buffer.concat(bufferArr).equals(await fs.readFile(filename)));
|
assert(Buffer.concat(bufferArr).equals(await fs.readFile(filename)));
|
||||||
handle.close();
|
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());
|
})().then(common.mustCall());
|
||||||
|
Loading…
x
Reference in New Issue
Block a user