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

254
Visualizações
How can I get the file encoding format with Js

When I use readAsText(file,'utf-8'), I ran into a problem. Because I use the utf8 format to parse the file, when the user file is not in utf8 encoding format, the parsing result is likely to be wrong. How can I use Js to get the encoding format of the user file to remind the user to upload the utf8 file? Under Windows, I judge whether the first 3 bytes of the file are BOM, but Mac will not add BOM to utf8 files, so can anyone help? thank you very much

const encodeReader = new FileReader();
encodeReader.onload = function (e) {
  const view = new Uint8Array(e.target.result as ArrayBuffer);
  let zwsp = "";
  for (const num of view) {
    zwsp += num.toString(16);
  }
  if (zwsp.toUpperCase() === "EFBBBF") {
    console.log("it is utf-8");
  }
};
encodeReader.readAsArrayBuffer(file.slice(0, 3));

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