rndme / download

file downloading using client-side javascript
MIT License
2.28k stars 417 forks source link

Can't download ArrayBuffer #101

Closed chekoopa closed 3 years ago

chekoopa commented 3 years ago

Blob does support ArrayBuffer as a constructor argument, but when used on download(), it returns just a same-lengthed stream of zeroes it does everything right.

UPD: Don't forget to use views to fill ArrayBuffers, like this:

var str= "hello world", arr= new ArrayBuffer(str.length); arr2=new Int8Array(arr);
str.split("").forEach(function(a,b){
    arr2[b]=a.charCodeAt();
});
download( arr, "textArrayBuffer.txt", "text/plain" );

I'm closing the issue.