Don't encourage binary string use #496

Closed
opened 2016-11-10 14:43:00 +00:00 by jimmywarting · 2 comments
jimmywarting commented 2016-11-10 14:43:00 +00:00 (Migrated from github.com)

as stated: https://developer.mozilla.org/en-US/docs/Web/API/FileReader/readAsBinaryString

This feature is non-standard and is not on a standards track. Do not use it on production sites facing the Web: it will not work for every user. There may also be large incompatibilities between implementations and the behavior may change in the future.

This method has been removed from the FileAPI standard. FileReader.readAsArrayBuffer() should be used instead.

It's not even supported in IE10

Javascript is bad at handling binary strings. One character is a 16-bit so it means a binary string can take up to 2x more memory since it's not in utf-8

What you should do in the readme is changing the examples to use arrayBuffer/typed arrays or just accept plain blob objects

as stated: https://developer.mozilla.org/en-US/docs/Web/API/FileReader/readAsBinaryString > This feature is non-standard and is not on a standards track. Do not use it on production sites facing the Web: it will not work for every user. There may also be large incompatibilities between implementations and the behavior may change in the future. > > This method has been removed from the FileAPI standard. FileReader.readAsArrayBuffer() should be used instead. It's not even supported in IE10 Javascript is bad at handling binary strings. One character is a 16-bit so it means a binary string can take up to 2x more memory since it's not in utf-8 What you should do in the readme is changing the examples to use arrayBuffer/typed arrays or just accept plain blob objects
reviewher commented 2017-01-09 23:48:34 +00:00 (Migrated from github.com)

@jimmywarting @miclill there was probably a reason for preferring readAsBinaryString, most likely performance. The demo supports both modes.

One character is a 16-bit so it means a binary string can take up to 2x more memory since it's not in utf-8

The binary string is a direct mapping of bytes (if s is the string, s.charCodeAt(i) is the i-th byte), so UTF8 conversion is not involved. The string length will be the exact byte size of the uploaded file.

What you should do in the readme is changing the examples to use arrayBuffer/typed arrays or just accept plain blob objects

I agree that it would be helpful to add more examples like the readAsArrayBuffer form.

@jimmywarting @miclill there was probably a reason for preferring readAsBinaryString, most likely performance. The demo supports both modes. > One character is a 16-bit so it means a binary string can take up to 2x more memory since it's not in utf-8 The binary string is a direct mapping of bytes (if `s` is the string, `s.charCodeAt(i)` is the `i`-th byte), so UTF8 conversion is not involved. The string length will be the exact byte size of the uploaded file. > What you should do in the readme is changing the examples to use arrayBuffer/typed arrays or just accept plain blob objects I agree that it would be helpful to add more examples like the readAsArrayBuffer form.
SheetJSDev commented 2017-01-10 00:22:36 +00:00 (Migrated from github.com)

I have a 2010 tutorial that used readAsBinaryString in my bookmarks. When we added readAsArrayBuffer support, rABS was noticeably faster.

I have [a 2010 tutorial that used readAsBinaryString](https://www.html5rocks.com/en/tutorials/file/dndfiles/) in my bookmarks. When we added readAsArrayBuffer support, rABS was noticeably faster.
Sign in to join this conversation.
No Milestone
No Assignees
1 Participants
Notifications
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Dependencies

No dependencies set.

Reference: sheetjs/sheetjs#496
No description provided.