Random behavior of an array buffer

I want to get directly an arrayBuffer using apetch apetch ( https://fetch.spec.whatwg.org/ ). Once the data is returned, I want to use the array buffer.

It looks like sometimes arrayBuffer () works and sometimes it doesn't. Doesn't work, I mean, sometimes it returns an empty array. It doesn't work most of the time.

fetch(url).then(function(response) {
      response.arrayBuffer().then(function(buffer){
            results[i] = buffer;
        });
});

      

If I call blob () and convert it to an array buffer via FileReader it always works.

fetch(url).then(function(response) {
      response.blob().then(function(buffer){
            results[i] = buffer;
        });
});

...

var myReader = new FileReader();
myReader.addEventListener("loadend", function(e){
    // ALWAYS GOOD
    var byteArray = new Uint8Array(e.srcElement.result);
});

myReader.readAsArrayBuffer(results[0]);

      

And a live demo: http://codepen.io/nicolasrannou/pen/OVLyjX

Am I doing something wrong or is this a bug?

Thanks, Nicolas

+3
ecmascript-6 blob fetch-api arraybuffer


source to share


No one has answered this question yet

Check out similar questions:

303
Fetch: POST json data
2
How can I take a link to a BLOB url and read it correctly using the filereader API?
2
Extracting Partial Data from FileReader ArrayBuffer
1
Angular 1.6 Watch ES6 $
1
Reading a text file from client and client that exceeds the maximum single line size in javascript
1
Implementing XMLHttpRequest.responseType "arraybuffer" encoding
1
difference between fetching page and file in serviceworker
0
multithreading using pools does not speed up data processing through threads.js
0
Fetch API "Unable to read property" forEach "undefined"
0
FileReader readAsArrayBuffer in IE11 does not work for large files



All Articles
Loading...
X
Show
Funny
Dev
Pics