Re: [whatwg/streams] Possible feature discussion: opaque streams (#983)

> Opaque streams are something we might wish to add in future. An opaque stream is a stream you can't read from, but you can pass it off to APIs that can.
> 
> With opaque streams, instead of `response.body` returning `null` for an opaque response, it would return an opaque stream.

In the case of `fetch`: wouldn't it make more sense to transfer the whole `Response` instead? Then you could also have access to the response headers and status code from the other origin.
```js
const response = await fetch(url, {mode: 'no-cors'});
postMessage(response, origin, [response]);
```
But then what would be the benefit of initiating a `no-cors` `fetch` from the initial origin and then transferring it, when you could just as well initiate the `fetch` from the other origin?

> ```js
> const reader = body.getReader();  // throws!
> ```
What _can_ you do with an opaque stream, other than transferring it?

Can you pipe an opaque readable stream into an writable stream? I guess that would require the writable stream to either _be_ or _become_ opaque as well. For example:
* You could pipe an opaque readable stream into the writable side of a `TextDecoderStream`. This would have to turn the readable side opaque as well.
* You could pipe an opaque readable stream into the writable side of a previously transferred `TransformStream` from the other origin.

Could you observe the result of an pipe between opaque streams? Is the initiator of the pipe allowed to know whether the pipe completes successfully or with an error through the pipe's `Promise`? Can the initiator abort the pipe using an `AbortSignal`?

-- 
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/983#issuecomment-463618784

Received on Thursday, 14 February 2019 13:02:14 UTC