- From: Mattias Buelens <notifications@github.com>
- Date: Tue, 02 Feb 2021 02:08:42 -0800
- To: whatwg/streams <streams@noreply.github.com>
- Cc: Subscribed <subscribed@noreply.github.com>
- Message-ID: <whatwg/streams/issues/1105/771523711@github.com>
Hmm, good point. I don't see why you shouldn't be allowed to construct a `Response` from a partially-read or cancelled `ReadableStream`. 🤔
For example, it's already possible to create a non-disturbed `ReadableStream` from a disturbed one, thus bypassing this restriction:
```javascript
let rs1 = new ReadableStream({
start(c) {
c.enqueue(new Uint8Array([1, 2, 3]));
c.enqueue(new Uint8Array([4, 5, 6]));
c.enqueue(new Uint8Array([7, 8, 9]));
c.close();
}
});
// Disturb the stream
let reader1 = rs1.getReader();
await reader1.read(); // { done: false, value: Uint8Array([1, 2, 3]) }
reader1.releaseLock();
new Response(rs1); // throws TypeError: "Response body object should not be disturbed or locked"
// Create a "fresh" stream that continues from rs1
let rs2 = rs1.pipeThrough(new TransformStream());
// or: let [rs2, rs3] = rs1.tee(); rs3.cancel();
let resp = new Response(rs2); // works
await resp.arrayBuffer(); // ArrayBuffer([4, 5, 6, 7, 8, 9])
```
Once we have `ReadableStream.from()`, this will become even easier:
```javascript
new Response(rs1) // throws
new Response(ReadableStream.from(rs1)) // ok
```
Does anyone have any idea why we have this restriction? 🤷♂️
--
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/issues/1105#issuecomment-771523711
Received on Tuesday, 2 February 2021 10:08:54 UTC