[whatwg] API for encoding/decoding ArrayBuffers into text

Joshua Bell jsbell at chromium.org
Fri Mar 16 14:12:16 PDT 2012

On Fri, Mar 16, 2012 at 10:35 AM, Glenn Maynard <glenn at zewt.org> wrote:

> On Fri, Mar 16, 2012 at 11:19 AM, Joshua Bell <jsbell at chromium.org> wrote:
> ... where output === view if view is supplied, otherwise a new Uint8Array
>> (or Uint8ClampedArray??)
> Uint8Array is correct.  (Uint8ClampedArray is for image color data.)
> If UTF-16 or UTF-32 are supported, decoding to them should return
> Uint16Array and Uint32Array, respectively (with the return value being
> typed just to ArrayBufferView).

FYI, there was some follow up IRC conversation on this. With Typed Arrays
as currently specified - that is, that Uint16Array has platform endianness
- the above would imply that either platform endianness dictated the output
byte sequence (and le/be was ignored), or that encode("\uFFFD",
"utf-16").view[0] might != 0xFFFD on some platforms.

There was consensus (among the two of us) that the output view's underlying
buffer's byte order would be le/be depending on the selected encoding.
There is not consensus over what the return view type should be -
Uint8Array, or pursue BE/LE variants of Uint16Array to conceal platform

More information about the whatwg mailing list