Re: [whatwg/streams] Fix readable/writable file stream examples (PR #1191)

Thanks! Looks good. 👍

> Also the ReadableStream example misused the `fileHandle.read` call: it was supplying an ArrayBuffer and v's byteOffset within the ArrayBuffer, but the API requires supplying v itself and an offset relative to v's start.

I noticed a similar mistake in the ["A readable stream with an underlying pull source"](https://streams.spec.whatwg.org/commit-snapshots/5885d94e532e168959b98d27887e7f9f5e6becd3/#example-rs-pull) example. We're passing an `ArrayBuffer` to `fileHandle.read()`, but [it only accepts `Buffer | TypedArray | DataView`](https://nodejs.org/api/fs.html#filehandlereadbuffer-offset-length-position). https://github.com/whatwg/streams/blob/5885d94e532e168959b98d27887e7f9f5e6becd3/index.bs#L7305-L7307


We should probably use `new Uint8Array(CHUNK_SIZE)` instead, and use `.subarray(0, bytesRead)` (or `.slice`) in the `controller.enqueue()` call. Could you fix that too as part of this PR? 🙂

-- 
You are receiving this because you are subscribed to this thread.
Reply to this email directly or view it on GitHub:
https://github.com/whatwg/streams/pull/1191#issuecomment-981108982

Received on Sunday, 28 November 2021 15:59:44 UTC