requestTask.onChunkReceived((res) => {
console.log("onChunkReceived res=>", res);
requestTask.onChunkReceived 解析buffer 方案体积过大优化?
onChunkReceived res=> {data: ArrayBuffer(64971)} 返回的数据需要解析成字符串,然后转化为对象使用,但是解析字符串发现中文有乱码现象,因此采用了方案
// 在需要使用的地方引入
import { TextDecoder, TextEncoder } from 'text-encoding';
// 使用 TextDecoder
function decodeWithEncodingLib(buffer, charset = 'utf-8') {
const decoder = new TextDecoder(charset);
return decoder.decode(new Uint8Array(buffer));
}
但是该方案导致小程序的体积占比太大,有其他方案优化吗?
现在引入两个包, 2M 主包就不够了,还只是基本功能而已呢

at decodeURIComponent (<anonymous>)
at StreamProcessor._decodeArrayBuffer (stream-processor.js:125)
at StreamProcessor._decodeChunk (stream-processor.js:80)
at StreamProcessor.processChunk (stream-processor.js:22)
at Function.<anonymous> (VM1240 index.js:794)
at Function.<anonymous> (VM574 WASubContext.js:1)(env: Windows,mp,1.06.2504060; lib: 3.12.1)