- From: Jimmy Wärting <notifications@github.com>
- Date: Fri, 14 Sep 2018 07:20:25 -0700
- To: whatwg/streams <streams@noreply.github.com>
- Cc: Subscribed <subscribed@noreply.github.com>
- Message-ID: <whatwg/streams/pull/950/c421373573@github.com>
a bit out of track but I where just thinking, what if `Response` and `Request` where able to accept a `@@asyncIterator` and a `@@iterator`? Node.js and the the browser have different streaming api's but what they both will have in common is the `@@asyncIterator` that yields a `Uint8array` chunks. Node's streaming api can be exported to browsers. And whatwg-streams can be polyfilled in Node. But having to handle both in a uniformed way is tough and requires a large overhead and a dependency of the one or the other. A iterator can easily be created with neither of them and works in both the browser and Node.js ```js // if using Node: // const { Request, Response } = require('node-fetch') async function iterator() { yield Uint8Array.from([97, 98, 99]) } await new Response(iterator()).text() // abc await new Request(iterator()).text() // abc // With either Node-stream or whatwg-stream you would be able to do: await new Response(stream).text() await new Request(stream).text() // ...since it would be able to detect the `Symbol.asyncIterator` ``` There are already many modules out there that already uses node streaming api but none of them can be used by `window.fetch` together with Node's stream api unless they are converted to a `Blob` or a whatwg stream first Taking jsZip, WebTorrent and socket.io-stream as an example, they all utilize Nodes streaming api. But the fetch api can't handle them cuz it's a different streaming api (unless you are using node-fetch which is the complete opposite since they can't handle whatwg-streams) -- 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/950#issuecomment-421373573
Received on Friday, 14 September 2018 14:20:47 UTC