@etothepii/satisfactory-file-parser 0.4.10 → 0.4.11
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,14 +18,14 @@ 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.
|
|
21
|
+
| U1.0 | ✅ >= 0.4.11 |
|
|
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
|
-
|
|
28
|
+
For reading a save file (`.sav`), just pass a Buffer to the parser with the file content.
|
|
29
29
|
```js
|
|
30
30
|
import * as fs from 'fs';
|
|
31
31
|
import { Parser } from "@etothepii/satisfactory-file-parser";
|
|
@@ -34,8 +34,33 @@ const file = fs.readFileSync('./MySave.sav') as Buffer;
|
|
|
34
34
|
const parsedSave = Parser.ParseSaveFile(file);
|
|
35
35
|
```
|
|
36
36
|
|
|
37
|
+
### Save Parsing via Stream
|
|
38
|
+
|
|
39
|
+
You can parse via stream, to save RAM. The binary data will still be in memory, but the converted JSON won't.
|
|
40
|
+
The returned `stream` is a readable WHATWG stream of type string.
|
|
41
|
+
WHATWG is used by default by browsers. Node js can use them using `Writable.toWeb()` and `Writable.fromWeb()` for example.
|
|
42
|
+
|
|
43
|
+
```js
|
|
44
|
+
const jsonFileStream = fs.createWriteStream(outJsonPath, { highWaterMark: 1024 * 1024 * 200 }); // your outgoing JSON stream. In this case directly to file.
|
|
45
|
+
const whatwgWriteStream = Writable.toWeb(outJsonStream) as WritableStream<string>; // convert the file stream to WHATWG-compliant stream
|
|
46
|
+
|
|
47
|
+
const { stream, startStreaming } = ReadableStreamParser.CreateReadableStreamFromSaveToJson(savename, file, decompressedBody => {
|
|
48
|
+
console.log('on binary body data.');
|
|
49
|
+
}, (progress: number, msg: string | undefined) => {
|
|
50
|
+
// a callback for reporting progress as number [0,1]. Sometimes has a message.
|
|
51
|
+
console.log(`${new Date().toString()}: progress`, progress, msg);
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
stream.pipeTo(whatwgWriteStream);
|
|
55
|
+
whatwgWriteStream.on('close', () => {
|
|
56
|
+
// write stream finished
|
|
57
|
+
});
|
|
58
|
+
|
|
59
|
+
startStreaming();
|
|
60
|
+
```
|
|
61
|
+
|
|
37
62
|
Consequently, writing a parsed save file back is just as easy.
|
|
38
|
-
The SaveParser has callbacks to assist
|
|
63
|
+
The SaveParser has callbacks to assist during syncing on different occasions during the process.
|
|
39
64
|
For example, when writing the header or when writing a chunk of the save body.
|
|
40
65
|
The splitting in individual chunks enables you to more easily stream the binary data to somewhere else.
|
|
41
66
|
```js
|
|
@@ -172,7 +172,7 @@ class DataFields {
|
|
|
172
172
|
reader.readInt32();
|
|
173
173
|
reader.readBytes(1);
|
|
174
174
|
const recipeTypePath = reader.readString();
|
|
175
|
-
|
|
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.
|
|
387
|
+
ObjectReference_1.ObjectReference.write(writer, instance.blueprintProxy);
|
|
387
388
|
}
|
|
388
389
|
}
|
|
389
390
|
}
|
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.
|
|
4
|
+
"version": "0.4.11",
|
|
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",
|