-
-
Notifications
You must be signed in to change notification settings - Fork 8k
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
Discourage use of the FileReader #2295
Comments
The library functions support binary strings, The original reason for preferring binary strings in the browser demos is IE10 performance. "Old Habits Die Hard". We've accepted PRs that have phased out use of MDN still recommends binary strings for XMLHttpRequest: https://developer.mozilla.org/en-US/docs/Web/API/XMLHttpRequest/Sending_and_Receiving_Binary_Data#receiving_binary_data_in_older_browsers function load_binary_resource(url) {
var req = new XMLHttpRequest();
req.open('GET', url, false);
//XHR binary charset opt by Marcus Granado 2006 [http://mgran.blogspot.com]
req.overrideMimeType('text\/plain; charset=x-user-defined');
req.send(null);
if (req.status != 200) return '';
return req.responseText;
} That having been said, we'd accept PRs that phase out use of PS: the parsers already detect input type. The |
Well, IE is pretty dead now, just 0.7% marketshare worldwide. MS will stop support IE in August. MS 360 apps themself have dropped support for IE11 already. It's not only them who stop supporting IE, me and other bigger website stopped as well
Cool, i can do that, how about
Cool |
Moving the discussion to the PR |
First and formost i would like to discourage the use of
readAsBinaryString
Javascript dose not handle binary strings particular well...
fetch(url).then(res => res.text())
works well also - when in fact it dose not, ajax performs text encoding on binary strings when being fetched[6]readAsBinaryString
from the spec for a reason, so we should stop using it.Indeed, readAsBinaryString only converts the binary data into a DOMString (UTF-16). There is not much you can do from it afterward. Also, storing it as an UTF-16 string implies that it takes far more space in memory than the original data size. Add to this that strings are immutable, I guess you can see how inefficient it is to work from this. [1]
I do not know what the reason behind using a binary string is, but if you for some reason need to get some part of the chunk as a text then a better conversion would then be to use
str = new TextDecoder().decode(data.slice(0, 1024))
?The sheets are also in binary format so maybe it would be easier to parse the binary using DataView. (Using the DataView instead of Buffer would reduce the dependency on the browser build)
Now for the 2nd reason of why not to encourage the use of FileReader any more:
FileReader
. It's a old legacy API now days when there is this new Blob reading methods supported directly onto the blob[5]_buffer
property if they don't use the new read methodsIf we instead encouraged everyone to use Uint8Array instead then i think it would have a better cross platform support on Deno, NodeJS, and also in the browser. (if it's even possible to use sheetjs on the server - i don't know)
It would also make the code simpler if there is just one way do read the data instead of multiple ways to reduce the code complexity
It would also make it easier for PPl to know how to import data from ajax since it has no way of getting data as binary string
I'm willing to help with PR's if we can change any occurrence of FileReader
I could do multiple smaller PR's for each file if that is easier to review, or i could do several at once.
I could also help create some depreciation warning to the console if anyone are using the binary,
XLSX.read(data, { type: 'binary' })
syntaxI would also like to emphasize that the read method could be a tiny bit smarter if it could do auto detection based on the kind of data it is. instead of setting
{ type: 'array' }
it could instead switch based on the first argument and look if it is a ArrayBuffer or ArrayBufferView.Then it could be a tiny bit easier to just do:
The text was updated successfully, but these errors were encountered: