Loading streaming binary data with XHR ArrayBuffer

922 views
Skip to first unread message

Adam Malcontenti-Wilson

unread,
Apr 21, 2012, 9:29:03 AM4/21/12
to Chromium HTML5
Hi,
I've recently found that if you try to use the
responseType="arraybuffer" property that the response property doesn't
get populated until the actual file has finished loading, which poses
a problem when I want to try and read data from a streaming binary
source (e.g. such as a Shoutcast stream (although they may be other
similar use-cases)).
Progress events show me how much data has been downloaded but doesn't
actually allow me to access any of it (that I can see). If I don't
specify a responseType, I can use the responseText property which
shows what it has read thus far, but this is almost useless for binary
data.
Is this a bug (e.g. simply not yet implemented in any major browser),
or a lacking part of the specification? I notice that in the XHR spec,
it defines the "response entity body" as "the fragment of the entity
body of the response received so far" which means that I would have
expected it to work as I've described, but it seems not to. Have I
misinterpreted the spec in this way?

P.S. Ideally for this use-case as it is infinite streaming, XHR might
need to be extended to allow progress events to only contain the last
chunk, and discard the rest of the data instead of buffering it in
memory waiting for the end of the response to fire the load event,
however this might not be the case with other examples such as
attempting to unzip a zip file while it is still being downloaded, and
although it might be a good suggestion for future XHR work, not the
question I am asking at the moment. Also, I understand that I could
use a proxy to decode and chunk over WebSockets, but I'm asking more
about being able to do this in-browser with HTML5 rather than using
intermediate servers.

Thanks,
Adam.

Karel Tuma

unread,
Apr 25, 2012, 10:05:54 AM4/25/12
to Chromium HTML5
Hi,

Unfortunately, this is not possible with current XHR Level 2. Chunked/
progressive
arraybuffers|blobs didnt make it into the spec, however it is most
likely
going to be implemented:

http://lists.w3.org/Archives/Public/public-webapps/2011JulSep/0741.html

Currently, responseText hacks (*BAD* idea for media streaming) are
easy and it
usually works (until the process runs out of RAM, that is). For
multimedia though,
one has to do it properly, ie via NaCl wrapper
https://developers.google.com/native-client/pepper18/peppercpp/classpp_1_1_u_r_l_loader#a907697c3c268a68eb3b4ca341aea4812

NaCl can pass arraybuffers to javascript, or just share the sandboxed
filesystem where
progressively downloaded assets can be saved.

//k

On Apr 21, 3:29 pm, Adam Malcontenti-Wilson <adman....@gmail.com>
wrote:
Reply all
Reply to author
Forward
0 new messages