@loaders.gl/tile-converter 4.0.0-alpha.13 → 4.0.0-alpha.15

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 (142) hide show
  1. package/bin/i3s-server.js +4 -0
  2. package/dist/3d-tiles-converter/3d-tiles-converter.d.ts +0 -1
  3. package/dist/3d-tiles-converter/3d-tiles-converter.d.ts.map +1 -1
  4. package/dist/3d-tiles-converter/3d-tiles-converter.js +8 -19
  5. package/dist/3d-tiles-converter/helpers/b3dm-converter.d.ts +4 -1
  6. package/dist/3d-tiles-converter/helpers/b3dm-converter.d.ts.map +1 -1
  7. package/dist/converter.min.js +65 -65
  8. package/dist/dist.min.js +881 -261
  9. package/dist/es5/3d-tiles-converter/3d-tiles-converter.js +34 -67
  10. package/dist/es5/3d-tiles-converter/3d-tiles-converter.js.map +1 -1
  11. package/dist/es5/3d-tiles-converter/helpers/b3dm-converter.js.map +1 -1
  12. package/dist/es5/deps-installer/deps-installer.js +1 -1
  13. package/dist/es5/i3s-converter/helpers/batch-ids-extensions.js.map +1 -1
  14. package/dist/es5/i3s-converter/helpers/geometry-converter.js.map +1 -1
  15. package/dist/es5/i3s-converter/helpers/gltf-attributes.js.map +1 -1
  16. package/dist/es5/i3s-converter/i3s-converter.js +36 -43
  17. package/dist/es5/i3s-converter/i3s-converter.js.map +1 -1
  18. package/dist/es5/i3s-converter/types.js.map +1 -1
  19. package/dist/es5/i3s-server/README.md +46 -2
  20. package/dist/es5/i3s-server/app.js +3 -3
  21. package/dist/es5/i3s-server/app.js.map +1 -1
  22. package/dist/es5/i3s-server/bin/www.js +61 -0
  23. package/dist/es5/i3s-server/bin/www.js.map +1 -0
  24. package/dist/es5/i3s-server/controllers/slpk-controller.js +14 -18
  25. package/dist/es5/i3s-server/controllers/slpk-controller.js.map +1 -1
  26. package/dist/es5/index.js +7 -0
  27. package/dist/es5/index.js.map +1 -1
  28. package/dist/es5/pgm-loader.js +1 -1
  29. package/dist/es5/slpk-extractor/helpers/file-handle-provider.js +59 -26
  30. package/dist/es5/slpk-extractor/helpers/file-handle-provider.js.map +1 -1
  31. package/dist/es5/slpk-extractor/helpers/fs-promises.js +77 -0
  32. package/dist/es5/slpk-extractor/helpers/fs-promises.js.map +1 -0
  33. package/dist/es5/slpk-extractor/slpk-extractor.js +7 -7
  34. package/dist/es5/slpk-extractor/slpk-extractor.js.map +1 -1
  35. package/dist/esm/3d-tiles-converter/3d-tiles-converter.js +8 -18
  36. package/dist/esm/3d-tiles-converter/3d-tiles-converter.js.map +1 -1
  37. package/dist/esm/3d-tiles-converter/helpers/b3dm-converter.js.map +1 -1
  38. package/dist/esm/deps-installer/deps-installer.js +1 -1
  39. package/dist/esm/i3s-converter/helpers/batch-ids-extensions.js.map +1 -1
  40. package/dist/esm/i3s-converter/helpers/geometry-converter.js.map +1 -1
  41. package/dist/esm/i3s-converter/helpers/gltf-attributes.js.map +1 -1
  42. package/dist/esm/i3s-converter/i3s-converter.js +5 -8
  43. package/dist/esm/i3s-converter/i3s-converter.js.map +1 -1
  44. package/dist/esm/i3s-converter/types.js.map +1 -1
  45. package/dist/esm/i3s-server/README.md +46 -2
  46. package/dist/esm/i3s-server/app.js +4 -4
  47. package/dist/esm/i3s-server/app.js.map +1 -1
  48. package/dist/esm/i3s-server/bin/i3s-server.min.js +614 -0
  49. package/{src/i3s-server/bin/www → dist/esm/i3s-server/bin/www.js} +12 -55
  50. package/dist/esm/i3s-server/bin/www.js.map +1 -0
  51. package/dist/esm/i3s-server/controllers/slpk-controller.js +6 -12
  52. package/dist/esm/i3s-server/controllers/slpk-controller.js.map +1 -1
  53. package/dist/esm/index.js +1 -0
  54. package/dist/esm/index.js.map +1 -1
  55. package/dist/esm/pgm-loader.js +1 -1
  56. package/dist/esm/slpk-extractor/helpers/file-handle-provider.js +17 -6
  57. package/dist/esm/slpk-extractor/helpers/file-handle-provider.js.map +1 -1
  58. package/dist/esm/slpk-extractor/helpers/fs-promises.js +32 -0
  59. package/dist/esm/slpk-extractor/helpers/fs-promises.js.map +1 -0
  60. package/dist/esm/slpk-extractor/slpk-extractor.js +2 -2
  61. package/dist/esm/slpk-extractor/slpk-extractor.js.map +1 -1
  62. package/dist/i3s-converter/helpers/batch-ids-extensions.d.ts +1 -1
  63. package/dist/i3s-converter/helpers/batch-ids-extensions.d.ts.map +1 -1
  64. package/dist/i3s-converter/helpers/geometry-converter.d.ts +2 -3
  65. package/dist/i3s-converter/helpers/geometry-converter.d.ts.map +1 -1
  66. package/dist/i3s-converter/helpers/gltf-attributes.d.ts +2 -2
  67. package/dist/i3s-converter/helpers/gltf-attributes.d.ts.map +1 -1
  68. package/dist/i3s-converter/i3s-converter.d.ts.map +1 -1
  69. package/dist/i3s-converter/i3s-converter.js +5 -6
  70. package/dist/i3s-converter/types.d.ts +32 -1
  71. package/dist/i3s-converter/types.d.ts.map +1 -1
  72. package/dist/i3s-server/app.d.ts.map +1 -1
  73. package/dist/i3s-server/app.js +1 -1
  74. package/dist/i3s-server/bin/www.d.ts +3 -0
  75. package/dist/i3s-server/bin/www.d.ts.map +1 -0
  76. package/dist/i3s-server/bin/www.js +83 -0
  77. package/dist/i3s-server/controllers/slpk-controller.d.ts.map +1 -1
  78. package/dist/i3s-server/controllers/slpk-controller.js +4 -9
  79. package/dist/index.d.ts +1 -0
  80. package/dist/index.d.ts.map +1 -1
  81. package/dist/index.js +3 -1
  82. package/dist/slpk-extractor/helpers/file-handle-provider.d.ts +15 -12
  83. package/dist/slpk-extractor/helpers/file-handle-provider.d.ts.map +1 -1
  84. package/dist/slpk-extractor/helpers/file-handle-provider.js +25 -10
  85. package/dist/slpk-extractor/helpers/fs-promises.d.ts +38 -0
  86. package/dist/slpk-extractor/helpers/fs-promises.d.ts.map +1 -0
  87. package/dist/slpk-extractor/helpers/fs-promises.js +51 -0
  88. package/dist/slpk-extractor/slpk-extractor.d.ts +2 -2
  89. package/dist/slpk-extractor/slpk-extractor.d.ts.map +1 -1
  90. package/dist/slpk-extractor/slpk-extractor.js +4 -7
  91. package/dist/slpk-extractor.min.js +44 -44
  92. package/package.json +20 -21
  93. package/src/3d-tiles-converter/3d-tiles-converter.ts +10 -28
  94. package/src/3d-tiles-converter/helpers/b3dm-converter.ts +5 -2
  95. package/src/i3s-converter/helpers/batch-ids-extensions.ts +1 -1
  96. package/src/i3s-converter/helpers/geometry-converter.ts +2 -7
  97. package/src/i3s-converter/helpers/gltf-attributes.ts +2 -2
  98. package/src/i3s-converter/i3s-converter.ts +5 -6
  99. package/src/i3s-converter/types.ts +32 -1
  100. package/src/i3s-server/README.md +46 -2
  101. package/src/i3s-server/app.js +1 -1
  102. package/{dist/es5/i3s-server/bin/www → src/i3s-server/bin/www.js} +7 -7
  103. package/src/i3s-server/controllers/slpk-controller.js +4 -11
  104. package/src/index.ts +1 -0
  105. package/src/slpk-extractor/helpers/file-handle-provider.ts +36 -18
  106. package/src/slpk-extractor/helpers/fs-promises.ts +66 -0
  107. package/src/slpk-extractor/slpk-extractor.ts +5 -6
  108. package/dist/3d-tiles-attributes-worker.d.ts +0 -28
  109. package/dist/3d-tiles-attributes-worker.d.ts.map +0 -1
  110. package/dist/3d-tiles-attributes-worker.js +0 -3
  111. package/dist/3d-tiles-attributes-worker.js.map +0 -7
  112. package/dist/es5/3d-tiles-attributes-worker.js +0 -25
  113. package/dist/es5/3d-tiles-attributes-worker.js.map +0 -1
  114. package/dist/es5/i3s-attributes-worker.js +0 -25
  115. package/dist/es5/i3s-attributes-worker.js.map +0 -1
  116. package/dist/es5/workers/3d-tiles-attributes-worker.js +0 -28
  117. package/dist/es5/workers/3d-tiles-attributes-worker.js.map +0 -1
  118. package/dist/es5/workers/i3s-attributes-worker.js +0 -30
  119. package/dist/es5/workers/i3s-attributes-worker.js.map +0 -1
  120. package/dist/esm/3d-tiles-attributes-worker.js +0 -16
  121. package/dist/esm/3d-tiles-attributes-worker.js.map +0 -1
  122. package/dist/esm/i3s-attributes-worker.js +0 -16
  123. package/dist/esm/i3s-attributes-worker.js.map +0 -1
  124. package/dist/esm/i3s-server/bin/www +0 -102
  125. package/dist/esm/workers/3d-tiles-attributes-worker.js +0 -8
  126. package/dist/esm/workers/3d-tiles-attributes-worker.js.map +0 -1
  127. package/dist/esm/workers/i3s-attributes-worker.js +0 -7
  128. package/dist/esm/workers/i3s-attributes-worker.js.map +0 -1
  129. package/dist/i3s-attributes-worker.d.ts +0 -45
  130. package/dist/i3s-attributes-worker.d.ts.map +0 -1
  131. package/dist/i3s-attributes-worker.js +0 -9
  132. package/dist/i3s-attributes-worker.js.map +0 -7
  133. package/dist/workers/3d-tiles-attributes-worker.d.ts +0 -2
  134. package/dist/workers/3d-tiles-attributes-worker.d.ts.map +0 -1
  135. package/dist/workers/3d-tiles-attributes-worker.js +0 -9
  136. package/dist/workers/i3s-attributes-worker.d.ts +0 -2
  137. package/dist/workers/i3s-attributes-worker.d.ts.map +0 -1
  138. package/dist/workers/i3s-attributes-worker.js +0 -5
  139. package/src/3d-tiles-attributes-worker.ts +0 -43
  140. package/src/i3s-attributes-worker.ts +0 -59
  141. package/src/workers/3d-tiles-attributes-worker.ts +0 -6
  142. package/src/workers/i3s-attributes-worker.ts +0 -7
@@ -0,0 +1,83 @@
1
+ #!/usr/bin/env node
2
+ "use strict";
3
+ /**
4
+ * Module dependencies.
5
+ */
6
+ const app = require('../app');
7
+ const debug = require('debug')('i3s-server:server');
8
+ const https = require('https');
9
+ const http = require('http');
10
+ const fs = require('fs');
11
+ const path = require('path');
12
+ /**
13
+ * Get port from environment and store in Express.
14
+ */
15
+ const httpPort = normalizePort(process.env.PORT || '80'); // eslint-disable-line no-process-env, no-undef
16
+ const httpsPort = normalizePort(process.env.HTTPS_PORT || '443'); // eslint-disable-line no-process-env, no-undef
17
+ /**
18
+ * Create HTTP server.
19
+ */
20
+ const options = {
21
+ key: fs.readFileSync(path.join(__dirname, '../certs/key.pem')),
22
+ cert: fs.readFileSync(path.join(__dirname, '../certs/cert.pem'))
23
+ };
24
+ const httpServer = http.createServer(app);
25
+ const httpsServer = https.createServer(options, app);
26
+ /**
27
+ * Listen on provided port, on all network interfaces.
28
+ */
29
+ httpServer.listen(httpPort);
30
+ httpServer.on('error', formErrorHandler(httpPort));
31
+ httpServer.on('listening', formListeningHandler(httpServer));
32
+ httpsServer.listen(httpsPort);
33
+ httpsServer.on('error', formErrorHandler(httpsPort));
34
+ httpsServer.on('listening', formListeningHandler(httpsServer));
35
+ /**
36
+ * Normalize a port into a number, string, or false.
37
+ */
38
+ function normalizePort(val) {
39
+ const chkPort = parseInt(val, 10);
40
+ if (isNaN(chkPort)) {
41
+ // named pipe
42
+ return val;
43
+ }
44
+ if (chkPort >= 0) {
45
+ // port number
46
+ return chkPort;
47
+ }
48
+ return false;
49
+ }
50
+ /**
51
+ * Event listener for HTTP/HTTPS server "error" event.
52
+ */
53
+ function formErrorHandler(optionalPort) {
54
+ return function onError(error) {
55
+ if (error.syscall !== 'listen') {
56
+ throw error;
57
+ }
58
+ const bind = typeof global.port === 'string' ? `Pipe ${optionalPort}` : `Port ${optionalPort}`;
59
+ // handle specific listen errors with friendly messages
60
+ switch (error.code) {
61
+ case 'EACCES':
62
+ console.error(`${bind} requires elevated privileges`); // eslint-disable-line no-console, no-undef
63
+ process.exit(1); // eslint-disable-line no-process-exit, no-undef
64
+ break;
65
+ case 'EADDRINUSE':
66
+ console.error(`${bind} is already in use`); // eslint-disable-line no-console, no-undef
67
+ process.exit(1); // eslint-disable-line no-process-exit, no-undef
68
+ break;
69
+ default:
70
+ throw error;
71
+ }
72
+ };
73
+ }
74
+ /**
75
+ * Event listener for HTTP/HTTPS server "listening" event.
76
+ */
77
+ function formListeningHandler(optionalServer) {
78
+ return function onListening() {
79
+ const addr = optionalServer.address();
80
+ const bind = typeof addr === 'string' ? `pipe ${addr}` : `port ${addr.port}`;
81
+ debug(`Listening on ${bind}`);
82
+ };
83
+ }
@@ -1 +1 @@
1
- {"version":3,"file":"slpk-controller.d.ts","sourceRoot":"","sources":["../../../src/i3s-server/controllers/slpk-controller.js"],"names":[],"mappings":"AAOA,+DAEC;AAOD,oEAgBC"}
1
+ {"version":3,"file":"slpk-controller.d.ts","sourceRoot":"","sources":["../../../src/i3s-server/controllers/slpk-controller.js"],"names":[],"mappings":"AAOA,+DAEC;AAOD,oEASC"}
@@ -1,11 +1,11 @@
1
1
  "use strict";
2
2
  require('@loaders.gl/polyfills');
3
- const { fetchFile, parse } = require('@loaders.gl/core');
4
- const { SLPKLoader } = require('@loaders.gl/i3s');
3
+ const { parseSLPK } = require('@loaders.gl/i3s');
5
4
  const path = require('path');
5
+ const { FileHandleProvider } = require('@loaders.gl/tile-converter');
6
6
  let slpkArchive;
7
7
  const loadArchive = async (fullLayerPath) => {
8
- slpkArchive = await (await fetchFile(fullLayerPath)).arrayBuffer();
8
+ slpkArchive = await parseSLPK(await FileHandleProvider.from(fullLayerPath));
9
9
  };
10
10
  const I3S_LAYER_PATH = process.env.I3sLayerPath || ''; // eslint-disable-line no-process-env, no-undef
11
11
  const FULL_LAYER_PATH = path.join(process.cwd(), I3S_LAYER_PATH); // eslint-disable-line no-undef
@@ -15,12 +15,7 @@ async function getFileByUrl(url) {
15
15
  let uncompressedFile;
16
16
  if (trimmedPath) {
17
17
  try {
18
- uncompressedFile = Buffer.from(await parse(slpkArchive, SLPKLoader, {
19
- slpk: {
20
- path: trimmedPath[1],
21
- pathMode: 'http'
22
- }
23
- }));
18
+ uncompressedFile = Buffer.from(await slpkArchive.getFile(trimmedPath[1], 'http'));
24
19
  }
25
20
  catch (e) { }
26
21
  }
package/dist/index.d.ts CHANGED
@@ -1,3 +1,4 @@
1
1
  export { default as I3SConverter } from './i3s-converter/i3s-converter';
2
2
  export { default as Tiles3DConverter } from './3d-tiles-converter/3d-tiles-converter';
3
+ export { FileHandleProvider } from './slpk-extractor/helpers/file-handle-provider';
3
4
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,OAAO,IAAI,YAAY,EAAC,MAAM,+BAA+B,CAAC;AACtE,OAAO,EAAC,OAAO,IAAI,gBAAgB,EAAC,MAAM,yCAAyC,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,OAAO,IAAI,YAAY,EAAC,MAAM,+BAA+B,CAAC;AACtE,OAAO,EAAC,OAAO,IAAI,gBAAgB,EAAC,MAAM,yCAAyC,CAAC;AACpF,OAAO,EAAC,kBAAkB,EAAC,MAAM,+CAA+C,CAAC"}
package/dist/index.js CHANGED
@@ -3,8 +3,10 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.Tiles3DConverter = exports.I3SConverter = void 0;
6
+ exports.FileHandleProvider = exports.Tiles3DConverter = exports.I3SConverter = void 0;
7
7
  var i3s_converter_1 = require("./i3s-converter/i3s-converter");
8
8
  Object.defineProperty(exports, "I3SConverter", { enumerable: true, get: function () { return __importDefault(i3s_converter_1).default; } });
9
9
  var _3d_tiles_converter_1 = require("./3d-tiles-converter/3d-tiles-converter");
10
10
  Object.defineProperty(exports, "Tiles3DConverter", { enumerable: true, get: function () { return __importDefault(_3d_tiles_converter_1).default; } });
11
+ var file_handle_provider_1 = require("./slpk-extractor/helpers/file-handle-provider");
12
+ Object.defineProperty(exports, "FileHandleProvider", { enumerable: true, get: function () { return file_handle_provider_1.FileHandleProvider; } });
@@ -1,6 +1,4 @@
1
- /// <reference types="node" />
2
1
  import { FileProvider } from '@loaders.gl/i3s';
3
- import { PathLike } from 'fs';
4
2
  /**
5
3
  * Provides file data using node fs library
6
4
  */
@@ -9,7 +7,7 @@ export declare class FileHandleProvider implements FileProvider {
9
7
  * Returns a new copy of FileHandleProvider
10
8
  * @param path The path to the file in file system
11
9
  */
12
- static from(path: PathLike): Promise<FileHandleProvider>;
10
+ static from(path: string): Promise<FileHandleProvider>;
13
11
  /**
14
12
  * The FileHandle from which data is provided
15
13
  */
@@ -20,29 +18,34 @@ export declare class FileHandleProvider implements FileProvider {
20
18
  private size;
21
19
  private constructor();
22
20
  /**
23
- * Gets an unsigned 8-bit integer (unsigned byte) at the specified byte offset from the start of the file.
21
+ * Gets an unsigned 8-bit integer at the specified byte offset from the start of the file.
24
22
  * @param offset The offset, in bytes, from the start of the file where to read the data.
25
23
  */
26
- getUint8(offset: number): Promise<number>;
24
+ getUint8(offset: bigint): Promise<number>;
27
25
  /**
28
- * Gets an unsigned 16-bit integer (unsigned byte) at the specified byte offset from the start of the file.
26
+ * Gets an unsigned 16-bit integer at the specified byte offset from the start of the file.
29
27
  * @param offset The offset, in bytes, from the start of the file where to read the data.
30
28
  */
31
- getUint16(offset: number): Promise<number>;
29
+ getUint16(offset: bigint): Promise<number>;
32
30
  /**
33
- * Gets an unsigned 32-bit integer (unsigned byte) at the specified byte offset from the start of the file.
31
+ * Gets an unsigned 32-bit integer at the specified byte offset from the start of the file.
34
32
  * @param offset The offset, in bytes, from the start of the file where to read the data.
35
33
  */
36
- getUint32(offset: number): Promise<number>;
34
+ getUint32(offset: bigint): Promise<number>;
35
+ /**
36
+ * Gets an unsigned 32-bit integer at the specified byte offset from the start of the file.
37
+ * @param offset The offset, in bytes, from the start of the file where to read the data.
38
+ */
39
+ getBigUint64(offset: bigint): Promise<bigint>;
37
40
  /**
38
41
  * returns an ArrayBuffer whose contents are a copy of this file bytes from startOffset, inclusive, up to endOffset, exclusive.
39
- * @param startOffset The offset, in bytes, from the start of the file where to start reading the data.
42
+ * @param startOffsset The offset, in byte, from the start of the file where to start reading the data.
40
43
  * @param endOffset The offset, in bytes, from the start of the file where to end reading the data.
41
44
  */
42
- slice(startOffset: number, endOffset: number): Promise<ArrayBuffer>;
45
+ slice(startOffsset: bigint, endOffset: bigint): Promise<ArrayBuffer>;
43
46
  /**
44
47
  * the length (in bytes) of the data.
45
48
  */
46
- get length(): number;
49
+ get length(): bigint;
47
50
  }
48
51
  //# sourceMappingURL=file-handle-provider.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"file-handle-provider.d.ts","sourceRoot":"","sources":["../../../src/slpk-extractor/helpers/file-handle-provider.ts"],"names":[],"mappings":";AAAA,OAAO,EAAC,YAAY,EAAC,MAAM,iBAAiB,CAAC;AAC7C,OAAO,EAAyB,QAAQ,EAAC,MAAM,IAAI,CAAC;AAEpD;;GAEG;AACH,qBAAa,kBAAmB,YAAW,YAAY;IACrD;;;OAGG;WACU,IAAI,CAAC,IAAI,EAAE,QAAQ,GAAG,OAAO,CAAC,kBAAkB,CAAC;IAK9D;;OAEG;IACH,OAAO,CAAC,cAAc,CAAwB;IAE9C;;OAEG;IACH,OAAO,CAAC,IAAI,CAAS;IAErB,OAAO;IAKP;;;OAGG;IACG,QAAQ,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;IAU/C;;;OAGG;IACG,SAAS,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;IAUhD;;;OAGG;IACG,SAAS,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;IAUhD;;;;OAIG;IACG,KAAK,CAAC,WAAW,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,GAAG,OAAO,CAAC,WAAW,CAAC;IAMzE;;OAEG;IACH,IAAI,MAAM,IAAI,MAAM,CAEnB;CACF"}
1
+ {"version":3,"file":"file-handle-provider.d.ts","sourceRoot":"","sources":["../../../src/slpk-extractor/helpers/file-handle-provider.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,YAAY,EAAC,MAAM,iBAAiB,CAAC;AAG7C;;GAEG;AACH,qBAAa,kBAAmB,YAAW,YAAY;IACrD;;;OAGG;WACU,IAAI,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,kBAAkB,CAAC;IAK5D;;OAEG;IACH,OAAO,CAAC,cAAc,CAAa;IAEnC;;OAEG;IACH,OAAO,CAAC,IAAI,CAAS;IAErB,OAAO;IAKP;;;OAGG;IACG,QAAQ,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;IAU/C;;;OAGG;IACG,SAAS,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;IAUhD;;;OAGG;IACG,SAAS,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;IAUhD;;;OAGG;IACG,YAAY,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;IAUnD;;;;OAIG;IACG,KAAK,CAAC,YAAY,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,GAAG,OAAO,CAAC,WAAW,CAAC;IAU1E;;OAEG;IACH,IAAI,MAAM,IAAI,MAAM,CAEnB;CACF"}
@@ -1,7 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.FileHandleProvider = void 0;
4
- const fs_1 = require("fs");
4
+ const fs_promises_1 = require("./fs-promises");
5
5
  /**
6
6
  * Provides file data using node fs library
7
7
  */
@@ -11,15 +11,15 @@ class FileHandleProvider {
11
11
  * @param path The path to the file in file system
12
12
  */
13
13
  static async from(path) {
14
- const fileDescriptor = await fs_1.promises.open(path);
15
- return new FileHandleProvider(fileDescriptor, (await fileDescriptor.stat()).size);
14
+ const fileDescriptor = await fs_promises_1.FileHandle.open(path);
15
+ return new FileHandleProvider(fileDescriptor, fileDescriptor.stat.size);
16
16
  }
17
17
  constructor(fileDescriptor, size) {
18
18
  this.fileDescriptor = fileDescriptor;
19
19
  this.size = size;
20
20
  }
21
21
  /**
22
- * Gets an unsigned 8-bit integer (unsigned byte) at the specified byte offset from the start of the file.
22
+ * Gets an unsigned 8-bit integer at the specified byte offset from the start of the file.
23
23
  * @param offset The offset, in bytes, from the start of the file where to read the data.
24
24
  */
25
25
  async getUint8(offset) {
@@ -30,7 +30,7 @@ class FileHandleProvider {
30
30
  return val;
31
31
  }
32
32
  /**
33
- * Gets an unsigned 16-bit integer (unsigned byte) at the specified byte offset from the start of the file.
33
+ * Gets an unsigned 16-bit integer at the specified byte offset from the start of the file.
34
34
  * @param offset The offset, in bytes, from the start of the file where to read the data.
35
35
  */
36
36
  async getUint16(offset) {
@@ -41,7 +41,7 @@ class FileHandleProvider {
41
41
  return val;
42
42
  }
43
43
  /**
44
- * Gets an unsigned 32-bit integer (unsigned byte) at the specified byte offset from the start of the file.
44
+ * Gets an unsigned 32-bit integer at the specified byte offset from the start of the file.
45
45
  * @param offset The offset, in bytes, from the start of the file where to read the data.
46
46
  */
47
47
  async getUint32(offset) {
@@ -51,14 +51,29 @@ class FileHandleProvider {
51
51
  }
52
52
  return val;
53
53
  }
54
+ /**
55
+ * Gets an unsigned 32-bit integer at the specified byte offset from the start of the file.
56
+ * @param offset The offset, in bytes, from the start of the file where to read the data.
57
+ */
58
+ async getBigUint64(offset) {
59
+ const val = new BigInt64Array((await this.fileDescriptor.read(Buffer.alloc(8), 0, 4, offset)).buffer.buffer).at(0);
60
+ if (val === undefined) {
61
+ throw new Error('something went wrong');
62
+ }
63
+ return val;
64
+ }
54
65
  /**
55
66
  * returns an ArrayBuffer whose contents are a copy of this file bytes from startOffset, inclusive, up to endOffset, exclusive.
56
- * @param startOffset The offset, in bytes, from the start of the file where to start reading the data.
67
+ * @param startOffsset The offset, in byte, from the start of the file where to start reading the data.
57
68
  * @param endOffset The offset, in bytes, from the start of the file where to end reading the data.
58
69
  */
59
- async slice(startOffset, endOffset) {
60
- const length = endOffset - startOffset;
61
- return (await this.fileDescriptor.read(Buffer.alloc(length), 0, length, startOffset)).buffer
70
+ async slice(startOffsset, endOffset) {
71
+ const bigLength = endOffset - startOffsset;
72
+ if (bigLength > Number.MAX_SAFE_INTEGER) {
73
+ throw new Error('too big slice');
74
+ }
75
+ const length = Number(bigLength);
76
+ return (await this.fileDescriptor.read(Buffer.alloc(length), 0, length, startOffsset)).buffer
62
77
  .buffer;
63
78
  }
64
79
  /**
@@ -0,0 +1,38 @@
1
+ /// <reference types="node" />
2
+ /// <reference types="node" />
3
+ import { BigIntStats } from 'fs';
4
+ /** file reading result */
5
+ export type FileReadResult = {
6
+ /** amount of the bytes read */
7
+ bytesRead: number;
8
+ /** the buffer filled with data from file*/
9
+ buffer: Buffer;
10
+ };
11
+ /** Object handling file info */
12
+ export declare class FileHandle {
13
+ private fileDescriptor;
14
+ private stats;
15
+ private constructor();
16
+ /**
17
+ * Opens a `FileHandle`.
18
+ *
19
+ * @param path path to the file
20
+ * @return Fulfills with a {FileHandle} object.
21
+ */
22
+ static open: (path: string) => Promise<FileHandle>;
23
+ /**
24
+ * Reads data from the file and stores that in the given buffer.
25
+ *
26
+ * If the file is not modified concurrently, the end-of-file is reached when the
27
+ * number of bytes read is zero.
28
+ * @param buffer A buffer that will be filled with the file data read.
29
+ * @param offset The location in the buffer at which to start filling.
30
+ * @param length The number of bytes to read.
31
+ * @param position The location where to begin reading data from the file. If `null`, data will be read from the current file position, and the position will be updated. If `position` is an
32
+ * integer, the current file position will remain unchanged.
33
+ * @return Fulfills upon success with a FileReadResult object
34
+ */
35
+ read: (buffer: Buffer, offset: number, length: number, position: number | bigint) => Promise<FileReadResult>;
36
+ get stat(): BigIntStats;
37
+ }
38
+ //# sourceMappingURL=fs-promises.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"fs-promises.d.ts","sourceRoot":"","sources":["../../../src/slpk-extractor/helpers/fs-promises.ts"],"names":[],"mappings":";;AAAA,OAAO,EAAmB,WAAW,EAAC,MAAM,IAAI,CAAC;AAEjD,0BAA0B;AAC1B,MAAM,MAAM,cAAc,GAAG;IAC3B,+BAA+B;IAC/B,SAAS,EAAE,MAAM,CAAC;IAClB,2CAA2C;IAC3C,MAAM,EAAE,MAAM,CAAC;CAChB,CAAC;AAEF,gCAAgC;AAChC,qBAAa,UAAU;IACrB,OAAO,CAAC,cAAc,CAAS;IAC/B,OAAO,CAAC,KAAK,CAAc;IAC3B,OAAO;IAIP;;;;;OAKG;IAEH,MAAM,CAAC,IAAI,SAAgB,MAAM,KAAG,QAAQ,UAAU,CAAC,CAUrD;IAEF;;;;;;;;;;;OAWG;IACH,IAAI,WACM,MAAM,UACN,MAAM,UACN,MAAM,YACJ,MAAM,GAAG,MAAM,KACxB,QAAQ,cAAc,CAAC,CAMxB;IAEF,IAAI,IAAI,IAAI,WAAW,CAEtB;CACF"}
@@ -0,0 +1,51 @@
1
+ "use strict";
2
+ var _a;
3
+ Object.defineProperty(exports, "__esModule", { value: true });
4
+ exports.FileHandle = void 0;
5
+ const fs_1 = require("fs");
6
+ /** Object handling file info */
7
+ class FileHandle {
8
+ constructor(fileDescriptor, stats) {
9
+ /**
10
+ * Reads data from the file and stores that in the given buffer.
11
+ *
12
+ * If the file is not modified concurrently, the end-of-file is reached when the
13
+ * number of bytes read is zero.
14
+ * @param buffer A buffer that will be filled with the file data read.
15
+ * @param offset The location in the buffer at which to start filling.
16
+ * @param length The number of bytes to read.
17
+ * @param position The location where to begin reading data from the file. If `null`, data will be read from the current file position, and the position will be updated. If `position` is an
18
+ * integer, the current file position will remain unchanged.
19
+ * @return Fulfills upon success with a FileReadResult object
20
+ */
21
+ this.read = (buffer, offset, length, position) => {
22
+ return new Promise((s) => {
23
+ (0, fs_1.read)(this.fileDescriptor, buffer, offset, length, position, (_err, bytesRead, buffer) => s({ bytesRead, buffer }));
24
+ });
25
+ };
26
+ this.fileDescriptor = fileDescriptor;
27
+ this.stats = stats;
28
+ }
29
+ get stat() {
30
+ return this.stats;
31
+ }
32
+ }
33
+ exports.FileHandle = FileHandle;
34
+ _a = FileHandle;
35
+ /**
36
+ * Opens a `FileHandle`.
37
+ *
38
+ * @param path path to the file
39
+ * @return Fulfills with a {FileHandle} object.
40
+ */
41
+ FileHandle.open = async (path) => {
42
+ const [fd, stats] = await Promise.all([
43
+ new Promise((s) => {
44
+ (0, fs_1.open)(path, undefined, undefined, (_err, fd) => s(fd));
45
+ }),
46
+ new Promise((s) => {
47
+ (0, fs_1.stat)(path, { bigint: true }, (_err, stats) => s(stats));
48
+ })
49
+ ]);
50
+ return new FileHandle(fd, stats);
51
+ };
@@ -1,9 +1,9 @@
1
1
  /**
2
2
  * Converter from slpk to i3s
3
3
  */
4
- export default class SLPKExtractor {
4
+ export default class SLPKConverter {
5
5
  /**
6
- * extract slpk to i3s
6
+ * Extract slpk to i3s
7
7
  * @param options
8
8
  * @param options.inputUrl the url to read SLPK file
9
9
  * @param options.outputPath the output filename
@@ -1 +1 @@
1
- {"version":3,"file":"slpk-extractor.d.ts","sourceRoot":"","sources":["../../src/slpk-extractor/slpk-extractor.ts"],"names":[],"mappings":"AA0BA;;GAEG;AACH,MAAM,CAAC,OAAO,OAAO,aAAa;IAChC;;;;;OAKG;IACU,OAAO,CAAC,OAAO,EAAE;QAAC,QAAQ,EAAE,MAAM,CAAC;QAAC,UAAU,EAAE,MAAM,CAAA;KAAC,GAAG,OAAO,CAAC,MAAM,CAAC;IA8BtF;;;OAGG;IACH,OAAO,CAAC,iBAAiB;YAYX,MAAM;YAUN,SAAS;CASxB"}
1
+ {"version":3,"file":"slpk-extractor.d.ts","sourceRoot":"","sources":["../../src/slpk-extractor/slpk-extractor.ts"],"names":[],"mappings":"AAuBA;;GAEG;AACH,MAAM,CAAC,OAAO,OAAO,aAAa;IAChC;;;;;OAKG;IACU,OAAO,CAAC,OAAO,EAAE;QAAC,QAAQ,EAAE,MAAM,CAAC;QAAC,UAAU,EAAE,MAAM,CAAA;KAAC,GAAG,OAAO,CAAC,MAAM,CAAC;IA8BtF;;;OAGG;IAEH,OAAO,CAAC,iBAAiB;YAYX,MAAM;YAWN,SAAS;CASxB"}
@@ -7,9 +7,6 @@ const i3s_1 = require("@loaders.gl/i3s");
7
7
  const loader_utils_1 = require("@loaders.gl/loader-utils");
8
8
  const compression_1 = require("@loaders.gl/compression");
9
9
  const file_utils_1 = require("../lib/utils/file-utils");
10
- /**
11
- * names of files that should be changed to index
12
- */
13
10
  const indexNames = [
14
11
  '3dSceneLayer.json.gz',
15
12
  '3dNodeIndexDocument.json.gz',
@@ -18,9 +15,9 @@ const indexNames = [
18
15
  /**
19
16
  * Converter from slpk to i3s
20
17
  */
21
- class SLPKExtractor {
18
+ class SLPKConverter {
22
19
  /**
23
- * extract slpk to i3s
20
+ * Extract slpk to i3s
24
21
  * @param options
25
22
  * @param options.inputUrl the url to read SLPK file
26
23
  * @param options.outputPath the output filename
@@ -32,7 +29,7 @@ class SLPKExtractor {
32
29
  }
33
30
  const { inputUrl } = options;
34
31
  const provider = await file_handle_provider_1.FileHandleProvider.from(inputUrl);
35
- let localHeader = await (0, i3s_1.parseZipLocalFileHeader)(0, provider);
32
+ let localHeader = await (0, i3s_1.parseZipLocalFileHeader)(0n, provider);
36
33
  while (localHeader) {
37
34
  await this.writeFile(await this.unGzip({
38
35
  name: this.correctIndexNames(localHeader.fileName),
@@ -75,4 +72,4 @@ class SLPKExtractor {
75
72
  await (0, file_utils_1.writeFile)(dirName, options.data, fileName);
76
73
  }
77
74
  }
78
- exports.default = SLPKExtractor;
75
+ exports.default = SLPKConverter;