[whatwg] API for encoding/decoding ArrayBuffers into text

On Wed, 21 Mar 2012 01:27:47 -0700, Jonas Sicking <jonas at sicking.cc> wrote:
> This leaves us with 2 or 3. So the question is if we should support
> streaming or not. I suspect doing so would be worth it.

For XMLHttpRequest it might be, yes.

I think we should expose the same encoding set throughout the platform.  
One reason to limit the encoding set initially might be because we have  
not all converged yet on our encoding sets. Gecko, Safari, and Internet  
Explorer expose a lot more encodings than Opera and Chrome.

As for the API, how about:

   enc = new Encoder("euc-kr")
   string1 = enc.encode(bytes1)
   string2 = enc.encode(bytes2)
   string3 = enc.eof() // might return empty string if all is fine

And similarly you would have

   dec = new Decoder("shift_jis")
   bytes = dec.decode(string)

Or alternatively you could have a single object that exposes both encode()  
and decode() and tracks state for both:

   enc = new Encoding("gb18030")
   bytes1  = enc.decode(string1)
   string2 = enc.encode(bytes2)


-- 
Anne van Kesteren
http://annevankesteren.nl/

Received on Wednesday, 21 March 2012 12:42:37 UTC