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

Add readAsArrayBuffer and drop support for readAsBinaryString #45

Open
eric1234 opened this issue Jul 17, 2013 · 12 comments
Open

Add readAsArrayBuffer and drop support for readAsBinaryString #45

eric1234 opened this issue Jul 17, 2013 · 12 comments

Comments

@eric1234
Copy link
Contributor

It appears that readAsBinaryString is no longer supported by the HTML5 spec. Although implemented in some browsers (Chrome, Firefox) it will likely be removed in future releases. In addition IE10 was released late enough that they never needed to support it (but they do support readAsArrayBuffer and readAsText and readAsDataURL).

The end result of the current situation is that:

  • If I use readAsBinaryString it seems to work most places. But I get an error in IE10 (complaining about the method not existing). I imagine future version of Firefox and Webkit will behave the same.
  • If I use readAsArrayBuffer it will work on all modern browsers (including IE10) but it will not work on browsers using the flash fallback since the flash fallback doesn't provide support for readAsArrayBuffer.
  • readAsText should work everywhere. But if you plan to use interact with the data you might get issues since it will apply character encoding mojo. I don't need to interact with the data in a meaningful way (just doing a hash of some of the data) so I will probably try this one.
  • readAsDataURL also should work everywhere. But since it is base64 encoded I think it will increase the file size by 37% which could affect performance.
@eric1234
Copy link
Contributor Author

Just a quick followup related to this I figured I would note. I tried readAsText and the data returned was "nil" when using the flash fallback (IE9). But when using readAsDataURL I got what I needed on all browsers. Wasn't sure if the nil was due to the fact that I was reading binary data.

@gixo
Copy link

gixo commented Jul 23, 2013

Same issue here, we would like to see readAsArrayBuffer implemented if possible. Are there any workarounds to apply in the meantime?

@jayarjo
Copy link
Contributor

jayarjo commented Jul 23, 2013

Adding support for readAsArrayBuffer will require dramatic alterations here and there. I will definitely come to this one sooner or later, but not for current release.

@gixo
Copy link

gixo commented Jul 24, 2013

This will do for now, thanks! :)

@adcorduneanu
Copy link

no offence guys but i tried readAsArrayBuffer on IE 10.0.9200.16736 and isn't working

@jayarjo
Copy link
Contributor

jayarjo commented Dec 12, 2013

readAsArrayBuffer is not implemented yet, the temp solution was to emulate readAsBinaryString where it is not present.

@bcbirkhauser
Copy link

Any progress on this? Is there an expected release date for this functionality?

@andy250
Copy link

andy250 commented Dec 9, 2016

Any updates on this?

@jayarjo
Copy link
Contributor

jayarjo commented Dec 10, 2016

@andy250 can you describe in more detail how do you plan to use it?

readAsArrayBuffer is pointless to implement in runtimes other than HTML5 (will be slow and unusable). So the logic behind not implementing it was that if you plan to use it then you already plan to work in the environment that doesn't require moxie altogether.

@andy250
Copy link

andy250 commented Dec 10, 2016

@jayarjo I planned to use this method to read file chunk into a byte array (raw bytes from disk). Then feed this byte array to spark-md5 to calculate its md5 hash. I got it working already using browser's native FileReader and readAsArrayBuffer. The md5 hash matches the one calculated on the server. When using moxie FileReader's readAsText or readAsBinaryString I am getting different hashes (I suppose encoding issues). So my primary goal is to get raw bytes of a file chunk from disk.

I suppose there is some workaround to achieve this in other runtimes. I already thought about converting the string I got from readAsText into byte array, but again I need to know the encoding. Any suggestsions? If there is no way to achieve what I need I guess my best shot is to support md5 hashes only in html5 runtime.

BTW: why there is a problem to read raw file bytes e.g. in flash?

@jayarjo
Copy link
Contributor

jayarjo commented Dec 11, 2016

Flash doesn't allow direct access to file source until you preload the whole file in memory, which is not desirable operation in most cases. And then there's a need to pipe those bytes to and from the runtime, which basically kills all the benefit of using ArrayBuffer in first place.

You can always get hold of the native browser file object by doing file.getSource() on one produced by moxie.

@andy250
Copy link

andy250 commented Dec 11, 2016

@jayarjo Thanks. But even if I use file.getSource, then (when runtime is flash) this must be the whole file, right? So I cannot really chunk it. And how does it look in silverlight? Same restrictions and no point in using the ArrayBuffer?

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

6 participants