forked from omerjerk/RemoteDroid_web
-
Notifications
You must be signed in to change notification settings - Fork 0
/
stream.js
33 lines (29 loc) · 821 Bytes
/
stream.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
'use strict';
var Stream = (function stream() {
function constructor(url) {
this.url = url;
}
constructor.prototype = {
readAll: function(progress, complete) {
var xhr = new XMLHttpRequest();
var async = true;
xhr.open("GET", this.url, async);
xhr.responseType = "arraybuffer";
if (progress) {
xhr.onprogress = function (event) {
progress(xhr.response, event.loaded, event.total);
};
}
xhr.onreadystatechange = function (event) {
if (xhr.readyState === 4) {
complete(xhr.response);
// var byteArray = new Uint8Array(xhr.response);
// var array = Array.prototype.slice.apply(byteArray);
// complete(array);
}
}
xhr.send(null);
}
};
return constructor;
})();