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

Implement the File API's File.read method #3145

Closed
Tracked by #3141
oleiade opened this issue Jun 27, 2023 · 1 comment · Fixed by #3309
Closed
Tracked by #3141

Implement the File API's File.read method #3145

oleiade opened this issue Jun 27, 2023 · 1 comment · Fixed by #3309
Assignees
Milestone

Comments

@oleiade
Copy link
Member

oleiade commented Jun 27, 2023

As part of #3141, implementing the agreed-upon design for k6's File API, we intend to implement a File.read method.

The read method reads the file into an ArrayBuffer, and resolves to either the number of bytes read during the operation or null (EOF) if there is nothing more to read. Note that it should be possible for a read to be successful and return 0 bytes read while not indicating an EOF.

prototype

interface File {
    read(p ArrayBuffer | TypedArray | DataView): Promise<number>
}

example

const file = fs.openSync("fou.txt")
const buf = new Uint8Array(100);
const numberOfBytesRead = file.readSync(buf)
@oleiade
Copy link
Member Author

oleiade commented Nov 13, 2023

Implemented by #3309

@oleiade oleiade closed this as completed Nov 13, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant