[whatwg] API for encoding/decoding ArrayBuffers into text

Jonas Sicking jonas at sicking.cc
Mon Mar 26 17:33:56 PDT 2012


On Mon, Mar 26, 2012 at 4:40 PM, Joshua Bell <jsbell at chromium.org> wrote:
>> * We lost the ability to decode from a arraybuffer and see how many
>> bytes were consumed before a null-terminator was hit. One not terribly
>> elegant solution would be to add a TextDecoder.decodeWithLength method
>> which return a DOMString+length tuple.
>
> Agreed, but of course see above - there was consensus earlier in the thread
> that searching for null terminators should be done outside the API,
> therefore the caller will have the length handy already. Yes, this would be
> a big flaw since decoding at tightly packed data structure (e.g. array of
> null terminated strings w/o length) would be impossible with just the
> nullTerminator flag.

Requiring callers to find the null character first, and then use that
will require one additional pass over the encoded binary data though.
Also, if we put the API for finding the null character on the Decoder
object it doesn't seem like we're creating an API which is easier to
use, just one that has moved some of the logic from the API to every
caller.

Though I guess the best solution would be to add methods to DataView
which allows consuming an ArrayBuffer up to a null terminated point
and returns the decoded string. Potentially such a method could take a
Decoder object as argument.

/ Jonas



More information about the whatwg mailing list