[whatwg] API for encoding/decoding ArrayBuffers into text
glenn at zewt.org
Tue Mar 13 16:11:33 PDT 2012
On Tue, Mar 13, 2012 at 5:49 PM, 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).
There was discussion about this before:
(I don't know why it was on the WebGL list; typed arrays are becoming
infrastructural and this doesn't seem like it belongs there, even though
ArrayBuffer was started there.)
The API on that wiki page is a reasonable start. For the same reasons that
we discussed in a recent thread (
conversion errors should use replacement (eg. U+FFFD), not throw
exceptions. The "any" arguments should be fixed. Encoding to UTF-16
should definitely not prefix a BOM, and UTF-16 having unspecified
endianness is obviously bad.
I'd also suggest that, unless there's serious, substantiated demand for
it--which I doubt--only major Unicode encodings be supported. Don't make
it easier for people to keep using legacy encodings.
> Shouldn't this just be another ArrayBufferView type with special
> semantics, like Uint8ClampedArray? DOMStringArray or some such? And/or a
> getString()/setString() method pair on DataView?
I don't think so, because retrieving the N'th decoded/reencoded character
isn't a constant-time operation.
More information about the whatwg