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

[whatwg] API for encoding/decoding ArrayBuffers into text

From: Jonas Sicking <jonas@sicking.cc>
Date: Mon, 26 Mar 2012 17:33:56 -0700
Message-ID: <CA+c2ei-XbMpKgQS5PArdYPASc4kqD=yuvMYj4cnt1ZAmAUAFMw@mail.gmail.com>
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
Received on Monday, 26 March 2012 17:33:56 UTC

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