[whatwg] File API Streaming Blobs

Adam Malcontenti-Wilson adman.com at gmail.com
Fri Jan 21 12:35:53 PST 2011

XHR2 is one part of the APIs required for my use case as that is the
easiest way to download for example a music file. However, while
downloading, there's no way to pipe the download(ing) blob to the
HTML5 Audio element as to play Audio it requires an object URL, and an
object URL can (currently) only point to a static Blob, as well as the
fact that a Blob cannot be appended. This would be important for
listening streaming audio that needs to be processed in JavaScript or
cached to persistant storage using the Filesystem APIs without having
to wait for the entire file to be downloaded into an ArrayBuffer or

I'm not really sure about the <device> tag fitting in with this as it
seems to be more about reading serial ports and cameras from what I've
seen, however any streaming interface that could be specified could be
also used in the device API to stream binary content to devices.

My suggestion was for another alternative version of Blob and/or
createObjectUrl that mimicks how a HTTP request can be parsed and (in
the case of audio or video) start playing before it has finished
downloading (e.g. got to the content-length or had a connection close)
by pushing content when it is appended to the blob and then the
"virtual connection" can be closed when the Blob has finished being
built by calling a close() function. I've also thought of other
alternatives, but I'd make sure that there isn't already a way to do
this with the current (specified) APIs, and I think this has the most
other use cases as any data that takes a while to process can be
streamed to the user or other parts of the browser.

Adam Malcontenti-Wilson

On Sat, Jan 22, 2011 at 5:55 AM, David Flanagan <david at davidflanagan.com> wrote:
> Doesn't the current XHR2 spec address this use case?
> Browsers don't seem to implement it yet, but shouldn't something like this
> work for the original poster?
>        x = new XMLHttpRequest()
>        x.open("GET", "http://my-media-file");
>        x.responseType = "blob";
>        x.send();
>        var nbytes = 0;
>        x.onprogress = function(e) {
>           var blob = x.response.slice(nbytes, e.loaded-nbytes);
>           nbytes += blob.size;
>           var reader = new FileReader();
>           reader.readAsArrayBuffer(blob, function() {
>               // process blob content here
>            });
>        }
>    David Flanagan
> On 01/21/2011 02:02 AM, Jeremy Orlow wrote:
>> Would something like this tie in to the<device>  work that's being done
>> maybe?
>> ---------- Forwarded message ----------
>> From: Adam Malcontenti-Wilson<adman.com at gmail.com>
>> Date: Fri, Jan 21, 2011 at 6:21 AM
>> Subject: [chromium-html5] File API Streaming Blobs
>> To: Chromium HTML5<chromium-html5 at chromium.org>
>> Hi.
>> I'm trying to make an application which will download media files from
>> a server and cache them locally, as well as playing them back but I'm
>> trying to figure out how I could do so without making the user wait
>> for the entire file to be downloaded, converted to a blob, then
>> saved.
>> For example, suppose that I create a new BlobBuilder, append "hello",
>> get the Blob, and then create an object url from that blob, and then
>> open the object url. Any other text that I append to the BlobBuilder
>> would not go into the old blob that I created a url for, and hence not
>> shown making "streaming" impossible.
>> Is there any other methods in the spec(s) to implement such
>> streaming?
>> If not, perhaps there needs to be yet another object to have a way of
>> creating a "StreamingBlob" that doesn't "close" the virtual connection
>> to the browser until a close method is called, thereby facilitating
>> streaming.
>> Thanks,

Adam Malcontenti-Wilson

More information about the whatwg mailing list