This is basically an updated version of the existing loadImage function we used, which was pulled basically one for one from Parziphal on Stack Overflow: https://stackoverflow.com/a/42196770
The new function's biggest difference is that the resolved value is an ordinary fetch Response object, manually instantiated from an XHR's results, which supports the usual body-access functions. We get blob MIME type detection for free, though we have to manually parse the XHR's headers.
In the future, the guts of this function can probably be rewritten to report progress from a real fetch call and return its response object verbatim! For now all that matters to us is being able to choose whether we want a blob or array buffer out of the response, and building off XHR works fine for that.
This is basically an updated version of the existing
loadImage
function we used, which was pulled basically one for one from Parziphal on Stack Overflow: https://stackoverflow.com/a/42196770The new function's biggest difference is that the resolved value is an ordinary fetch
Response
object, manually instantiated from an XHR's results, which supports the usual body-access functions. We get blob MIME type detection for free, though we have to manually parse the XHR's headers.In the future, the guts of this function can probably be rewritten to report progress from a real
fetch
call and return its response object verbatim! For now all that matters to us is being able to choose whether we want a blob or array buffer out of the response, and building off XHR works fine for that.