- From: Jake Archibald <notifications@github.com>
- Date: Fri, 14 Sep 2018 15:07:15 +0000 (UTC)
- To: whatwg/fetch <fetch@noreply.github.com>
- Cc: Subscribed <subscribed@noreply.github.com>
- Message-ID: <whatwg/fetch/issues/809/421388625@github.com>
Would a constructor that takes an iterator and returns a ReadableStream of those values fix this problem? On Fri, 14 Sep 2018, 15:59 Jimmy Wärting, <notifications@github.com> wrote: > I where just thinking, what if Response and Request where able to accept > a @@asyncIterator and a @@iterator? > > That is the minium you need to create a producer that don't consume lot of > RAM and are able to generate lot of data. > > 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 > > // if using Node:// const { Request, Response } = require('node-fetch') > async function* iterator() { > yield Uint8Array.from([97, 98, 99]) > } > await new Response(iterator()).text() // abcawait 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, view it on GitHub > <https://github.com/whatwg/fetch/issues/809>, or mute the thread > <https://github.com/notifications/unsubscribe-auth/AAFtmkATU9CAk1Blr3tMNwWGsijXFngHks5ua8RZgaJpZM4WpbrV> > . > -- 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/fetch/issues/809#issuecomment-421388625
Received on Friday, 14 September 2018 15:07:39 UTC