在处理返回文件的时候,碰到一个返回文件过大,因而处理的时候会报Maximum call stack size exceeded的问题。
原来的处理代码:
String.fromCharCode.apply(null, new Uint8Array(arraybuffer))
文件过大会报错。
看了好多解决方法,最后在stackoverflow上找的一个靠谱的解决方法:
const arrayBufferToBase64 = (buffer: any) => {
const uint8Array = new Uint8Array(buffer);
const data = uint8Array.reduce(
(acc, i) => (acc += String.fromCharCode.apply(null, [i])),
''
);
return data;
};
用这个代码替换原来的处理,就可以解决了。
参考:https://stackoverflow.com/questions/38432611/converting-arraybuffer-to-string-maximum-call-stack-size-exceeded/