Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Streaming support #198

Closed
atgillette opened this issue Aug 24, 2015 · 13 comments
Closed

Streaming support #198

atgillette opened this issue Aug 24, 2015 · 13 comments

Comments

@atgillette
Copy link

Is there any plans to add support for streaming, something like what request has?

@dgraham
Copy link
Contributor

dgraham commented Aug 24, 2015

There are no current plans for streaming requests or responses. We are limited by what XMLHttpRequest supports.

There is a draft specification for streams in the Fetch API, with a native implementation shipping in Chrome already.

@jimmywarting
Copy link

jimmywarting commented Sep 16, 2016

Please reopen, there are two was you can get a stream from XMLHttpRequest.

xhrRequest.responseType = "ms-stream";
// or
xhrRequest.responseType = "moz-chunked-arraybuffer";

If this would be implemented then i would rather want to use the polyfill then firefox or edge partially supported fetch api
This is crucial for my application where i need to handle large file with lower memory.
And with web-stream-polyfill this would be a breeze

@mislav
Copy link
Contributor

mislav commented Sep 17, 2016

Sure, let's revisit this. But I make no promises about actually implementing this in github/fetch.

It sounds like we can get native streaming from Chrome 43+, and streaming via XHR in IE and Firefox. How about Safari— is anything available there?

@mislav mislav reopened this Sep 17, 2016
@jimmywarting
Copy link

Like i said to jonnyreeves/chunked-request

Played a bit myself with streams and monkey patching xhr:
This is how i would do it for firefox: https://jsfiddle.net/98L105v3/2/

I created it yesterday, maybe it would be of any interest?

@jimmywarting
Copy link

jimmywarting commented Sep 17, 2016

Borrow some info from jonnyreeves/chunked-request#16

  • Chrome: use native reader from fetch
  • FF: set responseType to moz-chunked-arraybuffer, get ArrayBuffer(s) from xhr.response progress event(s), accumulate if needed, resolve reader.read Promise
  • IE10+: set responseType to ms-stream, call readAsArrayBuffer on xhr.response to get an eventemitter, get ArrayBuffer(s) from eventemitter progress event(s), accumulate if needed, resolve reader.read Promise
  • IE9: set responseType to text, slice xhr.responseText on progress event(s) to get chunk(s), convert to ArrayBuffer(s) using text-encoding-utf-8, accumulate if needed, resolve reader.read Promise
  • Safari: until it supports fetch, basically do the same thing as for IE9, except use native Uint8Array when converting to ArrayBuffer like this.

They also utility a partial request method (making multiple range request) Perhaps this would be a solution or just make it overkill

@jimmywarting
Copy link

jimmywarting commented Sep 17, 2016

if this gets implemented the we can't use this code any longer

  if (self.fetch) {
    return
  }

Cuz with streams i think the polyfill would actually be better then the partial fetch api FF & Edge supports

@jimmywarting
Copy link

Oh, and by the way.
If someone would do new Responsen(blob, {}).body.getReader() then there is some code you can take out of my Screw-FileReader lib about the part where I make a blob to a ReadableStream 😉

@caub
Copy link

caub commented Oct 28, 2016

Even if XMLHttpRequest can't really do streams, I think it would be great to have https://github.com/domenic/streams-demo working on old browsers, with only one chunk, and by adding a res.body.getReader()

@happycollision
Copy link

@jimmywarting I'm not sure if this is still a concern, but the workaround method for a bad FileReader might also work to allow this polyfill to override a native implementation so you can keep your preferred streaming when browsers only offer partial support.

@mutantcornholio
Copy link

this project probably deserves to be looked at too

@Angel3477

This comment has been minimized.

@sandorvasas
Copy link

still no stream support?

@mislav
Copy link
Contributor

mislav commented May 21, 2019

Still no streaming support, and I think that it's safe to decide at this point that this polyfill will never have streaming support.

This polyfill has been feature-complete for a while (i.e. has all the features implemented that cover most common usages of fetch) and will likely get no new large features. Furthermore, this polyfill isn't even used in any of today's modern browsers, since Chrome, Firefox, Safari, and Edge all have shipped with a native implementation of window.fetch for a long while now.

If your app really needs streaming, feature-detect it and use native browser capabilities. When streaming capabilities are not present (e.g. when this polyfill is being used in old browsers), your app should gracefully fall back to regular request/response reading.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

9 participants