W3C home > Mailing lists > Public > whatwg@whatwg.org > August 2013

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

From: Tab Atkins Jr. <jackalmage@gmail.com>
Date: Mon, 5 Aug 2013 13:30:21 -0700
Message-ID: <CAAWBYDAdFASoyV6fv3bQ1hohqfhoXypjc569p5Yx-LHf0b6+JA@mail.gmail.com>
To: Simon Pieters <simonp@opera.com>
Cc: WHATWG List <whatwg@whatwg.org>, Chang Shu <cshu01@gmail.com>
On Mon, Aug 5, 2013 at 12:41 PM, Simon Pieters <simonp@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.

~TJ
Received on Monday, 5 August 2013 20:31:06 UTC

This archive was generated by hypermail 2.3.1 : Monday, 13 April 2015 23:09:23 UTC