JS合并多个ArrayBuffer

2021-03-30  本文已影响0人  简夕_bcb0

使用Uint8Array来操作

function concatenate(...arrays) {

    let totalLen = 0;

    for (let arr of arrays)

        totalLen += arr.byteLength;

    let res = new Uint8Array(totalLen)

    let offset = 0

    for (let arr of arrays) {

        let uint8Arr = new Uint8Array(arr)

        res.set(uint8Arr, offset)

        offset += arr.byteLength

    }

    return res.buffer

}

上一篇下一篇

猜你喜欢

热点阅读