-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathread.js
61 lines (47 loc) · 873 Bytes
/
read.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
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
/**
* Unsigned 8-bit integer.
*/
exports.uint8 = function(buf, pos){
return buf[pos.offset++];
};
/**
* Unsigned 16-bit integer.
*/
exports.uint16 = function(buf, pos, be){
var o = pos.offset;
pos.offset += 2;
if (be) {
return buf[o] << 8
| buf[o + 1];
}
return buf[o + 1] << 8
| buf[o];
};
/**
* Unsigned 32-bit integer.
*/
exports.uint32 = function(buf, pos, be){
var o = pos.offset;
pos.offset += 4;
if (be) {
return buf[o] << 24
| buf[o + 1] << 16
| buf[o + 2] << 8
| buf[o + 3];
}
return buf[o + 3] << 24
| buf[o + 2] << 16
| buf[o + 1] << 8
| buf[o];
};
/**
* NULL-delimited character array.
*/
exports.string = function(buf, pos){
var arr = [];
while (buf[pos.offset]) {
arr.push(String.fromCharCode(buf[pos.offset++]));
}
pos.offset++;
return arr.join('');
};