Skip to content Skip to sidebar Skip to footer

Converting Array Buffer To String - Maximum Call Stack Size Exceeded

Our app downloads a zip file, but the response is in binary. So what I did is to convert it to base64. It works when the size is 87.7KB but an error occurs when the response size i

Solution 1:

I got my answer from another question

btoa(newUint8Array(blob).reduce(function (data, byte) {
    return data + String.fromCharCode(byte);
}, ''));

Source

Solution 2:

https://stackoverflow.com/a/40077712/6582356

functionblobToB64(data) {
    if ('TextDecoder'inwindow) {
      // Decode as UTF-8var dataView = newDataView(data);
      var decoder = newTextDecoder('utf8');
      returnbtoa(decoder.decode(dataView));
    } else {
      // Fallbackreturnbtoa(newUint8Array(data).reduce((data, byte) =>
        data + String.fromCharCode(byte),
        ''))
    }
}

https://developer.mozilla.org/en-US/docs/Web/API/TextDecoder

This one is seems to have better performance

Post a Comment for "Converting Array Buffer To String - Maximum Call Stack Size Exceeded"