Necesito convertir una gran matriz (Uint8Array(224337596)) dentro de mi código. Aparentemente, el tamaño es demasiado grande y hace que el navegador se bloquee.
¿Hay alguna solución para tal vez esto en trozos?
var encrypted = convertUint8ArrayToWordArray(mergedArray) function convertUint8ArrayToWordArray(u8Array) { var words = [], i = 0, len = u8Array.length; while (i < len) { words.push( (u8Array[i++] << 24) | (u8Array[i++] << 16) | (u8Array[i++] << 8) | (u8Array[i++]) ); } return { sigBytes: words.length * 4, words: words }; }Si la ventana de su navegador se congela, puede procesar la matriz de forma asíncrona en lotes. He puesto el ejemplo en un fragmento
function pause() { return new Promise(r => setTimeout(r, 0)) } async function convertUint8ArrayToWordArray(u8Array) { var words = [], i = 0, len = u8Array.length; while (i < len) { words.push( (u8Array[i++] << 24) | (u8Array[i++] << 16) | (u8Array[i++] << 8) | (u8Array[i++]) ); if (i % 100000 == 0) { await pause(); } } return { sigBytes: words.length * 4, words: words }; } const bigArray = new Uint8Array(224337596); for (let idx = 0; idx < bigArray.length; ++idx) { bigArray[idx] = Math.floor(Math.random() * 256); } convertUint8ArrayToWordArray(bigArray).then((res) => { console.log(res.words[0]) });