Converting array buffer to string - Maximum call stack size exceeded

前端 未结 2 1171
执念已碎
执念已碎 2021-01-04 17:30

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 occ

相关标签:
2条回答
  • 2021-01-04 18:05

    I got my answer from another question

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

    Source

    0 讨论(0)
  • 2021-01-04 18:13

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

    function blobToB64(data) {
        if ('TextDecoder' in window) {
          // Decode as UTF-8
          var dataView = new DataView(data);
          var decoder = new TextDecoder('utf8');
          return btoa(decoder.decode(dataView));
        } else {
          // Fallback
          return btoa(new Uint8Array(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

    0 讨论(0)
提交回复
热议问题