Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

179
Views
Convert large byteArray to wordArray

I need to convert a large array (Uint8Array(224337596)) inside my code. Apparently the size is to big and makes the browser crash.

Is there any workaround to maybe to this in chunks?

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
    };
}
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

If your browser window freezes, than you can process the array asynchronously in batches. I've put the example into snippet

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])
});

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!