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

Match Fetch and WHATWG Streams Spec #16

Closed
ariutta opened this issue Aug 19, 2016 · 4 comments
Closed

Match Fetch and WHATWG Streams Spec #16

ariutta opened this issue Aug 19, 2016 · 4 comments

Comments

@ariutta
Copy link
Contributor

ariutta commented Aug 19, 2016

We've discussed matching the WHATWG streams spec: async read method returns a Promise, which is fulfilled by an ArrayBuffer. I'm understanding that to mean we want to build an abstraction over the various fetch and xhr implementations so that they all give a reader with an async read method to the parsers. Here's what it would look like for various implementations:

  • 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.

Are we on the same page with this?

@ariutta
Copy link
Contributor Author

ariutta commented Aug 22, 2016

Here's a demo of this (ms-stream not yet implemented): #15 (comment)

@jonnyreeves jonnyreeves added this to the 0.5 milestone Aug 22, 2016
@ariutta ariutta changed the title Match WHATWG Streams Spec Match Fetch and WHATWG Streams Spec Aug 22, 2016
@ariutta
Copy link
Contributor Author

ariutta commented Aug 22, 2016

We want to dedup code for XHR, but I'm not sure how to best do this, because the patch for ms-stream needs to handle the readAsArrayBuffer method, which returns an eventemitter, meaning we have two eventemitters: the XHR response and the result from readAsArrayBuffer. So we might not be able to just create a single abstraction by applying browser-specific "patches" to a generic XHR request.

Also, do we want to use try/catch (something roughly like this) for feature detection or use browser detection as we are at present or use a combination of both?

@jonnyreeves
Copy link
Owner

Changing the milestone to 0.6; looking to land 0.5 with binary data support (and fix for chrome) in the mean time as real-life keeps getting in the way :(

@jonnyreeves
Copy link
Owner

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

No branches or pull requests

2 participants