Suggest javascript string as ISO-8859 encoded downloadable blob

I am working on an application to simplify the task of working with CSV files. All CSV files are encoded in ISO-8859-15, and I can’t change this because they are exported from the tool and after starting my javascript web application they need to be re-imported.

I download CSV using FileReaderJS http://bgrins.github.com/filereader.js/ , which I expanded to provide readAsText correct encoding, thus converting input to a UTF-8 string.

Now I am modifying the line obtained from the downloaded CSV and want to offer the result (in the content variable) as the load using FileSaver https://github.com/eligrey/FileSaver.js using this code:

 var bb = new BlobBuilder(); bb.append(content); saveAs(bb.getBlob("text/plain;charset=iso-8859-15"),"export.csv"); 

When the file arrives on my machine, it still remains UTF-8. I believe that I will probably have to convert the UTF-8 string to the iso-8859-15 encoding - this is not a problem since I do not require any non-iso-8859 characters, but I have no idea how . I briefly reviewed http://www.webtoolkit.info/demo/javascript-utf-8 , but that did not help me.

Does anyone know how to make this work?

+4
source share

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


All Articles