filereader.js
filereader.js copied to clipboard
Text file encoding support (UTF8 / ANSI)
Superb plugin! Please, if possible, add text file encodind option for reading the file contents.
OK so you would need a way to hook into the arguments passed into readAsText 0. Do you want to switch the encoding per-file or globally? This option could be added as a global configuration value, or could be attached onto the file object in the onbeforestart callback.
It would be nice to have a feature to "autodiscover" the encoding of text files (ANSI/UTF-8). But it could be a parameter as you suggested.
var FileReaderOptions = { readAsDefault: "Text", encoding: "ANSI", // or "UTF-8" on: { load: function(e, file) { loadPlainText(e.target.result); } } } FileReaderJS.setupDrop($('#dropper').get(0), FileReaderOptions);
Thanks
Seems good, with the caveat that the default for encoding
should be undefined
(so that we keep spec behavior for people who don't specify an option). I'm not going to be able to implement this at the moment, but I'd be happy to accept a PR.
Regarding auto discovery, this would be even better but I don't know of any way to do that with the current API - the encoding must be specified as the second parameter to readAsText
I tried this: http://jsfromhell.com/geral/utf-8
It didn't work for me.
I'd like to contribute. However I'm confused how github works. I don't know how to contribute.
Is there a way to switch between ANSI/UTF-8 as suggested here? https://developer.mozilla.org/en-US/docs/Web/API/FileReader/readAsText
I'd like to contribute. However I'm confused how github works. I don't know how to contribute.
You can fork the repository and then make the changes locally and create a pull request.
Is there a way to switch between ANSI/UTF-8 as suggested here?
Around this line you could add something like:
var readAsOptions = undefined;
if (readAs === "readAsText") {
readAsOptions = whatever encoding;
}
reader[readAs](file, readAsOptions);