[whatwg] File API Streaming Blobs

Glenn Maynard glenn at zewt.org
Fri Jan 21 12:50:34 PST 2011

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

More information about the whatwg mailing list