Skip to content

Commit

Permalink
fix suggestions
Browse files Browse the repository at this point in the history
  • Loading branch information
pulkit-30 committed Dec 7, 2023
1 parent 35ee64e commit ca3883a
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 1 deletion.
1 change: 1 addition & 0 deletions ex.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Hello world
22 changes: 22 additions & 0 deletions index.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import fs from "fs/promises";

async function test() {
let path = './ex.txt';

let buf = Buffer.alloc(4);
let handle;
try {
handle = await fs.open(path);
{
let buf = Buffer.alloc(4);
let { bytesRead, buffer } = await handle.read(buf);
// let { bytesRead, buffer } = await handle.read(buf, {}); // It is behavior I would expect.
console.log(bytesRead);
console.log(buffer);
console.log(buf);
}
} finally {
await handle?.close();
}
}
test();
2 changes: 1 addition & 1 deletion lib/internal/fs/promises.js
Original file line number Diff line number Diff line change
Expand Up @@ -670,7 +670,7 @@ async function read(handle, bufferOrParams, offset, length, position) {
validateInteger(offset, 'offset', 0);
}

length = length ?? buffer.byteLength - offset;
length ??= buffer.byteLength - offset;

if (length === 0)
return { __proto__: null, bytesRead: length, buffer };
Expand Down

0 comments on commit ca3883a

Please sign in to comment.