Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Text file encoding support (UTF8 / ANSI) #20

Open
azev opened this issue Apr 5, 2015 · 5 comments
Open

Text file encoding support (UTF8 / ANSI) #20

azev opened this issue Apr 5, 2015 · 5 comments

Comments

@azev
Copy link

azev commented Apr 5, 2015

Superb plugin!
Please, if possible, add text file encodind option for reading the file contents.

@bgrins
Copy link
Owner

bgrins commented Apr 14, 2015

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.

@azev
Copy link
Author

azev commented Apr 14, 2015

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

@bgrins
Copy link
Owner

bgrins commented Apr 14, 2015

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

@azev
Copy link
Author

azev commented Apr 14, 2015

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

@bgrins
Copy link
Owner

bgrins commented Apr 15, 2015

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);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants