@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
package/README.md
CHANGED
|
@@ -9,14 +9,18 @@ This parser can read, modify and write:
|
|
|
9
9
|
- Blueprint Files `.sbp`, `.sbpcfg`
|
|
10
10
|
|
|
11
11
|
## Supported Versions
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
12
|
+
The version support of the packages is indicated below.
|
|
13
|
+
|
|
14
|
+
Game Version Files of U5 and below are NOT supported.
|
|
15
|
+
|
|
16
|
+
U8 has only read support so far and only for save files, not for blueprint files. More coming soon.
|
|
17
|
+
|
|
18
|
+
| Game Version | Package |
|
|
19
|
+
|:--------------:|:-----------------------------|
|
|
20
|
+
| <= U5 | ❌ |
|
|
21
|
+
| U6 + U7 | ✅ 0.0.1 - 0.0.34 |
|
|
22
|
+
| U8 | ⚠️ >= 0.1.0 ( .sav file Reading only so far) |
|
|
23
|
+
|
|
20
24
|
|
|
21
25
|
## Installation via npm
|
|
22
26
|
`npm install @etothepii/satisfactory-file-parser`
|
package/build/index.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
"use strict";
|
|
1
2
|
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
2
3
|
if (k2 === undefined) k2 = k;
|
|
3
4
|
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
@@ -12,54 +13,43 @@ var __createBinding = (this && this.__createBinding) || (Object.create ? (functi
|
|
|
12
13
|
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
13
14
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
14
15
|
};
|
|
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
|
-
Object.defineProperty(exports, "SaveWriter", { enumerable: true, get: function () { return save_writer_1.SaveWriter; } });
|
|
56
|
-
__exportStar(require("./parser/satisfactory/structs/util.types"), exports);
|
|
57
|
-
var save_stream_json_stringifier_1 = require("./parser/stream/save-stream-json-stringifier");
|
|
58
|
-
Object.defineProperty(exports, "SaveStreamJsonStringifier", { enumerable: true, get: function () { return save_stream_json_stringifier_1.SaveStreamJsonStringifier; } });
|
|
59
|
-
var save_stream_writer_class_1 = require("./parser/stream/save-stream-writer.class");
|
|
60
|
-
Object.defineProperty(exports, "SaveStreamWriter", { enumerable: true, get: function () { return save_stream_writer_class_1.SaveStreamWriter; } });
|
|
61
|
-
__exportStar(require("./parser/error/parser.error"), exports);
|
|
62
|
-
__exportStar(require("./parser/file.types"), exports);
|
|
63
|
-
var parser_1 = require("./parser/parser");
|
|
64
|
-
Object.defineProperty(exports, "Parser", { enumerable: true, get: function () { return parser_1.Parser; } });
|
|
65
|
-
});
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
exports.Parser = exports.SaveStreamWriter = exports.SaveStreamJsonStringifier = exports.SaveWriter = exports.SaveReader = exports.BlueprintWriter = exports.BlueprintConfigWriter = exports.BlueprintReader = exports.BlueprintConfigReader = exports.ByteWriter = exports.ByteReader = exports.SatisfactorySave = exports.Level = exports.SaveEntity = exports.SaveComponent = exports.ObjectReference = exports.DataFields = void 0;
|
|
18
|
+
__exportStar(require("./parser/satisfactory/blueprint/blueprint.types"), exports);
|
|
19
|
+
var DataFields_1 = require("./parser/satisfactory/objects/DataFields");
|
|
20
|
+
Object.defineProperty(exports, "DataFields", { enumerable: true, get: function () { return DataFields_1.DataFields; } });
|
|
21
|
+
var ObjectReference_1 = require("./parser/satisfactory/objects/ObjectReference");
|
|
22
|
+
Object.defineProperty(exports, "ObjectReference", { enumerable: true, get: function () { return ObjectReference_1.ObjectReference; } });
|
|
23
|
+
__exportStar(require("./parser/satisfactory/objects/Property"), exports);
|
|
24
|
+
var SaveComponent_1 = require("./parser/satisfactory/objects/SaveComponent");
|
|
25
|
+
Object.defineProperty(exports, "SaveComponent", { enumerable: true, get: function () { return SaveComponent_1.SaveComponent; } });
|
|
26
|
+
var SaveEntity_1 = require("./parser/satisfactory/objects/SaveEntity");
|
|
27
|
+
Object.defineProperty(exports, "SaveEntity", { enumerable: true, get: function () { return SaveEntity_1.SaveEntity; } });
|
|
28
|
+
var level_class_1 = require("./parser/satisfactory/save/level.class");
|
|
29
|
+
Object.defineProperty(exports, "Level", { enumerable: true, get: function () { return level_class_1.Level; } });
|
|
30
|
+
var satisfactory_save_1 = require("./parser/satisfactory/save/satisfactory-save");
|
|
31
|
+
Object.defineProperty(exports, "SatisfactorySave", { enumerable: true, get: function () { return satisfactory_save_1.SatisfactorySave; } });
|
|
32
|
+
__exportStar(require("./parser/satisfactory/save/save.types"), exports);
|
|
33
|
+
var byte_reader_class_1 = require("./parser/byte/byte-reader.class");
|
|
34
|
+
Object.defineProperty(exports, "ByteReader", { enumerable: true, get: function () { return byte_reader_class_1.ByteReader; } });
|
|
35
|
+
var byte_writer_class_1 = require("./parser/byte/byte-writer.class");
|
|
36
|
+
Object.defineProperty(exports, "ByteWriter", { enumerable: true, get: function () { return byte_writer_class_1.ByteWriter; } });
|
|
37
|
+
var blueprint_reader_1 = require("./parser/satisfactory/blueprint/blueprint-reader");
|
|
38
|
+
Object.defineProperty(exports, "BlueprintConfigReader", { enumerable: true, get: function () { return blueprint_reader_1.BlueprintConfigReader; } });
|
|
39
|
+
Object.defineProperty(exports, "BlueprintReader", { enumerable: true, get: function () { return blueprint_reader_1.BlueprintReader; } });
|
|
40
|
+
var blueprint_writer_1 = require("./parser/satisfactory/blueprint/blueprint-writer");
|
|
41
|
+
Object.defineProperty(exports, "BlueprintConfigWriter", { enumerable: true, get: function () { return blueprint_writer_1.BlueprintConfigWriter; } });
|
|
42
|
+
Object.defineProperty(exports, "BlueprintWriter", { enumerable: true, get: function () { return blueprint_writer_1.BlueprintWriter; } });
|
|
43
|
+
var save_reader_1 = require("./parser/satisfactory/save/save-reader");
|
|
44
|
+
Object.defineProperty(exports, "SaveReader", { enumerable: true, get: function () { return save_reader_1.SaveReader; } });
|
|
45
|
+
var save_writer_1 = require("./parser/satisfactory/save/save-writer");
|
|
46
|
+
Object.defineProperty(exports, "SaveWriter", { enumerable: true, get: function () { return save_writer_1.SaveWriter; } });
|
|
47
|
+
__exportStar(require("./parser/satisfactory/structs/util.types"), exports);
|
|
48
|
+
var save_stream_json_stringifier_1 = require("./parser/stream/save-stream-json-stringifier");
|
|
49
|
+
Object.defineProperty(exports, "SaveStreamJsonStringifier", { enumerable: true, get: function () { return save_stream_json_stringifier_1.SaveStreamJsonStringifier; } });
|
|
50
|
+
var save_stream_writer_class_1 = require("./parser/stream/save-stream-writer.class");
|
|
51
|
+
Object.defineProperty(exports, "SaveStreamWriter", { enumerable: true, get: function () { return save_stream_writer_class_1.SaveStreamWriter; } });
|
|
52
|
+
__exportStar(require("./parser/error/parser.error"), exports);
|
|
53
|
+
__exportStar(require("./parser/file.types"), exports);
|
|
54
|
+
var parser_1 = require("./parser/parser");
|
|
55
|
+
Object.defineProperty(exports, "Parser", { enumerable: true, get: function () { return parser_1.Parser; } });
|
|
@@ -1,18 +1,8 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
})(function (require, exports) {
|
|
10
|
-
"use strict";
|
|
11
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
-
exports.Alignment = void 0;
|
|
13
|
-
var Alignment;
|
|
14
|
-
(function (Alignment) {
|
|
15
|
-
Alignment[Alignment["BIG_ENDIAN"] = 0] = "BIG_ENDIAN";
|
|
16
|
-
Alignment[Alignment["LITTLE_ENDIAN"] = 1] = "LITTLE_ENDIAN";
|
|
17
|
-
})(Alignment = exports.Alignment || (exports.Alignment = {}));
|
|
18
|
-
});
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Alignment = void 0;
|
|
4
|
+
var Alignment;
|
|
5
|
+
(function (Alignment) {
|
|
6
|
+
Alignment[Alignment["BIG_ENDIAN"] = 0] = "BIG_ENDIAN";
|
|
7
|
+
Alignment[Alignment["LITTLE_ENDIAN"] = 1] = "LITTLE_ENDIAN";
|
|
8
|
+
})(Alignment = exports.Alignment || (exports.Alignment = {}));
|
|
@@ -1,12 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
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
|
-
});
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
@@ -1,12 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
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
|
-
});
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
@@ -1,139 +1,129 @@
|
|
|
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
|
-
readBytes(count) {
|
|
44
|
-
return new Uint8Array(new Array(count).fill(0).map(pl => this.bufferView.getUint8(this.currentByte++)));
|
|
45
|
-
}
|
|
46
|
-
readHex(hexLength) {
|
|
47
|
-
let hexPart = [];
|
|
48
|
-
for (let i = 0; i < hexLength; i++) {
|
|
49
|
-
let currentHex = String.fromCharCode(this.bufferView.getUint8(this.currentByte++));
|
|
50
|
-
hexPart.push(currentHex);
|
|
51
|
-
}
|
|
52
|
-
return hexPart.join('');
|
|
53
|
-
}
|
|
54
|
-
readInt8() {
|
|
55
|
-
let data = this.bufferView.getInt8(this.currentByte++);
|
|
56
|
-
return data;
|
|
57
|
-
}
|
|
58
|
-
readUint8() {
|
|
59
|
-
let data = this.bufferView.getUint8(this.currentByte++);
|
|
60
|
-
return data;
|
|
61
|
-
}
|
|
62
|
-
readInt16() {
|
|
63
|
-
let data = this.bufferView.getInt16(this.currentByte, this.alignment === alignment_enum_1.Alignment.LITTLE_ENDIAN);
|
|
64
|
-
this.currentByte += 2;
|
|
65
|
-
return data;
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ByteReader = void 0;
|
|
4
|
+
const alignment_enum_1 = require("./alignment.enum");
|
|
5
|
+
class ByteReader {
|
|
6
|
+
constructor(fileBuffer, alignment) {
|
|
7
|
+
this.debug = false;
|
|
8
|
+
this.currentByte = 0;
|
|
9
|
+
this.handledByte = 0;
|
|
10
|
+
this.maxByte = 0;
|
|
11
|
+
this.getAmountAllocatedLeft = () => this.bufferView.byteLength - this.currentByte;
|
|
12
|
+
this.getBufferPosition = () => this.currentByte;
|
|
13
|
+
this.getBufferSlice = (begin, end) => this.bufferView.buffer.slice(begin, end);
|
|
14
|
+
this.getBufferProgress = () => this.currentByte / this.bufferView.buffer.byteLength;
|
|
15
|
+
this.getBufferLength = () => this.bufferView.buffer.byteLength;
|
|
16
|
+
this.getBuffer = () => this.bufferView.buffer;
|
|
17
|
+
this.alignment = alignment;
|
|
18
|
+
this.reset(fileBuffer);
|
|
19
|
+
}
|
|
20
|
+
reset(newFileBuffer) {
|
|
21
|
+
this.fileBuffer = newFileBuffer;
|
|
22
|
+
this.bufferView = new DataView(newFileBuffer, 0, Math.min(102400, this.fileBuffer.byteLength));
|
|
23
|
+
this.maxByte = newFileBuffer.byteLength;
|
|
24
|
+
this.currentByte = 0;
|
|
25
|
+
this.handledByte = 0;
|
|
26
|
+
}
|
|
27
|
+
skipBytes(byteLength = 1) {
|
|
28
|
+
this.currentByte += byteLength;
|
|
29
|
+
return;
|
|
30
|
+
}
|
|
31
|
+
readByte() {
|
|
32
|
+
return parseInt(this.bufferView.getUint8(this.currentByte++).toString());
|
|
33
|
+
}
|
|
34
|
+
readBytes(count) {
|
|
35
|
+
return new Uint8Array(new Array(count).fill(0).map(pl => this.bufferView.getUint8(this.currentByte++)));
|
|
36
|
+
}
|
|
37
|
+
readHex(hexLength) {
|
|
38
|
+
let hexPart = [];
|
|
39
|
+
for (let i = 0; i < hexLength; i++) {
|
|
40
|
+
let currentHex = String.fromCharCode(this.bufferView.getUint8(this.currentByte++));
|
|
41
|
+
hexPart.push(currentHex);
|
|
66
42
|
}
|
|
67
|
-
|
|
68
|
-
|
|
43
|
+
return hexPart.join('');
|
|
44
|
+
}
|
|
45
|
+
readInt8() {
|
|
46
|
+
let data = this.bufferView.getInt8(this.currentByte++);
|
|
47
|
+
return data;
|
|
48
|
+
}
|
|
49
|
+
readUint8() {
|
|
50
|
+
let data = this.bufferView.getUint8(this.currentByte++);
|
|
51
|
+
return data;
|
|
52
|
+
}
|
|
53
|
+
readInt16() {
|
|
54
|
+
let data = this.bufferView.getInt16(this.currentByte, this.alignment === alignment_enum_1.Alignment.LITTLE_ENDIAN);
|
|
55
|
+
this.currentByte += 2;
|
|
56
|
+
return data;
|
|
57
|
+
}
|
|
58
|
+
readUint16() {
|
|
59
|
+
let data = this.bufferView.getUint16(this.currentByte, this.alignment === alignment_enum_1.Alignment.LITTLE_ENDIAN);
|
|
60
|
+
this.currentByte += 2;
|
|
61
|
+
return data;
|
|
62
|
+
}
|
|
63
|
+
readInt32() {
|
|
64
|
+
let data = this.bufferView.getInt32(this.currentByte, this.alignment === alignment_enum_1.Alignment.LITTLE_ENDIAN);
|
|
65
|
+
this.currentByte += 4;
|
|
66
|
+
return data;
|
|
67
|
+
}
|
|
68
|
+
readUint32() {
|
|
69
|
+
let data = this.bufferView.getUint32(this.currentByte, this.alignment === alignment_enum_1.Alignment.LITTLE_ENDIAN);
|
|
70
|
+
this.currentByte += 4;
|
|
71
|
+
return data;
|
|
72
|
+
}
|
|
73
|
+
readLong() {
|
|
74
|
+
let data = this.bufferView.getBigInt64(this.currentByte, this.alignment === alignment_enum_1.Alignment.LITTLE_ENDIAN);
|
|
75
|
+
this.currentByte += 8;
|
|
76
|
+
return data;
|
|
77
|
+
}
|
|
78
|
+
readInt64() {
|
|
79
|
+
return this.readLong();
|
|
80
|
+
}
|
|
81
|
+
readUint64() {
|
|
82
|
+
let data = this.bufferView.getBigUint64(this.currentByte, this.alignment === alignment_enum_1.Alignment.LITTLE_ENDIAN);
|
|
83
|
+
this.currentByte += 8;
|
|
84
|
+
return data;
|
|
85
|
+
}
|
|
86
|
+
readFloat32() {
|
|
87
|
+
let data = this.bufferView.getFloat32(this.currentByte, this.alignment === alignment_enum_1.Alignment.LITTLE_ENDIAN);
|
|
88
|
+
this.currentByte += 4;
|
|
89
|
+
return data;
|
|
90
|
+
}
|
|
91
|
+
readDouble() {
|
|
92
|
+
let data = this.bufferView.getFloat64(this.currentByte, this.alignment === alignment_enum_1.Alignment.LITTLE_ENDIAN);
|
|
93
|
+
this.currentByte += 8;
|
|
94
|
+
return data;
|
|
95
|
+
}
|
|
96
|
+
readString() {
|
|
97
|
+
let strLength = this.readInt32();
|
|
98
|
+
let startBytes = this.currentByte;
|
|
99
|
+
if (strLength === 0) {
|
|
100
|
+
return '';
|
|
101
|
+
}
|
|
102
|
+
if (strLength > (this.bufferView.buffer.byteLength - this.currentByte)) {
|
|
103
|
+
let errorMessage = `Cannot read string of length ${strLength} at position ${this.currentByte} as it exceeds the end at ${this.bufferView.buffer.byteLength}`;
|
|
104
|
+
throw new Error(errorMessage);
|
|
105
|
+
}
|
|
106
|
+
if (strLength < 0) {
|
|
107
|
+
const string = new Array(-strLength - 1).fill('').map(c => String.fromCharCode(this.readUint16()));
|
|
69
108
|
this.currentByte += 2;
|
|
70
|
-
return
|
|
71
|
-
}
|
|
72
|
-
readInt32() {
|
|
73
|
-
let data = this.bufferView.getInt32(this.currentByte, this.alignment === alignment_enum_1.Alignment.LITTLE_ENDIAN);
|
|
74
|
-
this.currentByte += 4;
|
|
75
|
-
return data;
|
|
76
|
-
}
|
|
77
|
-
readUint32() {
|
|
78
|
-
let data = this.bufferView.getUint32(this.currentByte, this.alignment === alignment_enum_1.Alignment.LITTLE_ENDIAN);
|
|
79
|
-
this.currentByte += 4;
|
|
80
|
-
return data;
|
|
81
|
-
}
|
|
82
|
-
readLong() {
|
|
83
|
-
let data = this.bufferView.getBigInt64(this.currentByte, this.alignment === alignment_enum_1.Alignment.LITTLE_ENDIAN);
|
|
84
|
-
this.currentByte += 8;
|
|
85
|
-
return data;
|
|
109
|
+
return string.join('');
|
|
86
110
|
}
|
|
87
|
-
|
|
88
|
-
|
|
111
|
+
try {
|
|
112
|
+
const string = new Array(strLength - 1).fill('').map(c => String.fromCharCode(this.readUint8()));
|
|
113
|
+
this.currentByte += 1;
|
|
114
|
+
return string.join('');
|
|
89
115
|
}
|
|
90
|
-
|
|
91
|
-
let
|
|
92
|
-
|
|
93
|
-
|
|
116
|
+
catch (error) {
|
|
117
|
+
let errorMessage = `Cannot read UTF8 string of length ${strLength} at position ${this.currentByte}.`;
|
|
118
|
+
console.log(errorMessage, error);
|
|
119
|
+
throw error;
|
|
94
120
|
}
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
}
|
|
100
|
-
readDouble() {
|
|
101
|
-
let data = this.bufferView.getFloat64(this.currentByte, this.alignment === alignment_enum_1.Alignment.LITTLE_ENDIAN);
|
|
102
|
-
this.currentByte += 8;
|
|
103
|
-
return data;
|
|
104
|
-
}
|
|
105
|
-
readString() {
|
|
106
|
-
let strLength = this.readInt32();
|
|
107
|
-
let startBytes = this.currentByte;
|
|
108
|
-
if (strLength === 0) {
|
|
109
|
-
return '';
|
|
110
|
-
}
|
|
111
|
-
if (strLength > (this.bufferView.buffer.byteLength - this.currentByte)) {
|
|
112
|
-
let errorMessage = `Cannot read string of length ${strLength} at position ${this.currentByte} as it exceeds the end at ${this.bufferView.buffer.byteLength}`;
|
|
113
|
-
throw new Error(errorMessage);
|
|
114
|
-
}
|
|
115
|
-
if (strLength < 0) {
|
|
116
|
-
const string = new Array(-strLength - 1).fill('').map(c => String.fromCharCode(this.readUint16()));
|
|
117
|
-
this.currentByte += 2;
|
|
118
|
-
return string.join('');
|
|
119
|
-
}
|
|
120
|
-
try {
|
|
121
|
-
const string = new Array(strLength - 1).fill('').map(c => String.fromCharCode(this.readUint8()));
|
|
122
|
-
this.currentByte += 1;
|
|
123
|
-
return string.join('');
|
|
124
|
-
}
|
|
125
|
-
catch (error) {
|
|
126
|
-
let errorMessage = `Cannot read UTF8 string of length ${strLength} at position ${this.currentByte}.`;
|
|
127
|
-
console.log(errorMessage, error);
|
|
128
|
-
throw error;
|
|
129
|
-
}
|
|
130
|
-
}
|
|
131
|
-
allocate(count) {
|
|
132
|
-
if (this.currentByte + count < this.bufferView.byteLength) {
|
|
133
|
-
console.warn('tried to allocate but there is not enough data left.');
|
|
134
|
-
}
|
|
135
|
-
return Promise.resolve();
|
|
121
|
+
}
|
|
122
|
+
allocate(count) {
|
|
123
|
+
if (this.currentByte + count < this.bufferView.byteLength) {
|
|
124
|
+
console.warn('tried to allocate but there is not enough data left.');
|
|
136
125
|
}
|
|
126
|
+
return Promise.resolve();
|
|
137
127
|
}
|
|
138
|
-
|
|
139
|
-
|
|
128
|
+
}
|
|
129
|
+
exports.ByteReader = ByteReader;
|