It appears that the string should be "UTF-8". However, this also causes the error above and does not work.
So, it looks like the default in FileReader.readAsText should be "utf8" and not "UTF-8"
It might also be worth considering create a class with constants for the major encoding types to make it less likely developers run into this, and to make it easier for us to change the encoding names in the future in case the underlying implementation changes.
Issue by mikechambers Wednesday May 09, 2012 at 18:38 GMT Originally opened as https://github.com/adobe/brackets/issues/848
In NativeFileSyste.FileReader.prototype.readAsText, is the user does not specify an encoding argument, the default is set to:
"utf-8"
If you try and load a UTF 8 Encoded file using this, you will get a SECURITY_ERR (which is actually an ENCODING_ERR).
If you change the default to "utf8" or, pass in an encoding of "utf8" then everything works fine.
If you look inside of FileUtils.js, "utf8" is used.
Looking at the HTML5 FileSystem specification:
http://dev.w3.org/2006/webapi/FileAPI/#encoding-determination
Say encoding names are specified as "a character set used on the Internet [IANACHARSET]".
Looking at the IANA Charsets:
http://www.iana.org/assignments/character-sets
It appears that the string should be "UTF-8". However, this also causes the error above and does not work.
So, it looks like the default in FileReader.readAsText should be "utf8" and not "UTF-8"
It might also be worth considering create a class with constants for the major encoding types to make it less likely developers run into this, and to make it easier for us to change the encoding names in the future in case the underlying implementation changes.