You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This package would be much helper if it abstracts away utf8's BOM handling. Currently reading fails for files encoded in utf8 (JSON.parse throws "Unexpected symbol" at BOM).
Grunt's file module can solve this problem (see below). Why not to reimplement the similar approach here?
file.read = function(filepath, options) {
if (!options) { options = {}; }
var contents;
grunt.verbose.write('Reading ' + filepath + '...');
try {
contents = fs.readFileSync(String(filepath));
// If encoding is not explicitly null, convert from encoded buffer to a
// string. If no encoding was specified, use the default.
if (options.encoding !== null) {
contents = iconv.decode(contents, options.encoding || file.defaultEncoding);
// Strip any BOM that might exist.
if (!file.preserveBOM && contents.charCodeAt(0) === 0xFEFF) {
contents = contents.substring(1);
}
}
grunt.verbose.ok();
return contents;
} catch(e) {
grunt.verbose.error();
throw grunt.util.error('Unable to read "' + filepath + '" file (Error code: ' + e.code + ').', e);
}
};
The text was updated successfully, but these errors were encountered:
jprichardson
changed the title
Reading of UTF8-encoded files fails
Reading of UTF8-encoded (w/ BOM) files fails
May 13, 2016
Hmm. It's recommended that in UTF8, there shouldn't be a BOM, but I realize that's not always the case. I'd accept a PR to strip the BOM. However, in writing a JSON file, it's not necessary.
This package would be much helper if it abstracts away utf8's BOM handling. Currently reading fails for files encoded in utf8 (
JSON.parse
throws "Unexpected symbol" at BOM).Grunt's file module can solve this problem (see below). Why not to reimplement the similar approach here?
The text was updated successfully, but these errors were encountered: