@etothepii/satisfactory-file-parser 0.4.10 → 0.4.12

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 CHANGED
@@ -18,24 +18,39 @@ Game Version Files of U5 and below are NOT supported.
18
18
  | <= U5 | ❌ |
19
19
  | U6 + U7 | ✅ 0.0.1 - 0.0.34 |
20
20
  | U8 | ✅ 0.1.20 - 0.3.7 |
21
- | U1.0 | ✅ >= 0.4.10 |
21
+ | U1.0 | ✅ >= 0.4.12 |
22
22
 
23
23
 
24
24
  ## Installation via npm
25
25
  `npm install @etothepii/satisfactory-file-parser`
26
26
 
27
27
  ## Usage of Save Parsing
28
- Usage of the SaveParser is easy. For reading a save file (`.sav`), just pass a Buffer to the parser with the file content.
28
+
29
+ I recommend parsing via stream, to save RAM. The binary data of the whole save will still be in memory, but the converted JSON won't.
30
+ The returned `stream` is a readable WHATWG stream of type string.
31
+ WHATWG is used by default by browsers. Node js can use them using `Writable.toWeb()` and `Writable.fromWeb()` for example.
32
+
29
33
  ```js
30
- import * as fs from 'fs';
31
- import { Parser } from "@etothepii/satisfactory-file-parser";
34
+ const jsonFileStream = fs.createWriteStream(outJsonPath, { highWaterMark: 1024 * 1024 * 200 }); // your outgoing JSON stream. In this case directly to file.
35
+ const whatwgWriteStream = Writable.toWeb(outJsonStream) as WritableStream<string>; // convert the file stream to WHATWG-compliant stream
36
+
37
+ const { stream, startStreaming } = ReadableStreamParser.CreateReadableStreamFromSaveToJson(savename, file, decompressedBody => {
38
+ console.log('on binary body data.');
39
+ }, (progress: number, msg: string | undefined) => {
40
+ // a callback for reporting progress as number [0,1]. Sometimes has a message.
41
+ console.log(`${new Date().toString()}: progress`, progress, msg);
42
+ });
32
43
 
33
- const file = fs.readFileSync('./MySave.sav') as Buffer;
34
- const parsedSave = Parser.ParseSaveFile(file);
44
+ stream.pipeTo(whatwgWriteStream);
45
+ whatwgWriteStream.on('close', () => {
46
+ // write stream finished
47
+ });
48
+
49
+ startStreaming();
35
50
  ```
36
51
 
37
52
  Consequently, writing a parsed save file back is just as easy.
38
- The SaveParser has callbacks to assist in syncing on different occasions during the process.
53
+ The SaveParser has callbacks to assist during syncing on different occasions during the process.
39
54
  For example, when writing the header or when writing a chunk of the save body.
40
55
  The splitting in individual chunks enables you to more easily stream the binary data to somewhere else.
41
56
  ```js
@@ -57,6 +72,18 @@ Parser.WriteSave(save, binaryBeforeCompressed => {
57
72
  fs.writeFileSync('./MyModifiedSave.sav', Buffer.concat([header!, ...bodyChunks]));
58
73
  ```
59
74
 
75
+
76
+ ### Old Usage of Save Parsing. Deprecated.
77
+ For reading a save file (`.sav`) and parse In-Memory, just pass a Buffer to the parser with the file content.
78
+ ```js
79
+ import * as fs from 'fs';
80
+ import { Parser } from "@etothepii/satisfactory-file-parser";
81
+
82
+ const file = fs.readFileSync('./MySave.sav') as Buffer;
83
+ const parsedSave = Parser.ParseSaveFile(file);
84
+ ```
85
+
86
+
60
87
  ## Usage of Blueprint Parsing
61
88
  Blueprint parsing works very similiar. Note, that blueprints consist of 2 files. The `.sbp` main file and the config file `.sbpcfg`.
62
89
 
@@ -172,7 +172,7 @@ class DataFields {
172
172
  reader.readInt32();
173
173
  reader.readBytes(1);
174
174
  const recipeTypePath = reader.readString();
175
- reader.readInt64();
175
+ const blueprintProxy = ObjectReference_1.ObjectReference.read(reader);
176
176
  instances.push({
177
177
  transform,
178
178
  unknownUseNumbers,
@@ -180,6 +180,7 @@ class DataFields {
180
180
  paintFinishPath,
181
181
  recipeTypePath,
182
182
  patternPath,
183
+ blueprintProxy
183
184
  });
184
185
  }
185
186
  property.buildables.push({
@@ -383,7 +384,7 @@ class DataFields {
383
384
  writer.writeInt32(0);
384
385
  writer.writeByte(0);
385
386
  writer.writeString(instance.recipeTypePath);
386
- writer.writeInt64(0n);
387
+ ObjectReference_1.ObjectReference.write(writer, instance.blueprintProxy);
387
388
  }
388
389
  }
389
390
  }
@@ -34,7 +34,11 @@ class StructProperty extends BasicProperty_1.AbstractBaseProperty {
34
34
  struct.value = StructProperty.ParseValue(reader, struct.subtype, size);
35
35
  const readBytes = reader.getBufferPosition() - before;
36
36
  if (readBytes !== size) {
37
- throw new Error(`possibly corrupt. Read ${readBytes} for StructProperty Content of ${struct.subtype}, but ${size} were indicated.`);
37
+ if (size - readBytes === 4 && reader.readInt32() === 0) {
38
+ }
39
+ else {
40
+ throw new Error(`possibly corrupt. Read ${readBytes} for StructProperty Content of ${struct.subtype}, but ${size} were indicated.`);
41
+ }
38
42
  }
39
43
  return struct;
40
44
  }
@@ -42,6 +42,7 @@ export type BuildableTypeInstance = {
42
42
  paintFinishPath: string;
43
43
  recipeTypePath: string;
44
44
  patternPath: string;
45
+ blueprintProxy: ObjectReference;
45
46
  };
46
47
  export type BuildableSubsystemSpecialProperty = {
47
48
  buildables: {
@@ -152,9 +152,6 @@ class Level {
152
152
  const collectable = ObjectReference_1.ObjectReference.read(reader);
153
153
  collected.push(collectable);
154
154
  }
155
- if (process.env.NODE_ENV === 'debug' && countSmthing > 0) {
156
- console.log(printSmthWhenItsCollectables, countSmthing, collected.map(coll => coll.pathName).join(', '));
157
- }
158
155
  }
159
156
  return collected;
160
157
  }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@etothepii/satisfactory-file-parser",
3
3
  "author": "etothepii",
4
- "version": "0.4.10",
4
+ "version": "0.4.12",
5
5
  "description": "A file parser for satisfactory files. Includes save files and blueprint files.",
6
6
  "types": "./build/index.d.ts",
7
7
  "main": "./build/index.js",