Open jonnyreeves opened 8 years ago
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)
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.
*/
So i guess the best thing to do is partial download... :(
@jimmywarting once detached you gotta use AsStreamForRead
.
It seems, MSStreamReader also does not fire progress events for every small chunk of data
See https://github.com/jonnyreeves/chunked-request/issues/10 for context and research.