[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Public WebGL] Typed Arrays & Strings

On Thu, Jul 1, 2010 at 10:18 AM, Vladimir Vukicevic <vladimir@mozilla.com> wrote:
One thing that's not quite clear to me, though... I understand that being able to do string charset conversions would be useful.  What I don't understand is the desire to do arbitrary binary string to UTF8-in-UInt8Array conversion and vice versa.  Is it possible to just ship raw byte arrays (ArrayBuffer) down across the wire, through XHR/WebSockets instead?  Seems much simpler/faster and less error prone than doing charset conversions on binary data.

The specific scenarios I am interested in both consuming and producing (from JS):
It sounds like Ryan is interested in the latter.

On Thu, Jul 1, 2010 at 4:11 AM, Chris Marrin <cmarrin@apple.com> wrote:
It does seem reasonable to have toDataURL() and fromDataURL() in the TypedArray base class, like Canvas 2D has. I'm not sure why we haven't discussed it before.

I like this suggestion:

// binary -> base64 JS string:
mybuf.toDataURL() // "data:application/octet-stream;base64,AwEEAQUJAgY="

// base64 JS string --> arraybuf:
mybuf = ArrayBuffer.fromDataURL("data:application/octet-stream;base64,AwEEAQUJAgY=")

... but it's unclear to me how you might use this approach for getting UTF-8 data embedded in an ArrayBuffer back out to a JS string. 

This inspired me to look again at the File API draft http://dev.w3.org/2006/webapi/FileAPI since the Blob type therein is a more direct match for something which should consume/produce data URIs. It does temptingly offer similar services, but the usage of those for these scenarios seems limited and convoluted: e.g. pull the content down as a Blob via XHR, read it (asynchronously) via a BlobReader as an ArrayBuffer via readAsArrayBuffer(); on receipt, parse it, determine the subrange which is e.g. a UTF-8 string, construct another BlobReader on it and read it (async again!) using readAsText(subblob, "UTF-8").