Cannot customize file encoding when working with Chrome file system API

I need to read a file containing a group of characters moved in an ASCII 65 table. This means that for each character I have to do:

String.fromCharCode('Β’'.charCodeAt(0)-65) // returns 'a'

But it doesn’t work at all. I asked my friends to do a test using Python by entering the same file, and they got the correct result.

When I try to do the same job with the Chrome file system, it doesn't work at all. I cannot return the expected characters. I think this is a problem with my encoding / encoding board, but I cannot figure out what and how to fix it.

I tried to open the file with a different encoding:

var reader=new FileReader();

reader.readAsText(file, 'windows-1252'); // no success
reader.readAsText(file, 'ISO-8859-2'); // no success

Appreciate any help

+1
source share
1

, readAsText. .

readAsArrayBuffer(), 8- int, .

var buf = new Uint8Array(reader.readAsArrayBuffer(file));
buf = buf.map((byte) => byte-65);
var string = new TextDecoder("ascii").decode(buf);
+2

Source: https://habr.com/ru/post/1661869/


All Articles