@etothepii/satisfactory-file-parser 0.0.33 → 0.1.1
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.
- package/README.md +12 -8
- package/build/index.js +41 -51
- package/build/parser/byte/alignment.enum.js +8 -18
- package/build/parser/byte/binary-operable.interface.js +2 -12
- package/build/parser/byte/binary-readable.interface.js +2 -12
- package/build/parser/byte/byte-reader.class.js +122 -132
- package/build/parser/byte/byte-writer.class.js +133 -143
- package/build/parser/error/parser.error.js +40 -50
- package/build/parser/file.types.js +2 -12
- package/build/parser/parser.js +84 -95
- package/build/parser/satisfactory/blueprint/blueprint-reader.js +109 -119
- package/build/parser/satisfactory/blueprint/blueprint-writer.js +56 -66
- package/build/parser/satisfactory/blueprint/blueprint.types.js +2 -12
- package/build/parser/satisfactory/objects/DataFields.js +306 -307
- package/build/parser/satisfactory/objects/ObjectReference.js +14 -24
- package/build/parser/satisfactory/objects/Property.js +974 -977
- package/build/parser/satisfactory/objects/SaveComponent.js +28 -38
- package/build/parser/satisfactory/objects/SaveEntity.js +69 -75
- package/build/parser/satisfactory/objects/SaveObject.js +26 -36
- package/build/parser/satisfactory/save/asynchronous-level.class.js +60 -70
- package/build/parser/satisfactory/save/level.class.d.ts +1 -1
- package/build/parser/satisfactory/save/level.class.js +147 -128
- package/build/parser/satisfactory/save/satisfactory-save.js +10 -20
- package/build/parser/satisfactory/save/save-reader.d.ts +2 -2
- package/build/parser/satisfactory/save/save-reader.js +209 -171
- package/build/parser/satisfactory/save/save-writer.js +97 -107
- package/build/parser/satisfactory/save/save.types.js +2 -12
- package/build/parser/satisfactory/structs/util.types.d.ts +6 -0
- package/build/parser/satisfactory/structs/util.types.js +122 -96
- package/build/parser/stream/byte-stream-reader.class.js +217 -227
- package/build/parser/stream/json-stream-state-writer.js +15 -25
- package/build/parser/stream/json-stream-writable.js +72 -82
- package/build/parser/stream/json-stream-writer.js +122 -132
- package/build/parser/stream/save-stream-json-stringifier.js +29 -39
- package/build/parser/stream/save-stream-reader.class.js +106 -116
- package/build/parser/stream/save-stream-writer.class.js +90 -100
- package/build/parser/stream/stream-level.class.js +93 -103
- package/package.json +2 -2
|
@@ -1,251 +1,241 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
this.
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
if (
|
|
32
|
-
|
|
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
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
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
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
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
|
-
|
|
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.
|
|
73
|
-
this.readLoopHandle = setTimeout(this.continuousRead);
|
|
85
|
+
this.resume();
|
|
74
86
|
}
|
|
87
|
+
await this.waitUntilNumBytesAvailable(count);
|
|
75
88
|
}
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
this.
|
|
81
|
-
|
|
82
|
-
|
|
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
|
-
|
|
107
|
-
|
|
108
|
-
|
|
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.
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
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
|
-
|
|
155
|
-
this.
|
|
156
|
-
|
|
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
|
-
|
|
160
|
-
|
|
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
|
-
|
|
168
|
-
this.currentByte += 2;
|
|
169
|
-
return data;
|
|
214
|
+
return string.join('');
|
|
170
215
|
}
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
this.
|
|
175
|
-
return
|
|
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
|
-
|
|
247
|
-
|
|
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
|
-
|
|
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;
|
|
@@ -1,28 +1,18 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.JsonStreamStateWriter = void 0;
|
|
4
|
+
const json_stream_writable_1 = require("./json-stream-writable");
|
|
5
|
+
class JsonStreamStateWriter extends json_stream_writable_1.JsonStreamWritable {
|
|
6
|
+
constructor(pushWritable, startState) {
|
|
7
|
+
super(pushWritable);
|
|
8
|
+
this.currentState = startState;
|
|
5
9
|
}
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
})(function (require, exports) {
|
|
10
|
-
"use strict";
|
|
11
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
-
exports.JsonStreamStateWriter = void 0;
|
|
13
|
-
const json_stream_writable_1 = require("./json-stream-writable");
|
|
14
|
-
class JsonStreamStateWriter extends json_stream_writable_1.JsonStreamWritable {
|
|
15
|
-
constructor(pushWritable, startState) {
|
|
16
|
-
super(pushWritable);
|
|
17
|
-
this.currentState = startState;
|
|
18
|
-
}
|
|
19
|
-
async useTransition(transition, ...params) {
|
|
20
|
-
if (!transition.requiresOneOfThemToBeBefore.includes(this.currentState)) {
|
|
21
|
-
throw new Error(`Invalid command. Method ${transition.name} is not allowed to be called at this state.`);
|
|
22
|
-
}
|
|
23
|
-
await transition.do(...params);
|
|
24
|
-
this.currentState = transition.assignOnFinish;
|
|
10
|
+
async useTransition(transition, ...params) {
|
|
11
|
+
if (!transition.requiresOneOfThemToBeBefore.includes(this.currentState)) {
|
|
12
|
+
throw new Error(`Invalid command. Method ${transition.name} is not allowed to be called at this state.`);
|
|
25
13
|
}
|
|
14
|
+
await transition.do(...params);
|
|
15
|
+
this.currentState = transition.assignOnFinish;
|
|
26
16
|
}
|
|
27
|
-
|
|
28
|
-
|
|
17
|
+
}
|
|
18
|
+
exports.JsonStreamStateWriter = JsonStreamStateWriter;
|