fetch-readablestream icon indicating copy to clipboard operation
fetch-readablestream copied to clipboard

Add Support for ms-stream

Open jonnyreeves opened this issue 8 years ago • 4 comments

See https://github.com/jonnyreeves/chunked-request/issues/10 for context and research.

jonnyreeves avatar Sep 21 '16 15:09 jonnyreeves

Sitting on a mac and don't have windows... But I think it's something like this:

var xhr = new XMLHttpRequest

function readyStateCallback() {
    if (xhr.readyState == 3) {
        var msstream = xhr.response // MSStream object

        var reader = new MSStreamReader()
        reader.onprogress = function () {
            console.log(reader.result) // need to slice it (it expands)
            // enqueue chunk (Uint8Array) to ReadableStream
        }
        reader.onload = function () {
            console.log(reader.result)
            // Done, close stream?
        }

        reader.readAsArrayBuffer(msstream)
    }
}

xhr.open('GET', 'http://myserver/myfile')
xhr.responseType = 'ms-stream'
xhr.onreadystatechange = readyStateCallback
xhr.send(null)

jimmywarting avatar Sep 24 '16 20:09 jimmywarting

I decided to investigate this further today and manage to get a ms-stream and convert it to a ReadableStream. and then i found this:

/* Notice: ms-stream may cause IE/Edge browser crash if seek too frequently!!!
 * The browser may crash in wininet.dll. Disable for now.
 *
 * For IE11/Edge browser by microsoft which supports `xhr.responseType = 'ms-stream'`
 * Notice that ms-stream API sucks. The buffer is always expanding along with downloading.
 *
 * We need to abort the xhr if buffer size exceeded limit size (e.g. 16 MiB), then do reconnect.
 * in order to release previous ArrayBuffer to avoid memory leak
 *
 * Otherwise, the ArrayBuffer will increase to a terrible size that equals final file size.
 */

src: https://github.com/6600/flvPlay/blob/aa8159a8fbc2cb85465503b97fb1c50880b6db10/src/io/xhr-msstream-loader.js

So i guess the best thing to do is partial download... :(

jimmywarting avatar Feb 23 '17 09:02 jimmywarting

@jimmywarting once detached you gotta use AsStreamForRead.

Mouvedia avatar Jul 26 '18 12:07 Mouvedia

It seems, MSStreamReader also does not fire progress events for every small chunk of data

Yaffle avatar Feb 09 '20 13:02 Yaffle