W3C home > Mailing lists > Public > whatwg@whatwg.org > March 2012

[whatwg] API for encoding/decoding ArrayBuffers into text

From: Glenn Maynard <glenn@zewt.org>
Date: Tue, 13 Mar 2012 18:11:33 -0500
Message-ID: <CABirCh9hZqqP2XO-dRXSZbz83POnWLaRn0H3+bwbzzDaiP-J0w@mail.gmail.com>
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.

Glenn Maynard
Received on Tuesday, 13 March 2012 16:11:33 UTC

This archive was generated by hypermail 2.4.0 : Wednesday, 22 January 2020 16:59:40 UTC