Can't fit file encoding when working with Chrome File System API

后端 未结 1 598
忘掉有多难
忘掉有多难 2021-01-23 12:57

I need to read a file which contains a group of symbols moved 65 in ASCII table. It means, for each symbol I am meant to do:

String.fromCharCode(\'¢\'.charCodeA         


        
相关标签:
1条回答
  • 2021-01-23 13:30

    Problem is, your shifted text is no longer text by readAsText criteria. Trying to read it with any standard codepage is not going to work.

    You should read the file as binary with readAsArrayBuffer(), interpret it as unsigned 8-bit int array, shift the bytes, and then convert the result to string.

    var buf = new Uint8Array(reader.readAsArrayBuffer(file));
    buf = buf.map((byte) => byte-65);
    var string = new TextDecoder("ascii").decode(buf);
    
    0 讨论(0)
提交回复
热议问题