[whatwg] API for encoding/decoding ArrayBuffers into text
Cedric Vivier
cedricv at neonux.com
Wed Mar 14 01:14:04 PDT 2012
Hi,
On Wed, Mar 14, 2012 at 06:49, Jonas Sicking <jonas at sicking.cc> wrote:
> Something that has come up a couple of times with content authors
> lately has been the desire to convert an ArrayBuffer (or part thereof)
> into a decoded string. Similarly being able to encode a string into an
> ArrayBuffer (or part thereof).
What are the 'late' use cases for this?
The question might sound naive, but to me the encoding/decoding would
have been really great to have during the time when we didn't have
support for ArrayBuffers in general input/output APIs like we have now
(XHR, WebSockets, File API, ...) - which sounds like the mainstream
use cases to me.
However there is one use case that is not supported that sounds
something worthy not to overlook imho : embedding of binary data
(typed arrays) into textual formats such as XML or JSON.
For this, base64 encoding/decoding is typically used (so that it
doesn't conflict with the XML or JSON container) and thus more or less
efficiently implemented in JavaScript (just like we had to
encode/decode strings in JS to/from XHR a while ago).
Would it make sense to support encoding="base64" in this API?
> Something as simple as
>
> DOMString decode(ArrayBufferView source, DOMString encoding);
> ArrayBufferView encode(DOMString source, DOMString encoding,
> [optional] ArrayBufferView destination);
This API proposal looks lean and mean.
I hope we can move the current StringEncoding proposal to something
closer to this.
Regards,
More information about the whatwg
mailing list