Re: String to ArrayBuffer

On 1/11/2012 7:44 PM, Charles Pritchard wrote:
> On 1/11/2012 4:22 PM, Boris Zbarsky wrote:
>> On 1/11/12 6:03 PM, Charles Pritchard wrote:
>>> Web Storage, also, only works with unicode.
>>
>> I'm not familiar with the relevant part of Web Storage.  Can you cite 
>> the relevant part please?
>
> The character code conversion gets weird. If you'd explain this in the 
> proper terms, I'd appreciate it.
>
> Load a binary resource via the old charset hack.
>
> Save the resulting string into localStorage. There are some conversion 
> issues. I am not using the right vocabulary.
> I know the list has seen the issue before, and I'll bet someone here 
> can explain it succinctly.
>
> Example:
> // Image files are easiest to try this with.
> https://developer.mozilla.org/En/XMLHttpRequest/Using_XMLHttpRequest#Receiving_binary_data_in_older_browsers 
>
> // From the article:
> function load_binary_resource(url) {
>   var req = new XMLHttpRequest();
>   req.open('GET', url, false);
>   //XHR binary charset opt by Marcus Granado 2006 
> [http://mgran.blogspot.com]
>   req.overrideMimeType('text\/plain; charset=x-user-defined');
>   req.send(null);
>   if (req.status != 200) return '';
>   return req.responseText;
> }
> var x = load_binary_resource('imageurl.png');
> localStorage.fail = x;
> localStorage.fail == x.fail; // will return false.
>

I'm sorry, I'm just digging myself in a hole with this one. First, that 
should be localStorage.fail == x;

Second, it seems to be working fine in my console. I know that I had 
some heavy issues with the technique last year.
There are many posts on the Net talking about base64 encoding binary 
before putting it into Web Storage.

But, more importantly, this thread is being resolved via the 
StringEncoding API for Typed Arrays.

I'm not sure what the plan is for Blob storage with IndexedDB; other 
than it's a v2 consideration.

Anyway, sorry for the confusion. If I do come across an old thread or 
explanation of the issue, I'll post it.
I'm certain there were issues with storing arbitrary binary in 
localStorage in prior versions of browsers.


-Charles

Received on Thursday, 12 January 2012 04:03:47 UTC