W3C home > Mailing lists > Public > whatwg@whatwg.org > January 2011

[whatwg] File API Streaming Blobs

From: Glenn Maynard <glenn@zewt.org>
Date: Fri, 21 Jan 2011 15:50:34 -0500
Message-ID: <AANLkTinR=xyjGp5NEh=LWN04ZT3wJcF6OZD2Phj62+Bp@mail.gmail.com>
On Fri, Jan 21, 2011 at 1:55 PM, 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
> ? ? ? ? ? ?});
>
> ? ? ? ?}

He wants to be able to stream data out, not just in.

It's tricky in practice, because there's no way for whoever's reading
the stream to block.  For example, if you're reading a 1 GB video on a
phone with 256 MB of memory, it needs to stop buffering when it's out
of memory until some data has been played and thrown away, as it would
when streaming from the network normally.  That requiests an API more
complex than simply writing to a file.

-- 
Glenn Maynard
Received on Friday, 21 January 2011 12:50:34 UTC

This archive was generated by hypermail 2.4.0 : Wednesday, 22 January 2020 16:59:29 UTC