Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

237
Visualizações
javascript base64 from FileReader stores in disk instead of memory?

I noticed that base64 generated from FileReader takes vary few memory space.

<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>

<body>
  <input type="file" multiple>
  <div id="img-container"></div>
  <script>

    b64arr = []
    function blobToDataURL(blob) {
      return new Promise((resolve, reject) => {
        let reader = new FileReader();
        reader.onload = function () {
          resolve(reader.result);
        }
        reader.onerror = function () {
          reject();
        }
        reader.readAsDataURL(blob);
      })
    }


    function getObjectUrl(blob) {
      return URL.createObjectURL(blob)
    }

    var fileEle = document.querySelector('input[type=file]');
    fileEle.onchange = function (e) {
      var files = e.target.files;
      Array.from(files).forEach(blob => {
        blobToDataURL(blob).then(b64 => {
          b64arr.push(b64.replace(/^data:image\/\w+;base64,/, ""))

          document.getElementById('img-container').innerHTML += `<img src="${b64}" style="height:200px" alt="">`
        })
      })
    };
    window.testArr = ['your long base64 string here']
  </script>
</body>

</html>

I take a memory snapshot and find testArr and b64arr memory shots differently,even if i call splice on base64 string on FileReader results: size shot of testArr, size shot of b64arr

Retained Size of testArr looks normal, but b64arr takes only 296 bytes(Actually 4 images of 11M+) So why does this happen? And is there any reference about this behavior?

about 4 years ago · Juan Pablo Isaza
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda