[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").Â