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

Chang Shu cshu01 at gmail.com
Mon Aug 5 13:39:22 PDT 2013


I see your point now, Simon. Technically both approaches should work.
As you said, yours has the limitation that the implementation does not
know which view to return unless you provide an enum type of parameter
instead of boolean to atob. And mine has the performance issue. How
about we don't return the 'binary' string in case the 2nd parameter is
provided in my case?

Thanks


On Mon, Aug 5, 2013 at 4:22 PM, Simon Pieters <simonp at opera.com> wrote:
>> On Mon, Aug 5, 2013 at 3:41 PM, Simon Pieters <simonp at opera.com> wrote:
>>
>>> 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.)
>>>
>
> On Mon, 05 Aug 2013 21:50:39 +0200, Chang Shu <cshu01 at gmail.com> wrote:
>
>> Thanks for the comments, Simon. The reason I put the return result as
>> a second (optional) parameter of atob is for backward compatibility.
>> User can still call:
>> var rtn = atob(Base64EncodedData);
>> and rtn would be a 'binary' string.
>> If user calls:
>> var rtn = atob(Base64EncodedData, arrayBufferView);
>> arrayView would be filled with data and rtn is also a parsed 'binary'
>> string. I think the native implementation can detect what type of
>> ArrayBufferView arrayBufferView is.
>
>
> I think you misunderstood my question.
>
> I understand that
>
>     var rtn = atob(Base64EncodedData);
>
> still needs to work for backwards compabitility. But that doesn't explain
> why
>
>
>     var rtn = atob(Base64EncodedData, arrayBufferView);
>
> is better than
>
>
>     var newarr = atob(encodedData, {typedarray:true});
>
> Your suggestion to both return a 'binary' string and to fill in the typed
> array provided in the second argument seems like it would have bad
> performance compared to only filling in or returning a typed array.
>
>
> --
> Simon Pieters
> Opera Software



More information about the whatwg mailing list