Closed
Description
Version
v14.18.1
Platform
Linux 5.4.141-78.230.amzn2int.x86_64 Fri Aug 27 01:18:39 UTC 2021 x86_64 x86_64 x86_64 GNU/Linux
Subsystem
No response
What steps will reproduce the bug?
Code
const fs = require('fs/promises');
let handle;
async function main() {
handle = await fs.open(__filename, 'r');
await read(0, 5); // Should get const ✅
await read(11, 7); // Should get require ✅
await read(0, 5); // Should get const again; zero is not honored ❌
await read(11, 7); // Should get require ✅
}
async function read(start, length) {
const buffer = Buffer.alloc(length);
await handle.read({ buffer, position: start, length });
console.log(buffer.toString());
}
Console Output
const
require
fs =
require
How often does it reproduce? Is there a required condition?
It's reproduced whenever you try to use 0
as the seek position
What is the expected behavior?
I would expect to be able to navigate back and forth using different positions of the file..
What do you see instead?
I am able to do that only if the position > 0 (STRICTLY greater than)
Additional information
I believe the cause might be this line here:
node/lib/internal/fs/promises.js
Line 524 in 2e2a6fe
Since 0
is falsy in javascript this might lead to this behavior. I am happy to put in a pull request to fix if indeed this is the cause.