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

259
Views
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
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!