-
Notifications
You must be signed in to change notification settings - Fork 0
/
unit8array.html
48 lines (40 loc) · 1.39 KB
/
unit8array.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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
</head>
<body>
</body>
<script>
var oReq = new XMLHttpRequest();
var url = './hello.txt'
// oReq.open("GET", "./hello.txt", true);
// oReq.responseType = "arraybuffer";
// oReq.onload = function (oEvent) {
// var arrayBuffer = oReq.response; // 注意:不是oReq.responseText
// console.log(arrayBuffer, 'arrayBuffer')
// if (arrayBuffer) {
// var byteArray = new Int8Array(arrayBuffer);
// var byteArray2 = new Uint16Array(arrayBuffer);
// for (var i = 0; i < byteArray.byteLength; i++) {
// // 对数组中的每个字节进行操作
// }
// }
// };
// oReq.send(null);
function load_binary_resource(url) {
var req = new XMLHttpRequest();
req.open('GET', url, false);
//XHR binary charset opt by Marcus Granado 2006 [http://mgran.blogspot.com]
req.overrideMimeType('text/plain; charset=utf-8');
req.send(null);
if (req.status != 200) return '';
return req;
}
var res = load_binary_resource(url)
console.log(res)
</script>
</html>