[whatwg] BinaryEncoding for Typed Arrays using window.btoa and window.atob

Tab Atkins Jr. jackalmage at gmail.com
Mon Aug 5 13:30:21 PDT 2013

On Mon, Aug 5, 2013 at 12:41 PM, Simon Pieters <simonp at opera.com> wrote:
>> var newarr = new Int32Array();
>> window.atob(encodedData, newarr); //decode base-64 string back to integer
>> array
>> //newarr[0] should be 1, newarr[1] should be 2 and newarr[2] should be 3.
> Is there a reason to support an arbitrary typed array for atob rather than
> returning a new typed array?
> e.g.
> var newarr = atob(encodedData, {typedarray:true});
> (I'm not sure which view is most appropriate to return.)

Decoding into a given typed array means you can reuse the same
(potentially large) buffer multiple times, rather than creating new
ones with every call.  Avoiding the GC churn can be significant.  It
also means you can decode several strings into the same typed array at
different offsets.


More information about the whatwg mailing list