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

feat(io): add readRange, readRangeSync #884

Merged
merged 1 commit into from
Apr 28, 2021

Conversation

kitsonk
Copy link
Contributor

@kitsonk kitsonk commented Apr 28, 2021

I found I needed to read a range of a seekable file and felt that readRange and readRangeSync are good compliments to readAll and realAllSync, so I wanted to contribute them back to std.

This PR also cleans up the Buffer() init types to accept what is truly needed to init the buffer which eliminates the need for arbitrary type asserts.

@kitsonk kitsonk requested a review from kt3k April 28, 2021 01:09
Copy link
Member

@kt3k kt3k left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. Nice feature to have 👍

@kitsonk kitsonk merged commit ac32161 into denoland:main Apr 28, 2021
const nread = await r.read(p);
assert(nread !== null, "Unexpected EOF reach while reading a range.");
assert(nread > 0, "Unexpected read of 0 bytes while reading a range.");
copy(p, result, off);
Copy link

@jabr jabr May 13, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why create and copy a new buffer here rather than just read into the result buffer directly?

const nread = await r.read(result.subarray(off))
assert()
assert()

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants