@loaders.gl/tile-converter 3.2.5 → 3.2.8

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 (32) hide show
  1. package/dist/3d-tiles-attributes-worker.js +3 -3
  2. package/dist/3d-tiles-attributes-worker.js.map +1 -1
  3. package/dist/converter.min.js +10 -10
  4. package/dist/dist.min.js +161 -106
  5. package/dist/es5/3d-tiles-attributes-worker.js +1 -1
  6. package/dist/es5/i3s-attributes-worker.js +1 -1
  7. package/dist/es5/i3s-converter/helpers/node-pages.js +102 -46
  8. package/dist/es5/i3s-converter/helpers/node-pages.js.map +1 -1
  9. package/dist/es5/i3s-converter/i3s-converter.js +204 -105
  10. package/dist/es5/i3s-converter/i3s-converter.js.map +1 -1
  11. package/dist/es5/lib/utils/write-queue.js +66 -28
  12. package/dist/es5/lib/utils/write-queue.js.map +1 -1
  13. package/dist/es5/pgm-loader.js +1 -1
  14. package/dist/esm/3d-tiles-attributes-worker.js +1 -1
  15. package/dist/esm/i3s-attributes-worker.js +1 -1
  16. package/dist/esm/i3s-converter/helpers/node-pages.js +3 -3
  17. package/dist/esm/i3s-converter/helpers/node-pages.js.map +1 -1
  18. package/dist/esm/i3s-converter/i3s-converter.js +16 -16
  19. package/dist/esm/i3s-converter/i3s-converter.js.map +1 -1
  20. package/dist/esm/lib/utils/write-queue.js +10 -0
  21. package/dist/esm/lib/utils/write-queue.js.map +1 -1
  22. package/dist/esm/pgm-loader.js +1 -1
  23. package/dist/i3s-attributes-worker.js.map +1 -1
  24. package/dist/i3s-converter/helpers/node-pages.js +3 -3
  25. package/dist/i3s-converter/i3s-converter.js +16 -16
  26. package/dist/lib/utils/write-queue.d.ts +1 -0
  27. package/dist/lib/utils/write-queue.d.ts.map +1 -1
  28. package/dist/lib/utils/write-queue.js +13 -0
  29. package/package.json +15 -15
  30. package/src/i3s-converter/helpers/node-pages.ts +3 -3
  31. package/src/i3s-converter/i3s-converter.ts +16 -16
  32. package/src/lib/utils/write-queue.ts +12 -0
@@ -184,14 +184,14 @@ class NodePages {
184
184
  for (const [index, nodePage] of this.nodePages.entries()) {
185
185
  const nodePageStr = JSON.stringify(nodePage);
186
186
  const slpkPath = (0, path_1.join)(layers0Path, 'nodepages');
187
- writeQueue.enqueue({
187
+ await writeQueue.enqueue({
188
188
  archiveKey: `nodePages/${index.toString()}.json.gz`,
189
189
  writePromise: this.writeFile(slpkPath, nodePageStr, `${index.toString()}.json`)
190
190
  });
191
191
  }
192
192
  const metadata = (0, json_map_transform_1.default)({ nodeCount: this.nodesCounter }, (0, metadata_1.METADATA)());
193
193
  const compress = false;
194
- writeQueue.enqueue({
194
+ await writeQueue.enqueue({
195
195
  archiveKey: 'metadata.json',
196
196
  writePromise: this.writeFile(layers0Path, JSON.stringify(metadata), 'metadata.json', compress)
197
197
  });
@@ -200,7 +200,7 @@ class NodePages {
200
200
  for (const [index, nodePage] of this.nodePages.entries()) {
201
201
  const nodePageStr = JSON.stringify(nodePage);
202
202
  const nodePagePath = (0, path_1.join)(layers0Path, 'nodepages', index.toString());
203
- writeQueue.enqueue({ writePromise: this.writeFile(nodePagePath, nodePageStr) });
203
+ await writeQueue.enqueue({ writePromise: this.writeFile(nodePagePath, nodePageStr) });
204
204
  }
205
205
  }
206
206
  }
@@ -240,13 +240,13 @@ class I3SConverter {
240
240
  const [child] = await this._createNode(root0, sourceRootTile, parentId, 0);
241
241
  const childPath = (0, path_1.join)(this.layers0Path, 'nodes', child.path);
242
242
  if (this.options.slpk) {
243
- this.writeQueue.enqueue({
243
+ await this.writeQueue.enqueue({
244
244
  archiveKey: 'nodes/1/3dNodeIndexDocument.json.gz',
245
245
  writePromise: (0, file_utils_1.writeFileForSlpk)(childPath, JSON.stringify(child), '3dNodeIndexDocument.json')
246
246
  });
247
247
  }
248
248
  else {
249
- this.writeQueue.enqueue({ writePromise: (0, file_utils_1.writeFile)(childPath, JSON.stringify(child)) });
249
+ await this.writeQueue.enqueue({ writePromise: (0, file_utils_1.writeFile)(childPath, JSON.stringify(child)) });
250
250
  }
251
251
  }
252
252
  else {
@@ -264,13 +264,13 @@ class I3SConverter {
264
264
  */
265
265
  async _writeLayers0() {
266
266
  if (this.options.slpk) {
267
- this.writeQueue.enqueue({
267
+ await this.writeQueue.enqueue({
268
268
  archiveKey: '3dSceneLayer.json.gz',
269
269
  writePromise: (0, file_utils_1.writeFileForSlpk)(this.layers0Path, JSON.stringify(this.layers0), '3dSceneLayer.json')
270
270
  });
271
271
  }
272
272
  else {
273
- this.writeQueue.enqueue({
273
+ await this.writeQueue.enqueue({
274
274
  writePromise: (0, file_utils_1.writeFile)(this.layers0Path, JSON.stringify(this.layers0))
275
275
  });
276
276
  }
@@ -280,13 +280,13 @@ class I3SConverter {
280
280
  */
281
281
  async _writeNodeIndexDocument(root0, nodePath, rootPath) {
282
282
  if (this.options.slpk) {
283
- this.writeQueue.enqueue({
283
+ await this.writeQueue.enqueue({
284
284
  archiveKey: `nodes/${nodePath}/3dNodeIndexDocument.json.gz`,
285
285
  writePromise: (0, file_utils_1.writeFileForSlpk)(rootPath, JSON.stringify(root0), '3dNodeIndexDocument.json')
286
286
  });
287
287
  }
288
288
  else {
289
- this.writeQueue.enqueue({ writePromise: (0, file_utils_1.writeFile)(rootPath, JSON.stringify(root0)) });
289
+ await this.writeQueue.enqueue({ writePromise: (0, file_utils_1.writeFile)(rootPath, JSON.stringify(root0)) });
290
290
  }
291
291
  }
292
292
  /**
@@ -636,28 +636,28 @@ class I3SConverter {
636
636
  async _writeGeometries(geometryBuffer, compressedGeometry, childPath, slpkChildPath) {
637
637
  if (this.options.slpk) {
638
638
  const slpkGeometryPath = (0, path_1.join)(childPath, 'geometries');
639
- this.writeQueue.enqueue({
639
+ await this.writeQueue.enqueue({
640
640
  archiveKey: `${slpkChildPath}/geometries/0.bin.gz`,
641
641
  writePromise: (0, file_utils_1.writeFileForSlpk)(slpkGeometryPath, geometryBuffer, '0.bin')
642
642
  });
643
643
  }
644
644
  else {
645
645
  const geometryPath = (0, path_1.join)(childPath, 'geometries/0/');
646
- this.writeQueue.enqueue({
646
+ await this.writeQueue.enqueue({
647
647
  writePromise: (0, file_utils_1.writeFile)(geometryPath, geometryBuffer, 'index.bin')
648
648
  });
649
649
  }
650
650
  if (this.options.draco) {
651
651
  if (this.options.slpk) {
652
652
  const slpkCompressedGeometryPath = (0, path_1.join)(childPath, 'geometries');
653
- this.writeQueue.enqueue({
653
+ await this.writeQueue.enqueue({
654
654
  archiveKey: `${slpkChildPath}/geometries/1.bin.gz`,
655
655
  writePromise: (0, file_utils_1.writeFileForSlpk)(slpkCompressedGeometryPath, compressedGeometry, '1.bin')
656
656
  });
657
657
  }
658
658
  else {
659
659
  const compressedGeometryPath = (0, path_1.join)(childPath, 'geometries/1/');
660
- this.writeQueue.enqueue({
660
+ await this.writeQueue.enqueue({
661
661
  writePromise: (0, file_utils_1.writeFile)(compressedGeometryPath, compressedGeometry, 'index.bin')
662
662
  });
663
663
  }
@@ -679,14 +679,14 @@ class I3SConverter {
679
679
  const sharedDataStr = JSON.stringify(sharedData);
680
680
  if (this.options.slpk) {
681
681
  const slpkSharedPath = (0, path_1.join)(childPath, 'shared');
682
- this.writeQueue.enqueue({
682
+ await this.writeQueue.enqueue({
683
683
  archiveKey: `${slpkChildPath}/shared/sharedResource.json.gz`,
684
684
  writePromise: (0, file_utils_1.writeFileForSlpk)(slpkSharedPath, sharedDataStr, 'sharedResource.json')
685
685
  });
686
686
  }
687
687
  else {
688
688
  const sharedPath = (0, path_1.join)(childPath, 'shared/');
689
- this.writeQueue.enqueue({ writePromise: (0, file_utils_1.writeFile)(sharedPath, sharedDataStr) });
689
+ await this.writeQueue.enqueue({ writePromise: (0, file_utils_1.writeFile)(sharedPath, sharedDataStr) });
690
690
  }
691
691
  }
692
692
  /**
@@ -744,14 +744,14 @@ class I3SConverter {
744
744
  if (this.options.slpk) {
745
745
  const slpkTexturePath = (0, path_1.join)(childPath, 'textures');
746
746
  const compress = false;
747
- this.writeQueue.enqueue({
747
+ await this.writeQueue.enqueue({
748
748
  archiveKey: `${slpkChildPath}/textures/${name}.${format}`,
749
749
  writePromise: (0, file_utils_1.writeFileForSlpk)(slpkTexturePath, textureData, `${name}.${format}`, compress)
750
750
  });
751
751
  }
752
752
  else {
753
753
  const texturePath = (0, path_1.join)(childPath, `textures/${name}/`);
754
- this.writeQueue.enqueue({
754
+ await this.writeQueue.enqueue({
755
755
  writePromise: (0, file_utils_1.writeFile)(texturePath, textureData, `index.${format}`)
756
756
  });
757
757
  }
@@ -769,14 +769,14 @@ class I3SConverter {
769
769
  const fileBuffer = new Uint8Array(attributes[index]);
770
770
  if (this.options.slpk) {
771
771
  const slpkAttributesPath = (0, path_1.join)(childPath, 'attributes', folderName);
772
- this.writeQueue.enqueue({
772
+ await this.writeQueue.enqueue({
773
773
  archiveKey: `${slpkChildPath}/attributes/${folderName}.bin.gz`,
774
774
  writePromise: (0, file_utils_1.writeFileForSlpk)(slpkAttributesPath, fileBuffer, '0.bin')
775
775
  });
776
776
  }
777
777
  else {
778
778
  const attributesPath = (0, path_1.join)(childPath, `attributes/${folderName}/0`);
779
- this.writeQueue.enqueue({
779
+ await this.writeQueue.enqueue({
780
780
  writePromise: (0, file_utils_1.writeFile)(attributesPath, fileBuffer, 'index.bin')
781
781
  });
782
782
  }
@@ -12,6 +12,7 @@ export default class WriteQueue<T extends WriteQueueItem> extends Queue<T> {
12
12
  listeningInterval: number;
13
13
  writeConcurrency: number;
14
14
  constructor(listeningInterval?: number, writeConcurrency?: number);
15
+ enqueue(val: T): Promise<void>;
15
16
  startListening(): void;
16
17
  stopListening(): void;
17
18
  startWrite(): Promise<void>;
@@ -1 +1 @@
1
- {"version":3,"file":"write-queue.d.ts","sourceRoot":"","sources":["../../../src/lib/utils/write-queue.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,KAAK,EAAC,MAAM,SAAS,CAAC;AAE9B,oBAAY,cAAc,GAAG;IAC3B,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,YAAY,EAAE,OAAO,CAAC,MAAM,CAAC,CAAC;CAC/B,CAAC;AAEF,MAAM,CAAC,OAAO,OAAO,UAAU,CAAC,CAAC,SAAS,cAAc,CAAE,SAAQ,KAAK,CAAC,CAAC,CAAC;IACxE,OAAO,CAAC,UAAU,CAAC,CAAiB;IAC7B,YAAY,EAAE,OAAO,CAAC,IAAI,CAAC,GAAG,IAAI,CAAQ;IAC1C,OAAO,EAAE;QAAC,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAAA;KAAC,CAAM;IACtC,iBAAiB,EAAE,MAAM,CAAC;IAC1B,gBAAgB,EAAE,MAAM,CAAC;gBAEpB,iBAAiB,GAAE,MAAa,EAAE,gBAAgB,GAAE,MAAY;IAM5E,cAAc;IAId,aAAa;IAMP,UAAU,IAAI,OAAO,CAAC,IAAI,CAAC;IAW3B,QAAQ,IAAI,OAAO,CAAC,IAAI,CAAC;YAKjB,OAAO;IAmBrB,OAAO,CAAC,aAAa;CAStB"}
1
+ {"version":3,"file":"write-queue.d.ts","sourceRoot":"","sources":["../../../src/lib/utils/write-queue.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,KAAK,EAAC,MAAM,SAAS,CAAC;AAM9B,oBAAY,cAAc,GAAG;IAC3B,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,YAAY,EAAE,OAAO,CAAC,MAAM,CAAC,CAAC;CAC/B,CAAC;AAEF,MAAM,CAAC,OAAO,OAAO,UAAU,CAAC,CAAC,SAAS,cAAc,CAAE,SAAQ,KAAK,CAAC,CAAC,CAAC;IACxE,OAAO,CAAC,UAAU,CAAC,CAAiB;IAC7B,YAAY,EAAE,OAAO,CAAC,IAAI,CAAC,GAAG,IAAI,CAAQ;IAC1C,OAAO,EAAE;QAAC,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAAA;KAAC,CAAM;IACtC,iBAAiB,EAAE,MAAM,CAAC;IAC1B,gBAAgB,EAAE,MAAM,CAAC;gBAEpB,iBAAiB,GAAE,MAAa,EAAE,gBAAgB,GAAE,MAAY;IAMtE,OAAO,CAAC,GAAG,EAAE,CAAC;IAQpB,cAAc;IAId,aAAa;IAMP,UAAU,IAAI,OAAO,CAAC,IAAI,CAAC;IAW3B,QAAQ,IAAI,OAAO,CAAC,IAAI,CAAC;YAKjB,OAAO;IAmBrB,OAAO,CAAC,aAAa;CAStB"}
@@ -1,6 +1,12 @@
1
1
  "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
2
5
  Object.defineProperty(exports, "__esModule", { value: true });
3
6
  const queue_1 = require("./queue");
7
+ const process_1 = __importDefault(require("process"));
8
+ /** Memory limit size is based on testing */
9
+ const MEMORY_LIMIT = 4 * 1024 * 1024 * 1024; // 4GB
4
10
  class WriteQueue extends queue_1.Queue {
5
11
  constructor(listeningInterval = 2000, writeConcurrency = 400) {
6
12
  super();
@@ -9,6 +15,13 @@ class WriteQueue extends queue_1.Queue {
9
15
  this.listeningInterval = listeningInterval;
10
16
  this.writeConcurrency = writeConcurrency;
11
17
  }
18
+ async enqueue(val) {
19
+ super.enqueue(val);
20
+ /** https://nodejs.org/docs/latest-v14.x/api/process.html#process_process_memoryusage */
21
+ if (process_1.default.memoryUsage().rss > MEMORY_LIMIT) {
22
+ await this.startWrite();
23
+ }
24
+ }
12
25
  startListening() {
13
26
  this.intervalId = setInterval(this.startWrite.bind(this), this.listeningInterval);
14
27
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@loaders.gl/tile-converter",
3
- "version": "3.2.5",
3
+ "version": "3.2.8",
4
4
  "description": "Converter",
5
5
  "license": "MIT",
6
6
  "publishConfig": {
@@ -43,19 +43,19 @@
43
43
  "build-3d-tiles-attributes-worker": "esbuild src/workers/3d-tiles-attributes-worker.ts --outfile=dist/3d-tiles-attributes-worker.js --platform=node --target=esnext,node12 --minify --bundle --sourcemap --define:__VERSION__=\\\"$npm_package_version\\\""
44
44
  },
45
45
  "dependencies": {
46
- "@loaders.gl/3d-tiles": "3.2.5",
47
- "@loaders.gl/crypto": "3.2.5",
48
- "@loaders.gl/draco": "3.2.5",
49
- "@loaders.gl/gltf": "3.2.5",
50
- "@loaders.gl/i3s": "3.2.5",
51
- "@loaders.gl/images": "3.2.5",
52
- "@loaders.gl/loader-utils": "3.2.5",
53
- "@loaders.gl/polyfills": "3.2.5",
54
- "@loaders.gl/schema": "3.2.5",
55
- "@loaders.gl/textures": "3.2.5",
56
- "@loaders.gl/tiles": "3.2.5",
57
- "@loaders.gl/worker-utils": "3.2.5",
58
- "@loaders.gl/zip": "3.2.5",
46
+ "@loaders.gl/3d-tiles": "3.2.8",
47
+ "@loaders.gl/crypto": "3.2.8",
48
+ "@loaders.gl/draco": "3.2.8",
49
+ "@loaders.gl/gltf": "3.2.8",
50
+ "@loaders.gl/i3s": "3.2.8",
51
+ "@loaders.gl/images": "3.2.8",
52
+ "@loaders.gl/loader-utils": "3.2.8",
53
+ "@loaders.gl/polyfills": "3.2.8",
54
+ "@loaders.gl/schema": "3.2.8",
55
+ "@loaders.gl/textures": "3.2.8",
56
+ "@loaders.gl/tiles": "3.2.8",
57
+ "@loaders.gl/worker-utils": "3.2.8",
58
+ "@loaders.gl/zip": "3.2.8",
59
59
  "@luma.gl/engine": "^8.5.4",
60
60
  "@math.gl/core": "^3.5.1",
61
61
  "@math.gl/culling": "^3.5.1",
@@ -75,5 +75,5 @@
75
75
  "peerDependencies": {
76
76
  "@loaders.gl/core": "^3.2.0"
77
77
  },
78
- "gitHead": "1c084200e8b87479d06526c7107e75c6bff8968b"
78
+ "gitHead": "93463b94d4b88799ef4152fcb39d68c9fa58b8fc"
79
79
  }
@@ -204,14 +204,14 @@ export default class NodePages {
204
204
  for (const [index, nodePage] of this.nodePages.entries()) {
205
205
  const nodePageStr = JSON.stringify(nodePage);
206
206
  const slpkPath = join(layers0Path, 'nodepages');
207
- writeQueue.enqueue({
207
+ await writeQueue.enqueue({
208
208
  archiveKey: `nodePages/${index.toString()}.json.gz`,
209
209
  writePromise: this.writeFile(slpkPath, nodePageStr, `${index.toString()}.json`)
210
210
  });
211
211
  }
212
212
  const metadata = transform({nodeCount: this.nodesCounter}, metadataTemplate());
213
213
  const compress = false;
214
- writeQueue.enqueue({
214
+ await writeQueue.enqueue({
215
215
  archiveKey: 'metadata.json',
216
216
  writePromise: this.writeFile(
217
217
  layers0Path,
@@ -224,7 +224,7 @@ export default class NodePages {
224
224
  for (const [index, nodePage] of this.nodePages.entries()) {
225
225
  const nodePageStr = JSON.stringify(nodePage);
226
226
  const nodePagePath = join(layers0Path, 'nodepages', index.toString());
227
- writeQueue.enqueue({writePromise: this.writeFile(nodePagePath, nodePageStr)});
227
+ await writeQueue.enqueue({writePromise: this.writeFile(nodePagePath, nodePageStr)});
228
228
  }
229
229
  }
230
230
  }
@@ -341,7 +341,7 @@ export default class I3SConverter {
341
341
  const childPath = join(this.layers0Path, 'nodes', child.path!);
342
342
 
343
343
  if (this.options.slpk) {
344
- this.writeQueue.enqueue({
344
+ await this.writeQueue.enqueue({
345
345
  archiveKey: 'nodes/1/3dNodeIndexDocument.json.gz',
346
346
  writePromise: writeFileForSlpk(
347
347
  childPath,
@@ -350,7 +350,7 @@ export default class I3SConverter {
350
350
  )
351
351
  });
352
352
  } else {
353
- this.writeQueue.enqueue({writePromise: writeFile(childPath, JSON.stringify(child))});
353
+ await this.writeQueue.enqueue({writePromise: writeFile(childPath, JSON.stringify(child))});
354
354
  }
355
355
  } else {
356
356
  await this._addChildrenWithNeighborsAndWriteFile({
@@ -368,7 +368,7 @@ export default class I3SConverter {
368
368
  */
369
369
  private async _writeLayers0(): Promise<void> {
370
370
  if (this.options.slpk) {
371
- this.writeQueue.enqueue({
371
+ await this.writeQueue.enqueue({
372
372
  archiveKey: '3dSceneLayer.json.gz',
373
373
  writePromise: writeFileForSlpk(
374
374
  this.layers0Path,
@@ -377,7 +377,7 @@ export default class I3SConverter {
377
377
  )
378
378
  });
379
379
  } else {
380
- this.writeQueue.enqueue({
380
+ await this.writeQueue.enqueue({
381
381
  writePromise: writeFile(this.layers0Path, JSON.stringify(this.layers0))
382
382
  });
383
383
  }
@@ -392,12 +392,12 @@ export default class I3SConverter {
392
392
  rootPath: string
393
393
  ): Promise<void> {
394
394
  if (this.options.slpk) {
395
- this.writeQueue.enqueue({
395
+ await this.writeQueue.enqueue({
396
396
  archiveKey: `nodes/${nodePath}/3dNodeIndexDocument.json.gz`,
397
397
  writePromise: writeFileForSlpk(rootPath, JSON.stringify(root0), '3dNodeIndexDocument.json')
398
398
  });
399
399
  } else {
400
- this.writeQueue.enqueue({writePromise: writeFile(rootPath, JSON.stringify(root0))});
400
+ await this.writeQueue.enqueue({writePromise: writeFile(rootPath, JSON.stringify(root0))});
401
401
  }
402
402
  }
403
403
 
@@ -856,13 +856,13 @@ export default class I3SConverter {
856
856
  ): Promise<void> {
857
857
  if (this.options.slpk) {
858
858
  const slpkGeometryPath = join(childPath, 'geometries');
859
- this.writeQueue.enqueue({
859
+ await this.writeQueue.enqueue({
860
860
  archiveKey: `${slpkChildPath}/geometries/0.bin.gz`,
861
861
  writePromise: writeFileForSlpk(slpkGeometryPath, geometryBuffer, '0.bin')
862
862
  });
863
863
  } else {
864
864
  const geometryPath = join(childPath, 'geometries/0/');
865
- this.writeQueue.enqueue({
865
+ await this.writeQueue.enqueue({
866
866
  writePromise: writeFile(geometryPath, geometryBuffer, 'index.bin')
867
867
  });
868
868
  }
@@ -870,13 +870,13 @@ export default class I3SConverter {
870
870
  if (this.options.draco) {
871
871
  if (this.options.slpk) {
872
872
  const slpkCompressedGeometryPath = join(childPath, 'geometries');
873
- this.writeQueue.enqueue({
873
+ await this.writeQueue.enqueue({
874
874
  archiveKey: `${slpkChildPath}/geometries/1.bin.gz`,
875
875
  writePromise: writeFileForSlpk(slpkCompressedGeometryPath, compressedGeometry, '1.bin')
876
876
  });
877
877
  } else {
878
878
  const compressedGeometryPath = join(childPath, 'geometries/1/');
879
- this.writeQueue.enqueue({
879
+ await this.writeQueue.enqueue({
880
880
  writePromise: writeFile(compressedGeometryPath, compressedGeometry, 'index.bin')
881
881
  });
882
882
  }
@@ -904,13 +904,13 @@ export default class I3SConverter {
904
904
  const sharedDataStr = JSON.stringify(sharedData);
905
905
  if (this.options.slpk) {
906
906
  const slpkSharedPath = join(childPath, 'shared');
907
- this.writeQueue.enqueue({
907
+ await this.writeQueue.enqueue({
908
908
  archiveKey: `${slpkChildPath}/shared/sharedResource.json.gz`,
909
909
  writePromise: writeFileForSlpk(slpkSharedPath, sharedDataStr, 'sharedResource.json')
910
910
  });
911
911
  } else {
912
912
  const sharedPath = join(childPath, 'shared/');
913
- this.writeQueue.enqueue({writePromise: writeFile(sharedPath, sharedDataStr)});
913
+ await this.writeQueue.enqueue({writePromise: writeFile(sharedPath, sharedDataStr)});
914
914
  }
915
915
  }
916
916
 
@@ -994,13 +994,13 @@ export default class I3SConverter {
994
994
  const slpkTexturePath = join(childPath, 'textures');
995
995
  const compress = false;
996
996
 
997
- this.writeQueue.enqueue({
997
+ await this.writeQueue.enqueue({
998
998
  archiveKey: `${slpkChildPath}/textures/${name}.${format}`,
999
999
  writePromise: writeFileForSlpk(slpkTexturePath, textureData, `${name}.${format}`, compress)
1000
1000
  });
1001
1001
  } else {
1002
1002
  const texturePath = join(childPath, `textures/${name}/`);
1003
- this.writeQueue.enqueue({
1003
+ await this.writeQueue.enqueue({
1004
1004
  writePromise: writeFile(texturePath, textureData, `index.${format}`)
1005
1005
  });
1006
1006
  }
@@ -1024,13 +1024,13 @@ export default class I3SConverter {
1024
1024
 
1025
1025
  if (this.options.slpk) {
1026
1026
  const slpkAttributesPath = join(childPath, 'attributes', folderName);
1027
- this.writeQueue.enqueue({
1027
+ await this.writeQueue.enqueue({
1028
1028
  archiveKey: `${slpkChildPath}/attributes/${folderName}.bin.gz`,
1029
1029
  writePromise: writeFileForSlpk(slpkAttributesPath, fileBuffer, '0.bin')
1030
1030
  });
1031
1031
  } else {
1032
1032
  const attributesPath = join(childPath, `attributes/${folderName}/0`);
1033
- this.writeQueue.enqueue({
1033
+ await this.writeQueue.enqueue({
1034
1034
  writePromise: writeFile(attributesPath, fileBuffer, 'index.bin')
1035
1035
  });
1036
1036
  }
@@ -1,4 +1,8 @@
1
1
  import {Queue} from './queue';
2
+ import process from 'process';
3
+
4
+ /** Memory limit size is based on testing */
5
+ const MEMORY_LIMIT = 4 * 1024 * 1024 * 1024; // 4GB
2
6
 
3
7
  export type WriteQueueItem = {
4
8
  archiveKey?: string;
@@ -18,6 +22,14 @@ export default class WriteQueue<T extends WriteQueueItem> extends Queue<T> {
18
22
  this.writeConcurrency = writeConcurrency;
19
23
  }
20
24
 
25
+ async enqueue(val: T) {
26
+ super.enqueue(val);
27
+ /** https://nodejs.org/docs/latest-v14.x/api/process.html#process_process_memoryusage */
28
+ if (process.memoryUsage().rss > MEMORY_LIMIT) {
29
+ await this.startWrite();
30
+ }
31
+ }
32
+
21
33
  startListening() {
22
34
  this.intervalId = setInterval(this.startWrite.bind(this), this.listeningInterval);
23
35
  }