Converting array buffer to string - Maximum call stack size exceeded(将数组缓冲区转换为字符串 - 超出最大调用堆栈大小)
问题描述
我们的应用下载了一个 zip 文件,但响应是二进制的.
Our app downloads a zip file, but the response is in binary.
所以我所做的就是将其转换为 base64.大小为87.7KB
时有效,但响应大小为183KB
时出错.
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 is 183KB
.
错误是Uncaught RangeError: Maximum call stack size exceeded
有问题的行是
btoa(String.fromCharCode.apply(null, new Uint8Array(blob)))
根据this answer,必须替换 String.fromCharCode.apply()
使用 TextEncoder
.
According to this answer, the String.fromCharCode.apply()
must be replaced with TextEncoder
.
所以我改成
btoa(new TextDecoder('utf-8').decode(new Uint8Array(blob)))
但我得到一个错误.
Uncaught DOMException: Failed to execute 'btoa' on 'Window': 要编码的字符串包含 Latin1 范围之外的字符.
我使用此answer
现在是新代码
btoa(unescape(encodeURIComponent(new TextDecoder('utf-8').decode(new Uint8Array(blob)))))
现在可以下载,但下载的 zip 文件已损坏.
The download now works but the download zip file is corrupted.
整个代码可见这里
推荐答案
我从另一个问题得到了答案
I got my answer from another question
btoa(new Uint8Array(blob).reduce(function (data, byte) {
return data + String.fromCharCode(byte);
}, ''));
来源
这篇关于将数组缓冲区转换为字符串 - 超出最大调用堆栈大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:将数组缓冲区转换为字符串 - 超出最大调用堆栈


- CSS媒体查询(最大高度)不起作用,但为什么? 2022-01-01
- 如何使用 JSON 格式的 jQuery AJAX 从 .cfm 页面输出查 2022-01-01
- 400或500级别的HTTP响应 2022-01-01
- 失败的 Canvas 360 jquery 插件 2022-01-01
- Fetch API 如何获取响应体? 2022-01-01
- Quasar 2+Apollo:错误:找不到ID为默认的Apollo客户端。如果您在组件设置之外,请使用ProvideApolloClient() 2022-01-01
- addEventListener 在 IE 11 中不起作用 2022-01-01
- Css:将嵌套元素定位在父元素边界之外一点 2022-09-07
- 使用RSelum从网站(报纸档案)中抓取多个网页 2022-09-06
- Flexslider 箭头未正确显示 2022-01-01