@etothepii/satisfactory-file-parser 0.0.33 → 0.0.34

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (34) hide show
  1. package/build/index.js +41 -51
  2. package/build/parser/byte/alignment.enum.js +8 -18
  3. package/build/parser/byte/binary-operable.interface.js +2 -12
  4. package/build/parser/byte/binary-readable.interface.js +2 -12
  5. package/build/parser/byte/byte-reader.class.js +122 -132
  6. package/build/parser/byte/byte-writer.class.js +133 -143
  7. package/build/parser/error/parser.error.js +40 -50
  8. package/build/parser/file.types.js +2 -12
  9. package/build/parser/parser.js +85 -95
  10. package/build/parser/satisfactory/blueprint/blueprint-reader.js +109 -119
  11. package/build/parser/satisfactory/blueprint/blueprint-writer.js +56 -66
  12. package/build/parser/satisfactory/blueprint/blueprint.types.js +2 -12
  13. package/build/parser/satisfactory/objects/DataFields.js +297 -307
  14. package/build/parser/satisfactory/objects/ObjectReference.js +14 -24
  15. package/build/parser/satisfactory/objects/Property.js +967 -977
  16. package/build/parser/satisfactory/objects/SaveComponent.js +28 -38
  17. package/build/parser/satisfactory/objects/SaveEntity.js +65 -75
  18. package/build/parser/satisfactory/objects/SaveObject.js +26 -36
  19. package/build/parser/satisfactory/save/asynchronous-level.class.js +60 -70
  20. package/build/parser/satisfactory/save/level.class.js +122 -132
  21. package/build/parser/satisfactory/save/satisfactory-save.js +10 -20
  22. package/build/parser/satisfactory/save/save-reader.js +158 -168
  23. package/build/parser/satisfactory/save/save-writer.js +97 -107
  24. package/build/parser/satisfactory/save/save.types.js +2 -12
  25. package/build/parser/satisfactory/structs/util.types.js +89 -99
  26. package/build/parser/stream/byte-stream-reader.class.js +217 -227
  27. package/build/parser/stream/json-stream-state-writer.js +15 -25
  28. package/build/parser/stream/json-stream-writable.js +72 -82
  29. package/build/parser/stream/json-stream-writer.js +122 -132
  30. package/build/parser/stream/save-stream-json-stringifier.js +29 -39
  31. package/build/parser/stream/save-stream-reader.class.js +106 -116
  32. package/build/parser/stream/save-stream-writer.class.js +90 -100
  33. package/build/parser/stream/stream-level.class.js +93 -103
  34. package/package.json +1 -1
@@ -1,105 +1,95 @@
1
- (function (factory) {
2
- if (typeof module === "object" && typeof module.exports === "object") {
3
- var v = factory(require, exports);
4
- if (v !== undefined) module.exports = v;
5
- }
6
- else if (typeof define === "function" && define.amd) {
7
- define(["require", "exports"], factory);
8
- }
9
- })(function (require, exports) {
10
- "use strict";
11
- Object.defineProperty(exports, "__esModule", { value: true });
12
- exports.SerializeTransform = exports.ParseTransform = exports.SerializeVec2 = exports.ParseVec2 = exports.SerializeVec3 = exports.ParseVec3 = exports.norm = exports.mult = exports.length = exports.add = exports.sub = exports.SerializeVec4 = exports.ParseVec4 = exports.ParseCol4BGRA = exports.SerializeCol4BGRA = exports.ParseCol4RGBA = exports.SerializeCol4RGBA = void 0;
13
- const SerializeCol4RGBA = (writer, value) => {
14
- writer.writeFloat(value.r);
15
- writer.writeFloat(value.g);
16
- writer.writeFloat(value.b);
17
- writer.writeFloat(value.a);
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.SerializeTransform = exports.ParseTransform = exports.SerializeVec2 = exports.ParseVec2 = exports.SerializeVec3 = exports.ParseVec3 = exports.norm = exports.mult = exports.length = exports.add = exports.sub = exports.SerializeVec4 = exports.ParseVec4 = exports.ParseCol4BGRA = exports.SerializeCol4BGRA = exports.ParseCol4RGBA = exports.SerializeCol4RGBA = void 0;
4
+ const SerializeCol4RGBA = (writer, value) => {
5
+ writer.writeFloat(value.r);
6
+ writer.writeFloat(value.g);
7
+ writer.writeFloat(value.b);
8
+ writer.writeFloat(value.a);
9
+ };
10
+ exports.SerializeCol4RGBA = SerializeCol4RGBA;
11
+ const ParseCol4RGBA = (reader) => {
12
+ return {
13
+ r: reader.readFloat32(),
14
+ g: reader.readFloat32(),
15
+ b: reader.readFloat32(),
16
+ a: reader.readFloat32(),
18
17
  };
19
- exports.SerializeCol4RGBA = SerializeCol4RGBA;
20
- const ParseCol4RGBA = (reader) => {
21
- return {
22
- r: reader.readFloat32(),
23
- g: reader.readFloat32(),
24
- b: reader.readFloat32(),
25
- a: reader.readFloat32(),
26
- };
18
+ };
19
+ exports.ParseCol4RGBA = ParseCol4RGBA;
20
+ const SerializeCol4BGRA = (writer, value) => {
21
+ writer.writeByte(value.b);
22
+ writer.writeByte(value.g);
23
+ writer.writeByte(value.r);
24
+ writer.writeByte(value.a);
25
+ };
26
+ exports.SerializeCol4BGRA = SerializeCol4BGRA;
27
+ const ParseCol4BGRA = (reader) => {
28
+ return {
29
+ b: reader.readByte(),
30
+ g: reader.readByte(),
31
+ r: reader.readByte(),
32
+ a: reader.readByte(),
27
33
  };
28
- exports.ParseCol4RGBA = ParseCol4RGBA;
29
- const SerializeCol4BGRA = (writer, value) => {
30
- writer.writeByte(value.b);
31
- writer.writeByte(value.g);
32
- writer.writeByte(value.r);
33
- writer.writeByte(value.a);
34
+ };
35
+ exports.ParseCol4BGRA = ParseCol4BGRA;
36
+ const ParseVec4 = (reader) => {
37
+ return {
38
+ ...((0, exports.ParseVec3)(reader)),
39
+ w: reader.readFloat32()
34
40
  };
35
- exports.SerializeCol4BGRA = SerializeCol4BGRA;
36
- const ParseCol4BGRA = (reader) => {
37
- return {
38
- b: reader.readByte(),
39
- g: reader.readByte(),
40
- r: reader.readByte(),
41
- a: reader.readByte(),
42
- };
41
+ };
42
+ exports.ParseVec4 = ParseVec4;
43
+ const SerializeVec4 = (writer, vec) => {
44
+ (0, exports.SerializeVec3)(writer, vec);
45
+ writer.writeFloat(vec.w);
46
+ };
47
+ exports.SerializeVec4 = SerializeVec4;
48
+ const sub = (other, vec) => ({ x: other.x - vec.x, y: other.y - vec.y, z: other.z - vec.z });
49
+ exports.sub = sub;
50
+ const add = (vec, other) => ({ x: vec.x + other.x, y: vec.y + other.y, z: vec.z + other.z });
51
+ exports.add = add;
52
+ const length = (vec) => Math.sqrt(vec.x ** 2 + vec.y ** 2 + vec.z ** 2);
53
+ exports.length = length;
54
+ const mult = (vec, scale) => ({ x: vec.x * scale, y: vec.y * scale, z: vec.z * scale });
55
+ exports.mult = mult;
56
+ const norm = (vec) => (0, exports.mult)(vec, 1. / (0, exports.length)(vec));
57
+ exports.norm = norm;
58
+ const ParseVec3 = (reader) => {
59
+ return {
60
+ ...((0, exports.ParseVec2)(reader)),
61
+ z: reader.readFloat32()
43
62
  };
44
- exports.ParseCol4BGRA = ParseCol4BGRA;
45
- const ParseVec4 = (reader) => {
46
- return {
47
- ...((0, exports.ParseVec3)(reader)),
48
- w: reader.readFloat32()
49
- };
63
+ };
64
+ exports.ParseVec3 = ParseVec3;
65
+ const SerializeVec3 = (writer, vec) => {
66
+ (0, exports.SerializeVec2)(writer, vec);
67
+ writer.writeFloat(vec.z);
68
+ };
69
+ exports.SerializeVec3 = SerializeVec3;
70
+ const ParseVec2 = (reader) => {
71
+ return {
72
+ x: reader.readFloat32(),
73
+ y: reader.readFloat32(),
50
74
  };
51
- exports.ParseVec4 = ParseVec4;
52
- const SerializeVec4 = (writer, vec) => {
53
- (0, exports.SerializeVec3)(writer, vec);
54
- writer.writeFloat(vec.w);
75
+ };
76
+ exports.ParseVec2 = ParseVec2;
77
+ const SerializeVec2 = (writer, vec) => {
78
+ writer.writeFloat(vec.x);
79
+ writer.writeFloat(vec.y);
80
+ };
81
+ exports.SerializeVec2 = SerializeVec2;
82
+ const ParseTransform = (reader) => {
83
+ return {
84
+ rotation: (0, exports.ParseVec4)(reader),
85
+ translation: (0, exports.ParseVec3)(reader),
86
+ scale3d: (0, exports.ParseVec3)(reader),
55
87
  };
56
- exports.SerializeVec4 = SerializeVec4;
57
- const sub = (other, vec) => ({ x: other.x - vec.x, y: other.y - vec.y, z: other.z - vec.z });
58
- exports.sub = sub;
59
- const add = (vec, other) => ({ x: vec.x + other.x, y: vec.y + other.y, z: vec.z + other.z });
60
- exports.add = add;
61
- const length = (vec) => Math.sqrt(vec.x ** 2 + vec.y ** 2 + vec.z ** 2);
62
- exports.length = length;
63
- const mult = (vec, scale) => ({ x: vec.x * scale, y: vec.y * scale, z: vec.z * scale });
64
- exports.mult = mult;
65
- const norm = (vec) => (0, exports.mult)(vec, 1. / (0, exports.length)(vec));
66
- exports.norm = norm;
67
- const ParseVec3 = (reader) => {
68
- return {
69
- ...((0, exports.ParseVec2)(reader)),
70
- z: reader.readFloat32()
71
- };
72
- };
73
- exports.ParseVec3 = ParseVec3;
74
- const SerializeVec3 = (writer, vec) => {
75
- (0, exports.SerializeVec2)(writer, vec);
76
- writer.writeFloat(vec.z);
77
- };
78
- exports.SerializeVec3 = SerializeVec3;
79
- const ParseVec2 = (reader) => {
80
- return {
81
- x: reader.readFloat32(),
82
- y: reader.readFloat32(),
83
- };
84
- };
85
- exports.ParseVec2 = ParseVec2;
86
- const SerializeVec2 = (writer, vec) => {
87
- writer.writeFloat(vec.x);
88
- writer.writeFloat(vec.y);
89
- };
90
- exports.SerializeVec2 = SerializeVec2;
91
- const ParseTransform = (reader) => {
92
- return {
93
- rotation: (0, exports.ParseVec4)(reader),
94
- translation: (0, exports.ParseVec3)(reader),
95
- scale3d: (0, exports.ParseVec3)(reader),
96
- };
97
- };
98
- exports.ParseTransform = ParseTransform;
99
- const SerializeTransform = (writer, transform) => {
100
- (0, exports.SerializeVec4)(writer, transform.rotation);
101
- (0, exports.SerializeVec3)(writer, transform.translation);
102
- (0, exports.SerializeVec3)(writer, transform.scale3d);
103
- };
104
- exports.SerializeTransform = SerializeTransform;
105
- });
88
+ };
89
+ exports.ParseTransform = ParseTransform;
90
+ const SerializeTransform = (writer, transform) => {
91
+ (0, exports.SerializeVec4)(writer, transform.rotation);
92
+ (0, exports.SerializeVec3)(writer, transform.translation);
93
+ (0, exports.SerializeVec3)(writer, transform.scale3d);
94
+ };
95
+ exports.SerializeTransform = SerializeTransform;
@@ -1,251 +1,241 @@
1
- (function (factory) {
2
- if (typeof module === "object" && typeof module.exports === "object") {
3
- var v = factory(require, exports);
4
- if (v !== undefined) module.exports = v;
5
- }
6
- else if (typeof define === "function" && define.amd) {
7
- define(["require", "exports", "../byte/alignment.enum", "../byte/byte-writer.class", "../error/parser.error"], factory);
8
- }
9
- })(function (require, exports) {
10
- "use strict";
11
- Object.defineProperty(exports, "__esModule", { value: true });
12
- exports.ByteStreamReader = void 0;
13
- const alignment_enum_1 = require("../byte/alignment.enum");
14
- const byte_writer_class_1 = require("../byte/byte-writer.class");
15
- const parser_error_1 = require("../error/parser.error");
16
- class ByteStreamReader {
17
- constructor(reader, onCloseCallback, timeout = 30000, maxBufferThreshold = 100 * 1000 * 1000, alignment = alignment_enum_1.Alignment.LITTLE_ENDIAN) {
18
- this.reader = reader;
19
- this.onCloseCallback = onCloseCallback;
20
- this.timeout = timeout;
21
- this.maxBufferThreshold = maxBufferThreshold;
22
- this.alignment = alignment;
23
- this.debug = false;
24
- this.closedAlready = false;
25
- this.totalNumberOfBytesRead = 0;
26
- this.trailingBufferSize = 0;
27
- this.continuousRead = async () => {
28
- while (!this.inputStreamIsDone && !this.paused) {
29
- const { done, value } = await this.reader.read();
30
- if (!this.inputStreamIsDone) {
31
- if (value) {
32
- const trailingPos = Math.max(0, this.currentByte - this.trailingBufferSize);
33
- this.operatingStreamBuffer = new Uint8Array(byte_writer_class_1.ByteWriter.AppendBuffer(this.operatingStreamBuffer.slice(trailingPos), value));
34
- this.operatingDataView = new DataView(this.operatingStreamBuffer.buffer);
35
- this.currentByte = Math.min(this.currentByte, this.trailingBufferSize);
36
- if (this.operatingStreamBuffer.byteLength > this.maxBufferThreshold) {
37
- console.warn('pausing due to size.');
38
- this.pause();
39
- }
40
- if (this.callbackAfterRead) {
41
- this.callbackAfterRead();
42
- }
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ByteStreamReader = void 0;
4
+ const alignment_enum_1 = require("../byte/alignment.enum");
5
+ const byte_writer_class_1 = require("../byte/byte-writer.class");
6
+ const parser_error_1 = require("../error/parser.error");
7
+ class ByteStreamReader {
8
+ constructor(reader, onCloseCallback, timeout = 30000, maxBufferThreshold = 100 * 1000 * 1000, alignment = alignment_enum_1.Alignment.LITTLE_ENDIAN) {
9
+ this.reader = reader;
10
+ this.onCloseCallback = onCloseCallback;
11
+ this.timeout = timeout;
12
+ this.maxBufferThreshold = maxBufferThreshold;
13
+ this.alignment = alignment;
14
+ this.debug = false;
15
+ this.closedAlready = false;
16
+ this.totalNumberOfBytesRead = 0;
17
+ this.trailingBufferSize = 0;
18
+ this.continuousRead = async () => {
19
+ while (!this.inputStreamIsDone && !this.paused) {
20
+ const { done, value } = await this.reader.read();
21
+ if (!this.inputStreamIsDone) {
22
+ if (value) {
23
+ const trailingPos = Math.max(0, this.currentByte - this.trailingBufferSize);
24
+ this.operatingStreamBuffer = new Uint8Array(byte_writer_class_1.ByteWriter.AppendBuffer(this.operatingStreamBuffer.slice(trailingPos), value));
25
+ this.operatingDataView = new DataView(this.operatingStreamBuffer.buffer);
26
+ this.currentByte = Math.min(this.currentByte, this.trailingBufferSize);
27
+ if (this.operatingStreamBuffer.byteLength > this.maxBufferThreshold) {
28
+ console.warn('pausing due to size.');
29
+ this.pause();
30
+ }
31
+ if (this.callbackAfterRead) {
32
+ this.callbackAfterRead();
43
33
  }
44
34
  }
45
- else {
46
- this.close();
47
- }
48
- this.inputStreamIsDone = done;
49
35
  }
50
- };
51
- this.operatingStreamBuffer = new Uint8Array();
52
- this.operatingDataView = new DataView(this.operatingStreamBuffer.buffer);
53
- this.inputStreamIsDone = false;
54
- this.currentByte = 0;
55
- this.neededNextAmountOfBytes = 0;
36
+ else {
37
+ this.close();
38
+ }
39
+ this.inputStreamIsDone = done;
40
+ }
41
+ };
42
+ this.operatingStreamBuffer = new Uint8Array();
43
+ this.operatingDataView = new DataView(this.operatingStreamBuffer.buffer);
44
+ this.inputStreamIsDone = false;
45
+ this.currentByte = 0;
46
+ this.neededNextAmountOfBytes = 0;
47
+ this.paused = false;
48
+ this.trailingBufferSize = 2000;
49
+ this.readLoopHandle = setTimeout(this.continuousRead);
50
+ this.waitingTimeoutHandle = undefined;
51
+ }
52
+ pause() {
53
+ this.paused = true;
54
+ clearTimeout(this.readLoopHandle);
55
+ this.readLoopHandle = undefined;
56
+ if (this.waitingTimeoutHandle) {
57
+ clearTimeout(this.waitingTimeoutHandle);
58
+ this.waitingTimeoutHandle = undefined;
59
+ }
60
+ }
61
+ resume() {
62
+ if (this.paused) {
56
63
  this.paused = false;
57
- this.trailingBufferSize = 2000;
58
64
  this.readLoopHandle = setTimeout(this.continuousRead);
59
- this.waitingTimeoutHandle = undefined;
60
65
  }
61
- pause() {
62
- this.paused = true;
63
- clearTimeout(this.readLoopHandle);
64
- this.readLoopHandle = undefined;
65
- if (this.waitingTimeoutHandle) {
66
- clearTimeout(this.waitingTimeoutHandle);
67
- this.waitingTimeoutHandle = undefined;
68
- }
66
+ }
67
+ hasInput() {
68
+ return !this.inputStreamIsDone;
69
+ }
70
+ async close() {
71
+ this.inputStreamIsDone = true;
72
+ this.pause();
73
+ await this.onCloseCallback();
74
+ this.closedAlready = true;
75
+ }
76
+ async allocate(count) {
77
+ if (count > this.maxBufferThreshold * 0.5) {
78
+ console.warn(`you are waiting for a very big chunk here mate. ${count} bytes. U sure you have your numbers right?`);
69
79
  }
70
- resume() {
80
+ if (this.getAmountAllocatedLeft() < count) {
81
+ if (this.inputStreamIsDone) {
82
+ throw new parser_error_1.CorruptSaveError('Input Stream has finished before needed data was received.');
83
+ }
71
84
  if (this.paused) {
72
- this.paused = false;
73
- this.readLoopHandle = setTimeout(this.continuousRead);
85
+ this.resume();
74
86
  }
87
+ await this.waitUntilNumBytesAvailable(count);
75
88
  }
76
- hasInput() {
77
- return !this.inputStreamIsDone;
78
- }
79
- async close() {
80
- this.inputStreamIsDone = true;
81
- this.pause();
82
- await this.onCloseCallback();
83
- this.closedAlready = true;
84
- }
85
- async allocate(count) {
86
- if (count > this.maxBufferThreshold * 0.5) {
87
- console.warn(`you are waiting for a very big chunk here mate. ${count} bytes. U sure you have your numbers right?`);
88
- }
89
- if (this.getAmountAllocatedLeft() < count) {
90
- if (this.inputStreamIsDone) {
91
- throw new parser_error_1.CorruptSaveError('Input Stream has finished before needed data was received.');
92
- }
93
- if (this.paused) {
94
- this.resume();
95
- }
96
- await this.waitUntilNumBytesAvailable(count);
89
+ }
90
+ waitUntilNumBytesAvailable(count) {
91
+ this.neededNextAmountOfBytes = count;
92
+ return new Promise((resolve, reject) => {
93
+ if (this.getAmountAllocatedLeft() >= this.neededNextAmountOfBytes) {
94
+ this.neededNextAmountOfBytes = 0;
95
+ return resolve();
97
96
  }
98
- }
99
- waitUntilNumBytesAvailable(count) {
100
- this.neededNextAmountOfBytes = count;
101
- return new Promise((resolve, reject) => {
97
+ this.callbackAfterRead = () => {
102
98
  if (this.getAmountAllocatedLeft() >= this.neededNextAmountOfBytes) {
99
+ if (this.waitingTimeoutHandle) {
100
+ clearTimeout(this.waitingTimeoutHandle);
101
+ }
103
102
  this.neededNextAmountOfBytes = 0;
103
+ this.callbackAfterRead = undefined;
104
104
  return resolve();
105
105
  }
106
- this.callbackAfterRead = () => {
107
- if (this.getAmountAllocatedLeft() >= this.neededNextAmountOfBytes) {
108
- if (this.waitingTimeoutHandle) {
109
- clearTimeout(this.waitingTimeoutHandle);
110
- }
111
- this.neededNextAmountOfBytes = 0;
112
- this.callbackAfterRead = undefined;
113
- return resolve();
114
- }
115
- };
116
- if (this.waitingTimeoutHandle) {
117
- clearTimeout(this.waitingTimeoutHandle);
118
- }
119
- this.waitingTimeoutHandle = setTimeout(() => {
120
- if (!this.inputStreamIsDone) {
121
- reject(new parser_error_1.TimeoutError(`Timed out before ${this.neededNextAmountOfBytes} bytes were available to read next.`));
122
- }
123
- return resolve();
124
- }, this.timeout);
125
- });
126
- }
127
- skipBytes(byteLength = 1) {
128
- this.currentByte += byteLength;
129
- this.totalNumberOfBytesRead += byteLength;
130
- return;
131
- }
132
- readByte() {
133
- this.totalNumberOfBytesRead += 1;
134
- return this.operatingDataView.getUint8(this.currentByte++);
135
- }
136
- readBytes(count) {
137
- this.totalNumberOfBytesRead += count;
138
- return new Uint8Array(new Array(count).fill(0).map(pl => this.operatingDataView.getUint8(this.currentByte++)));
139
- }
140
- readHex(hexLength) {
141
- let hexPart = [];
142
- for (let i = 0; i < hexLength; i++) {
143
- let currentHex = String.fromCharCode(this.operatingDataView.getUint8(this.currentByte++));
144
- hexPart.push(currentHex);
106
+ };
107
+ if (this.waitingTimeoutHandle) {
108
+ clearTimeout(this.waitingTimeoutHandle);
145
109
  }
146
- this.totalNumberOfBytesRead += hexLength;
147
- return hexPart.join('');
148
- }
149
- readInt8() {
150
- this.totalNumberOfBytesRead += 1;
151
- let data = this.operatingDataView.getInt8(this.currentByte++);
152
- return data;
110
+ this.waitingTimeoutHandle = setTimeout(() => {
111
+ if (!this.inputStreamIsDone) {
112
+ reject(new parser_error_1.TimeoutError(`Timed out before ${this.neededNextAmountOfBytes} bytes were available to read next.`));
113
+ }
114
+ return resolve();
115
+ }, this.timeout);
116
+ });
117
+ }
118
+ skipBytes(byteLength = 1) {
119
+ this.currentByte += byteLength;
120
+ this.totalNumberOfBytesRead += byteLength;
121
+ return;
122
+ }
123
+ readByte() {
124
+ this.totalNumberOfBytesRead += 1;
125
+ return this.operatingDataView.getUint8(this.currentByte++);
126
+ }
127
+ readBytes(count) {
128
+ this.totalNumberOfBytesRead += count;
129
+ return new Uint8Array(new Array(count).fill(0).map(pl => this.operatingDataView.getUint8(this.currentByte++)));
130
+ }
131
+ readHex(hexLength) {
132
+ let hexPart = [];
133
+ for (let i = 0; i < hexLength; i++) {
134
+ let currentHex = String.fromCharCode(this.operatingDataView.getUint8(this.currentByte++));
135
+ hexPart.push(currentHex);
136
+ }
137
+ this.totalNumberOfBytesRead += hexLength;
138
+ return hexPart.join('');
139
+ }
140
+ readInt8() {
141
+ this.totalNumberOfBytesRead += 1;
142
+ let data = this.operatingDataView.getInt8(this.currentByte++);
143
+ return data;
144
+ }
145
+ readUint8() {
146
+ this.totalNumberOfBytesRead += 1;
147
+ let data = this.operatingDataView.getUint8(this.currentByte++);
148
+ return data;
149
+ }
150
+ readInt16() {
151
+ this.totalNumberOfBytesRead += 2;
152
+ let data = this.operatingDataView.getInt16(this.currentByte, this.alignment === alignment_enum_1.Alignment.LITTLE_ENDIAN);
153
+ this.currentByte += 2;
154
+ return data;
155
+ }
156
+ readUint16() {
157
+ this.totalNumberOfBytesRead += 2;
158
+ let data = this.operatingDataView.getUint16(this.currentByte, this.alignment === alignment_enum_1.Alignment.LITTLE_ENDIAN);
159
+ this.currentByte += 2;
160
+ return data;
161
+ }
162
+ readInt32() {
163
+ this.totalNumberOfBytesRead += 4;
164
+ let data = this.operatingDataView.getInt32(this.currentByte, this.alignment === alignment_enum_1.Alignment.LITTLE_ENDIAN);
165
+ this.currentByte += 4;
166
+ return data;
167
+ }
168
+ readUint32() {
169
+ this.totalNumberOfBytesRead += 4;
170
+ let data = this.operatingDataView.getUint32(this.currentByte, this.alignment === alignment_enum_1.Alignment.LITTLE_ENDIAN);
171
+ this.currentByte += 4;
172
+ return data;
173
+ }
174
+ readLong() {
175
+ this.totalNumberOfBytesRead += 8;
176
+ let data = this.operatingDataView.getBigInt64(this.currentByte, this.alignment === alignment_enum_1.Alignment.LITTLE_ENDIAN);
177
+ this.currentByte += 8;
178
+ return data;
179
+ }
180
+ readInt64() {
181
+ return this.readLong();
182
+ }
183
+ readUint64() {
184
+ this.totalNumberOfBytesRead += 8;
185
+ let data = this.operatingDataView.getBigUint64(this.currentByte, this.alignment === alignment_enum_1.Alignment.LITTLE_ENDIAN);
186
+ this.currentByte += 8;
187
+ return data;
188
+ }
189
+ readFloat32() {
190
+ this.totalNumberOfBytesRead += 4;
191
+ let data = this.operatingDataView.getFloat32(this.currentByte, this.alignment === alignment_enum_1.Alignment.LITTLE_ENDIAN);
192
+ this.currentByte += 4;
193
+ return data;
194
+ }
195
+ readDouble() {
196
+ this.totalNumberOfBytesRead += 8;
197
+ let data = this.operatingDataView.getFloat64(this.currentByte, this.alignment === alignment_enum_1.Alignment.LITTLE_ENDIAN);
198
+ this.currentByte += 8;
199
+ return data;
200
+ }
201
+ readString() {
202
+ let strLength = this.readInt32();
203
+ if (strLength === 0) {
204
+ return '';
153
205
  }
154
- readUint8() {
155
- this.totalNumberOfBytesRead += 1;
156
- let data = this.operatingDataView.getUint8(this.currentByte++);
157
- return data;
206
+ if (strLength > (this.operatingDataView.buffer.byteLength - this.currentByte)) {
207
+ let errorMessage = `Cannot read string of length ${strLength} at position ${this.currentByte} as it exceeds the end at ${this.operatingDataView.buffer.byteLength}`;
208
+ throw new Error(errorMessage);
158
209
  }
159
- readInt16() {
160
- this.totalNumberOfBytesRead += 2;
161
- let data = this.operatingDataView.getInt16(this.currentByte, this.alignment === alignment_enum_1.Alignment.LITTLE_ENDIAN);
210
+ if (strLength < 0) {
211
+ const string = new Array(-strLength - 1).fill('').map(c => String.fromCharCode(this.readUint16()));
162
212
  this.currentByte += 2;
163
- return data;
164
- }
165
- readUint16() {
166
213
  this.totalNumberOfBytesRead += 2;
167
- let data = this.operatingDataView.getUint16(this.currentByte, this.alignment === alignment_enum_1.Alignment.LITTLE_ENDIAN);
168
- this.currentByte += 2;
169
- return data;
214
+ return string.join('');
170
215
  }
171
- readInt32() {
172
- this.totalNumberOfBytesRead += 4;
173
- let data = this.operatingDataView.getInt32(this.currentByte, this.alignment === alignment_enum_1.Alignment.LITTLE_ENDIAN);
174
- this.currentByte += 4;
175
- return data;
176
- }
177
- readUint32() {
178
- this.totalNumberOfBytesRead += 4;
179
- let data = this.operatingDataView.getUint32(this.currentByte, this.alignment === alignment_enum_1.Alignment.LITTLE_ENDIAN);
180
- this.currentByte += 4;
181
- return data;
182
- }
183
- readLong() {
184
- this.totalNumberOfBytesRead += 8;
185
- let data = this.operatingDataView.getBigInt64(this.currentByte, this.alignment === alignment_enum_1.Alignment.LITTLE_ENDIAN);
186
- this.currentByte += 8;
187
- return data;
188
- }
189
- readInt64() {
190
- return this.readLong();
191
- }
192
- readUint64() {
193
- this.totalNumberOfBytesRead += 8;
194
- let data = this.operatingDataView.getBigUint64(this.currentByte, this.alignment === alignment_enum_1.Alignment.LITTLE_ENDIAN);
195
- this.currentByte += 8;
196
- return data;
197
- }
198
- readFloat32() {
199
- this.totalNumberOfBytesRead += 4;
200
- let data = this.operatingDataView.getFloat32(this.currentByte, this.alignment === alignment_enum_1.Alignment.LITTLE_ENDIAN);
201
- this.currentByte += 4;
202
- return data;
203
- }
204
- readDouble() {
205
- this.totalNumberOfBytesRead += 8;
206
- let data = this.operatingDataView.getFloat64(this.currentByte, this.alignment === alignment_enum_1.Alignment.LITTLE_ENDIAN);
207
- this.currentByte += 8;
208
- return data;
209
- }
210
- readString() {
211
- let strLength = this.readInt32();
212
- if (strLength === 0) {
213
- return '';
214
- }
215
- if (strLength > (this.operatingDataView.buffer.byteLength - this.currentByte)) {
216
- let errorMessage = `Cannot read string of length ${strLength} at position ${this.currentByte} as it exceeds the end at ${this.operatingDataView.buffer.byteLength}`;
217
- throw new Error(errorMessage);
218
- }
219
- if (strLength < 0) {
220
- const string = new Array(-strLength - 1).fill('').map(c => String.fromCharCode(this.readUint16()));
221
- this.currentByte += 2;
222
- this.totalNumberOfBytesRead += 2;
223
- return string.join('');
224
- }
225
- try {
226
- const string = new Array(strLength - 1).fill('').map(c => String.fromCharCode(this.readUint8()));
227
- this.currentByte += 1;
228
- this.totalNumberOfBytesRead += 1;
229
- return string.join('');
230
- }
231
- catch (error) {
232
- let errorMessage = `Cannot read UTF8 string of length ${strLength} at position ${this.currentByte}.`;
233
- console.log(errorMessage, error);
234
- throw error;
235
- }
236
- }
237
- getBufferPosition() {
238
- return this.totalNumberOfBytesRead;
239
- }
240
- getBufferProgress() {
241
- throw new parser_error_1.UnimplementedError();
242
- }
243
- getBufferLength() {
244
- return this.operatingStreamBuffer.byteLength;
216
+ try {
217
+ const string = new Array(strLength - 1).fill('').map(c => String.fromCharCode(this.readUint8()));
218
+ this.currentByte += 1;
219
+ this.totalNumberOfBytesRead += 1;
220
+ return string.join('');
245
221
  }
246
- getAmountAllocatedLeft() {
247
- return this.operatingStreamBuffer.byteLength - this.currentByte;
222
+ catch (error) {
223
+ let errorMessage = `Cannot read UTF8 string of length ${strLength} at position ${this.currentByte}.`;
224
+ console.log(errorMessage, error);
225
+ throw error;
248
226
  }
249
227
  }
250
- exports.ByteStreamReader = ByteStreamReader;
251
- });
228
+ getBufferPosition() {
229
+ return this.totalNumberOfBytesRead;
230
+ }
231
+ getBufferProgress() {
232
+ throw new parser_error_1.UnimplementedError();
233
+ }
234
+ getBufferLength() {
235
+ return this.operatingStreamBuffer.byteLength;
236
+ }
237
+ getAmountAllocatedLeft() {
238
+ return this.operatingStreamBuffer.byteLength - this.currentByte;
239
+ }
240
+ }
241
+ exports.ByteStreamReader = ByteStreamReader;