W3C home > Mailing lists > Public > public-webapps@w3.org > July to September 2012

RE: Lazy Blob

From: Jungkee Song <jungkee.song@samsung.com>
Date: Tue, 07 Aug 2012 18:07:23 +0900
To: 'Glenn Maynard' <glenn@zewt.org>
Cc: 'WebApps WG' <public-webapps@w3.org>, 'Robin Berjon' <robin@berjon.com>
Message-id: <00cf01cd747c$0f1d2f30$2d578d90$%song@samsung.com>
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 GMT

This archive was generated by hypermail 2.3.1 : Tuesday, 26 March 2013 18:49:54 GMT