-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstream.js
75 lines (57 loc) · 989 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
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
class Stream {
constructor(buffer) {
this.pos = 0;
this.data = buffer;
}
seek(pos) {
this.pos = pos;
}
skip(len) {
this.pos += len;
}
read(len) {
const read = this.data.subarray(this.pos, this.pos + len);
this.pos += len;
return read;
}
bytes(len) {
return this.read(len);
}
byte() {
return this.read(1);
}
Int8() {
return this.byte().readInt8();
}
UInt8() {
return this.byte().readUInt8();
}
Int16LE() {
return this.read(2).readInt16LE();
}
UInt16LE() {
return this.read(2).readUInt16LE();
}
Int16BE() {
return this.read(2).readInt16BE();
}
UInt16BE() {
return this.read(2).readUInt16BE();
}
Int32LE() {
return this.read(4).readInt32LE();
}
UInt32LE() {
return this.read(4).readUInt32LE();
}
Int32BE() {
return this.read(4).readInt32BE();
}
UInt32BE() {
return this.read(4).readUInt32BE();
}
String(len=1, encoding='utf8') {
return this.bytes(len).toString(encoding);
}
}
module.exports = Stream;