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

136
Visualizações
JavaScript Blob.size Browser Inconsistency

I have a JavaScript string which consists of 2048 common characters. I use the following Node.js code to find its size in bytes.

Buffer.from("the long string...").length

This returns the number 2048, which happens to be equal to the length of the string. I am using the Node.js function as my benchmark, so I view this as its actual size in bytes.

On the client side, I use Blob to determine the size of the string.

new Blob(["the long string..."], {type: "text/plain"}).size

This should return exactly the same value as the Node.js code. I tested it on a Linux Firefox browser and it returned 2048, which is good. I tested it on a Windows Firefox browser and it returned 2046, which is not what I was hoping for.

I cannot replicate this issue consistently; some strings produce the same result, and others produce conflicting results. This is a problem that needs solving because the application that I'm building relies on the browser and the server to calculate the size of a string in bytes.

How can I consistently get the byte size in both the server and the browser?

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