Skip to content

How to make ReadableStreamByobReader.read_with_u8_array() work? #3579

Closed Answered by Liamolucko
rom1v asked this question in Q&A
Discussion options

You must be logged in to vote

So (just to be sure to understand), there is no way read_with_u8_array() could work, is it correct? (if so, maybe it should be removed)

Yes.

There's actually a pretty good reason for this. ReadableStreamBYOBReader doesn't quite work like you'd expect: you can't just pass it a Uint8Array, wait for the promise to resolve, and then read the results out of the original buffer like you can in something like Rust's std::io::Read::read.

This is because it actually takes control over the Uint8Array while it's being read into. You can't access it anymore until the promise gives it back to you, and the original reference to it stays invalid forever. You can only access it through the new referenc…

Replies: 2 comments 10 replies

Comment options

You must be logged in to vote
7 replies
@daxpedda
Comment options

@rom1v
Comment options

@daxpedda
Comment options

@Liamolucko
Comment options

Answer selected by rom1v
@MOZGIII
Comment options

@daxpedda
Comment options

Comment options

You must be logged in to vote
3 replies
@daxpedda
Comment options

@rom1v
Comment options

@daxpedda
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
4 participants
Converted from issue

This discussion was converted from issue #3575 on August 28, 2023 20:23.