RE: Lazy Blob

Hi Glenn,

> > var xhr = new XMLHttpRequest();
> > xhr.open("GET", "resource.jpg");
> > var urlObject = xhr.getURLObject();
> > var newURL = URL.getObjectURL(urlObject);
> > img.src = newURL;

It's neat and I like the idea, too. However, there is a reason that I prefer
our blob approaches:

> > === Another XHR Approach
> >
> > partial interface XMLHttpRequest {
> >    Blob makeLazyBlob ();
> > };
> >
> > Usage:

[Service]
> > var xhr = new XMLHttpRequest();
> > xhr.open("GET", "/kitten.png", true);
> > xhr.setRequestHeader("Authorization", "Basic DEADBEEF");
> > var blob =xhr.makeLazyBlob();

window.intent.postResult(blob);

>From totally client developer's point of view, who perhaps do not care the
underlying details at all, it is absolutely transparent to use the obtained
blob as they used to deal with. (no matter which type of data the blob
contains)

[Client]
navigator.startActivity(intent, resultOK);

function resultOK (data) {
    // *data* is a blob delivered by service end.
        it can be a few MB of image file (kitten.png in the above example)
                 or a few MB of mp3 music file
                 or a few MB of raw text file
                 or a huge binary string
                 etc.

    var blob = data;
    
    var reader = new FileReader();
    
    // developers have all the existing file reader options with no
additional concern such that they do any further operations with the result

    reader.readAsDataURL(blob);
    // or
    reader.readAsBinaryString(blob);
    // or
    reader.readAsText(blob);
    // or
    reader.readAsArrayBuffer(blob);
}


Regards,
Jungkee

Jungkee Song
Samsung Electronics

Received on Tuesday, 7 August 2012 09:07:27 UTC