0

I am trying to read a excel file and create one locally. I have the below code

(async function () {
  const fetchPromise = fetch(url);
  let stream = await fetchPromise;
  let reader = stream.body.getReader();
  let decoder = new TextDecoder();
  while(true) {
    const {done, value} = await reader.read();
    if (done){
      break;
    }
    let res = decoder.decode(value, {stream: true, ignoreBOM: false});
    console.log(res);
  }
})();

I am seeing garbled characters when printing value of variable res.

when i execute file -I on the source file i am trying to read + create locally i see

count-3.xlsx: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet; charset=binary

What encoding scheme should i be passing to TextDecoder so i do not see garbled characters?

opensource-developer
  • 2,826
  • 4
  • 38
  • 88
  • Have you tried writing it to an actual file and seeing if it opens in excel? Because if you open a normal .xlsx file in a text editor, you will see 'garbled characters' or some form of binary code or hex bytes or something, it won't look like readable text – TKoL Dec 10 '20 at 10:27
  • @TKoL, yes i tried to write, but when i open the file i appears corrupt. – opensource-developer Dec 10 '20 at 11:28

0 Answers0