-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
184 lines (135 loc) · 4.75 KB
/
index.html
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
<html>
<head>
</head>
<body>
<script>
var image = window.location.hash.split('#')[1];
var CONNECTIONS = 3;
for (var i = 1; i <= CONNECTIONS; i++) {
window["b64content"+i] = "";
window["content"+i] = "";
};
// window["b64content1"] = ""
// window["b64content2"] = ""
// window["b64content3"] = ""
// window["content1"] = ""
// window["content2"] = ""
// window["content3"] = ""
length = Length(image, CONNECTIONS);
function Length(url, connections)
{
var http = new XMLHttpRequest();
http.open('HEAD', url);
http.onreadystatechange = function() {
if (this.readyState == this.DONE) {
console.log(this);
length = this.getResponseHeader('Content-Length');
// console.log(this);
get_image(url, length, connections)
}
};
http.send();
}
function get_part(url, start_index, end_index, variable_name, connections){
var xmlhttp=new XMLHttpRequest();
xmlhttp.open("GET",url,true);
// console.log("LENGTTH ="+length);
console.log("Start_part ="+start_index);
console.log("end_part ="+end_index);
xmlhttp.responseType = 'arraybuffer';
xmlhttp.setRequestHeader("Range", "bytes="+start_index+"-"+end_index);
xmlhttp.send();
xmlhttp.addEventListener("readystatechange", function () {
if (xmlhttp.readyState == xmlhttp.DONE) {
var response = new Uint8Array(xmlhttp.response)
// console.log(xmlhttp.response.length);
console.log("LENGTH of "+variable_name+" = "+response.length);
// console.log(variable_name)
window[variable_name] = response;
window["b64"+variable_name] = btoa(get_string(window[variable_name]));
// if (window['b64content1'] != "" && window['b64content2'] != "" && window['b64content3'] != ""){
for (var i = 1; i <= connections; i++) {
if (window['b64content'+i] == "")
return;
};
var final_content = ""
for (var i = 1; i <= connections; i++) {
final_content += window['b64content'+i];
};
document.getElementById("ItemPreview").src = "data:image/png;base64," + final_content;
}
});
// var something = new ArrayBuffer(xmlhttp.response)
// var view = new Int32Array(buffer);
// return new Uint8Array(xmlhttp.response)
}
function get_string(content)
{
var length = content.length
var string = ""
for(var i=0;i< length;i++)
{
string += String.fromCharCode(content[i]);
}
return string
}
var _appendBuffer = function(buffer1, buffer2) {
var tmp = new Uint8Array(buffer1.byteLength + buffer2.byteLength);
tmp.set(new Uint8Array(buffer1), 0);
tmp.set(new Uint8Array(buffer2), buffer1.byteLength);
return tmp;
};
function get_image(url, length, connections){
var difference = Math.floor(length/connections);
var modulo = difference%3;
if (modulo == 0)
difference -= 1;
else if (modulo%3 == 1)
difference -= 2;
var start_point = 0;
var i = 0;
for (i = 1; i <= (length/difference)-1; start_point = end_point +1, i++) {
end_point = start_point + difference;
get_part(url, start_point, end_point, "content"+i, connections);
};
get_part(url, start_point, length-1, "content"+i, connections);
// var end_part_1 = Math.floor(length/3);
// while()
// if (end_part_1 % 3 != 0 ){
// end_part_1 += 3 - (end_part_1 % 3);
// }
// end_part_1 = end_part_1-1;
// get_part(url, start_part_1, end_part_1, "content1");
// console.log(content1);
// var start_part_2 = end_part_1+1;
// var end_part_2 = start_part_2 + end_part_1;
// // var content2 = new Uint8Array(request.response);
// get_part(url, start_part_2, end_part_2, "content2") //--> returns only the partial content
// var start_part_3 = end_part_2+1;
// var end_part_3 = length-1;
// get_part(url, start_part_3, end_part_3, "content3") //--> returns only the partial content
// var start_part_4 = end_part_3;
// var end_part_4 = start_part_4 + end_part_1;
// console.log("Start_part 2 ="+start_part_4);
// console.log("end_part2 ="+end_part_4);
// // var content3 = new Uint8Array(request.response);
// content4 = xmlhttp.response; //--> returns only the partial content
// var start_part_5 = end_part_4;
// var end_part_5 = length -1;
// console.log("Start_part 2 ="+start_part_5);
// console.log("end_part2 ="+end_part_5);
// // var content3 = new Uint8Array(request.response);
// content5 = xmlhttp.response; //--> returns only the partial content
// image_64 = window.btoa(unescape(encodeURIComponent(content1 + content2 + content3)));
// console.log(image_64);
// content = content1+content2+content3
// image_64 = content
// console.log(content.length);
// image_64 = base64ArrayBuffer(content);
// document.getElementById("ItemPreview").src = "data:image/png;base64," + image_64;
}
</script>
<img id="ItemPreview" src="" />
</body>
</html>
<!-- -->