Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Two types of filehandle.read return different values #41558

Closed
nujarum opened this issue Jan 16, 2022 · 6 comments
Closed

Two types of filehandle.read return different values #41558

nujarum opened this issue Jan 16, 2022 · 6 comments
Labels
fs Issues and PRs related to the fs subsystem / file system.

Comments

@nujarum
Copy link

nujarum commented Jan 16, 2022

Version

v14.18.3 / v16.13.2

Platform

Microsoft Windows NT 10.0.19044.0 x64

Subsystem

fs/promises

What steps will reproduce the bug?

import { open } from 'fs/promises';

const path = '/path/to/file';
const fh = await open(path, 'w+'); // reading & writing

const input = new Uint8Array([0, 1, 2, 3]);
await fh.writeFile(input);

const length = input.byteLength;
const buffer = new Uint8Array(length);
const offset = 0;
const position = 0;

const result1 = await fh.read(buffer, offset, length, position);     // 4 parameters
const result2 = await fh.read({ buffer, offset, length, position }); // 1 object parameter

console.log('result1:', result1);
console.log('result2:', result2);

How often does it reproduce? Is there a required condition?

No response

What is the expected behavior?

I think the expected behavior is that these two return values are the same.

What do you see instead?

result1: { bytesRead: 4, buffer: Uint8Array(4) [ 0, 1, 2, 3 ] }
result2: { bytesRead: 0, buffer: Uint8Array(4) [ 0, 1, 2, 3 ] }

Additional information

No response

@Mesteery Mesteery added the fs Issues and PRs related to the fs subsystem / file system. label Jan 16, 2022
@nujarum
Copy link
Author

nujarum commented Jan 16, 2022

I get the same result even if I reverse the order of execution, but is it expected behavior?

const result2 = await fh.read({ buffer, offset, length, position }); // => { bytesRead: 0, buffer: Uint8Array(4) [ 0, 1, 2, 3 ] }
const result1 = await fh.read(buffer, offset, length, position);     // => { bytesRead: 4, buffer: Uint8Array(4) [ 0, 1, 2, 3 ] }

@Trott
Copy link
Member

Trott commented Jan 16, 2022

@nodejs/fs

@christian102094
Copy link

I think this was a bug (see #40715 and #40699). Already fixed in #40716. I guess it was released in Node version 17.2.x (#40983).

@nujarum
Copy link
Author

nujarum commented Jan 17, 2022

@christian102094 Thanks for the information.

Sorry, I was not aware of those closed issues.

Should I close this issue?

@benjamingr
Copy link
Member

@nujarum if you can verify this works for you in latest node that'd be helpful - after that sure!

Thanks for the report btw.

@nujarum
Copy link
Author

nujarum commented Jan 19, 2022

Sorry for late reply.

I have confirmed that this has been fixed in the latest version v17.4.0.

$ node -v
v17.4.0
const result2 = await fh.read({ buffer, offset, length, position });
// => result2: { bytesRead: 4, buffer: Uint8Array(4) [ 0, 1, 2, 3 ] }

Now that I understand the cause of this problem, I am going to close this issue.

(I hope this will be fixed in the LTS versions, v14 and v16. 😉)

@nujarum nujarum closed this as completed Jan 19, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
fs Issues and PRs related to the fs subsystem / file system.
Projects
None yet
Development

No branches or pull requests

5 participants