@loaders.gl/tile-converter 4.0.0-alpha.14 → 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 (75) hide show
  1. package/bin/i3s-server.js +4 -0
  2. package/dist/converter.min.js +58 -58
  3. package/dist/dist.min.js +241 -127
  4. package/dist/es5/deps-installer/deps-installer.js +1 -1
  5. package/dist/es5/i3s-converter/i3s-converter.js +26 -22
  6. package/dist/es5/i3s-converter/i3s-converter.js.map +1 -1
  7. package/dist/es5/i3s-server/README.md +46 -2
  8. package/dist/es5/i3s-server/app.js +3 -3
  9. package/dist/es5/i3s-server/app.js.map +1 -1
  10. package/dist/es5/i3s-server/bin/www.js +61 -0
  11. package/dist/es5/i3s-server/bin/www.js.map +1 -0
  12. package/dist/es5/i3s-server/controllers/slpk-controller.js +14 -18
  13. package/dist/es5/i3s-server/controllers/slpk-controller.js.map +1 -1
  14. package/dist/es5/index.js +7 -0
  15. package/dist/es5/index.js.map +1 -1
  16. package/dist/es5/pgm-loader.js +1 -1
  17. package/dist/es5/slpk-extractor/helpers/file-handle-provider.js +59 -26
  18. package/dist/es5/slpk-extractor/helpers/file-handle-provider.js.map +1 -1
  19. package/dist/es5/slpk-extractor/helpers/fs-promises.js +77 -0
  20. package/dist/es5/slpk-extractor/helpers/fs-promises.js.map +1 -0
  21. package/dist/es5/slpk-extractor/slpk-extractor.js +7 -7
  22. package/dist/es5/slpk-extractor/slpk-extractor.js.map +1 -1
  23. package/dist/esm/deps-installer/deps-installer.js +1 -1
  24. package/dist/esm/i3s-converter/i3s-converter.js +5 -1
  25. package/dist/esm/i3s-converter/i3s-converter.js.map +1 -1
  26. package/dist/esm/i3s-server/README.md +46 -2
  27. package/dist/esm/i3s-server/app.js +4 -4
  28. package/dist/esm/i3s-server/app.js.map +1 -1
  29. package/dist/esm/i3s-server/bin/i3s-server.min.js +614 -0
  30. package/dist/esm/i3s-server/bin/{www → www.js} +12 -55
  31. package/dist/esm/i3s-server/bin/www.js.map +1 -0
  32. package/dist/esm/i3s-server/controllers/slpk-controller.js +6 -12
  33. package/dist/esm/i3s-server/controllers/slpk-controller.js.map +1 -1
  34. package/dist/esm/index.js +1 -0
  35. package/dist/esm/index.js.map +1 -1
  36. package/dist/esm/pgm-loader.js +1 -1
  37. package/dist/esm/slpk-extractor/helpers/file-handle-provider.js +17 -6
  38. package/dist/esm/slpk-extractor/helpers/file-handle-provider.js.map +1 -1
  39. package/dist/esm/slpk-extractor/helpers/fs-promises.js +32 -0
  40. package/dist/esm/slpk-extractor/helpers/fs-promises.js.map +1 -0
  41. package/dist/esm/slpk-extractor/slpk-extractor.js +2 -2
  42. package/dist/esm/slpk-extractor/slpk-extractor.js.map +1 -1
  43. package/dist/i3s-converter/i3s-converter.d.ts.map +1 -1
  44. package/dist/i3s-converter/i3s-converter.js +5 -1
  45. package/dist/i3s-server/app.d.ts.map +1 -1
  46. package/dist/i3s-server/app.js +1 -1
  47. package/dist/i3s-server/bin/www.d.ts +3 -0
  48. package/dist/i3s-server/bin/www.d.ts.map +1 -0
  49. package/dist/i3s-server/bin/www.js +83 -0
  50. package/dist/i3s-server/controllers/slpk-controller.d.ts.map +1 -1
  51. package/dist/i3s-server/controllers/slpk-controller.js +4 -9
  52. package/dist/index.d.ts +1 -0
  53. package/dist/index.d.ts.map +1 -1
  54. package/dist/index.js +3 -1
  55. package/dist/slpk-extractor/helpers/file-handle-provider.d.ts +15 -12
  56. package/dist/slpk-extractor/helpers/file-handle-provider.d.ts.map +1 -1
  57. package/dist/slpk-extractor/helpers/file-handle-provider.js +25 -10
  58. package/dist/slpk-extractor/helpers/fs-promises.d.ts +38 -0
  59. package/dist/slpk-extractor/helpers/fs-promises.d.ts.map +1 -0
  60. package/dist/slpk-extractor/helpers/fs-promises.js +51 -0
  61. package/dist/slpk-extractor/slpk-extractor.d.ts +2 -2
  62. package/dist/slpk-extractor/slpk-extractor.d.ts.map +1 -1
  63. package/dist/slpk-extractor/slpk-extractor.js +4 -7
  64. package/dist/slpk-extractor.min.js +44 -44
  65. package/package.json +21 -20
  66. package/src/i3s-converter/i3s-converter.ts +5 -1
  67. package/src/i3s-server/README.md +46 -2
  68. package/src/i3s-server/app.js +1 -1
  69. package/{dist/es5/i3s-server/bin/www → src/i3s-server/bin/www.js} +7 -7
  70. package/src/i3s-server/controllers/slpk-controller.js +4 -11
  71. package/src/index.ts +1 -0
  72. package/src/slpk-extractor/helpers/file-handle-provider.ts +36 -18
  73. package/src/slpk-extractor/helpers/fs-promises.ts +66 -0
  74. package/src/slpk-extractor/slpk-extractor.ts +5 -6
  75. package/src/i3s-server/bin/www +0 -102
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@loaders.gl/tile-converter",
3
- "version": "4.0.0-alpha.14",
3
+ "version": "4.0.0-alpha.15",
4
4
  "description": "Converter",
5
5
  "license": "MIT",
6
6
  "publishConfig": {
@@ -22,7 +22,7 @@
22
22
  "bin": {
23
23
  "tile-converter": "./bin/converter.js",
24
24
  "slpk-extractor": "./bin/slpk-extractor.js",
25
- "i3s-server": "./src/i3s-server/bin/www"
25
+ "i3s-server": "./bin/i3s-server.js"
26
26
  },
27
27
  "files": [
28
28
  "src",
@@ -38,24 +38,25 @@
38
38
  "join-images": false
39
39
  },
40
40
  "scripts": {
41
- "pre-build": "npm run build-bundle && npm run build-converter-bundle && npm run build-slpk-extractor-bundle",
41
+ "pre-build": "npm run build-bundle && npm run build-converter-bundle && npm run build-slpk-extractor-bundle && npm run build-i3s-server-bundle",
42
42
  "build-bundle": "esbuild ./src/index.ts --bundle --outfile=dist/dist.min.js --platform=node --external:join-images",
43
43
  "build-converter-bundle": "esbuild src/converter-cli.ts --outfile=dist/converter.min.js --platform=node --target=esnext,node14 --external:join-images --minify --bundle --define:__VERSION__=\\\"$npm_package_version\\\"",
44
- "build-slpk-extractor-bundle": "esbuild src/slpk-extractor-cli.ts --outfile=dist/slpk-extractor.min.js --platform=node --target=esnext,node14 --external:join-images --minify --bundle --define:__VERSION__=\\\"$npm_package_version\\\""
44
+ "build-slpk-extractor-bundle": "esbuild src/slpk-extractor-cli.ts --outfile=dist/slpk-extractor.min.js --platform=node --target=esnext,node14 --external:join-images --minify --bundle --define:__VERSION__=\\\"$npm_package_version\\\"",
45
+ "build-i3s-server-bundle": "esbuild src/i3s-server/bin/www.js --outfile=dist/esm/i3s-server/bin/i3s-server.min.js --platform=node --target=esnext,node14 --external:join-images --minify --bundle --define:__VERSION__=\\\"$npm_package_version\\\""
45
46
  },
46
47
  "dependencies": {
47
- "@loaders.gl/3d-tiles": "4.0.0-alpha.14",
48
- "@loaders.gl/crypto": "4.0.0-alpha.14",
49
- "@loaders.gl/draco": "4.0.0-alpha.14",
50
- "@loaders.gl/gltf": "4.0.0-alpha.14",
51
- "@loaders.gl/i3s": "4.0.0-alpha.14",
52
- "@loaders.gl/images": "4.0.0-alpha.14",
53
- "@loaders.gl/loader-utils": "4.0.0-alpha.14",
54
- "@loaders.gl/polyfills": "4.0.0-alpha.14",
55
- "@loaders.gl/textures": "4.0.0-alpha.14",
56
- "@loaders.gl/tiles": "4.0.0-alpha.14",
57
- "@loaders.gl/worker-utils": "4.0.0-alpha.14",
58
- "@loaders.gl/zip": "4.0.0-alpha.14",
48
+ "@loaders.gl/3d-tiles": "4.0.0-alpha.15",
49
+ "@loaders.gl/crypto": "4.0.0-alpha.15",
50
+ "@loaders.gl/draco": "4.0.0-alpha.15",
51
+ "@loaders.gl/gltf": "4.0.0-alpha.15",
52
+ "@loaders.gl/i3s": "4.0.0-alpha.15",
53
+ "@loaders.gl/images": "4.0.0-alpha.15",
54
+ "@loaders.gl/loader-utils": "4.0.0-alpha.15",
55
+ "@loaders.gl/polyfills": "4.0.0-alpha.15",
56
+ "@loaders.gl/textures": "4.0.0-alpha.15",
57
+ "@loaders.gl/tiles": "4.0.0-alpha.15",
58
+ "@loaders.gl/worker-utils": "4.0.0-alpha.15",
59
+ "@loaders.gl/zip": "4.0.0-alpha.15",
59
60
  "@math.gl/core": "^3.5.1",
60
61
  "@math.gl/culling": "^3.5.1",
61
62
  "@math.gl/geoid": "^3.5.1",
@@ -63,13 +64,13 @@
63
64
  "archiver": "^5.0.0",
64
65
  "cors": "^2.8.5",
65
66
  "crypt": "^0.0.2",
66
- "debug": "~2.6.9",
67
- "express": "~4.17.3",
67
+ "debug": "~4.3.4",
68
+ "express": "~4.18.2",
68
69
  "json-map-transform": "^1.2.6",
69
70
  "jszip": "^3.5.0",
70
71
  "md5": "^2.3.0",
71
72
  "morgan": "~1.9.1",
72
- "uuid": "^8.1.0"
73
+ "uuid": "^9.0.0"
73
74
  },
74
75
  "peerDependencies": {
75
76
  "@loaders.gl/core": "^4.0.0-alpha.8"
@@ -78,5 +79,5 @@
78
79
  "join-images": "^1.1.3",
79
80
  "sharp": "^0.31.3"
80
81
  },
81
- "gitHead": "dd885592142ad9c26fc38e0eb0a711cf4806345a"
82
+ "gitHead": "47467ab23c65917e4642730e99b5d005af333c76"
82
83
  }
@@ -240,10 +240,14 @@ export default class I3SConverter {
240
240
 
241
241
  try {
242
242
  const preloadOptions = await this._fetchPreloadOptions();
243
+ let tilesetUrl = inputUrl;
244
+ if (preloadOptions.url) {
245
+ tilesetUrl = preloadOptions.url;
246
+ }
243
247
  if (preloadOptions.headers) {
244
248
  this.loadOptions.fetch = {headers: preloadOptions.headers};
245
249
  }
246
- this.sourceTileset = await load(inputUrl, this.Loader, this.loadOptions);
250
+ this.sourceTileset = await load(tilesetUrl, this.Loader, this.loadOptions);
247
251
 
248
252
  const preprocessResult = await this.preprocessConversion();
249
253
 
@@ -8,12 +8,56 @@ The server provides I3S Rest endpoints per specification https://github.com/Esri
8
8
  ### Serve 3DTiles to I3S converted dataset
9
9
 
10
10
  - Convert data set from 3DTiles to I3S without `--slpk` option
11
- - Serve output folder `I3sLayerPath="./data/BatchedTextured" DEBUG=i3s-server:* npx i3s-server`
11
+ - Serve output folder
12
+
13
+ Example for path `./data/BatchTextured/SceneServer/layers/0/...`:
14
+
15
+ #### Start the server
16
+
17
+ ```bash
18
+ PORT=8080 HTTPS_PORT=4443 I3sLayerPath="./data" DEBUG=i3s-server:* npx i3s-server
19
+ ```
20
+ #### Check the layer availability
21
+
22
+ The layer should be available on URLs:
23
+
24
+ - `http://localhost:8080/BatchTextured/SceneServer/layers/0/...`
25
+ - `https://localhost:4443/BatchTextured/SceneServer/layers/0/...`
26
+
27
+ #### Open in ArcGIS
28
+
29
+ `https://www.arcgis.com/home/webscene/viewer.html?url=http://localhost:8080/BatchTextured/SceneServer/layers/0/`
30
+
31
+ #### Open in I3S Explorer
32
+
33
+ `https://i3s.loaders.gl/viewer?tileset=http://localhost:8080/BatchTextured/SceneServer/layers/0`
12
34
 
13
35
  ### Serve SLPK
14
36
 
15
- - Serve slpk file `I3sLayerPath="../datasets/Rancho_Mesh_mesh_v17_1.slpk" DEBUG=i3s-server:* npx i3s-server`
37
+ Example for path `../datasets/Rancho_Mesh_mesh_v17_1.slpk`:
38
+
39
+ #### Start the server
40
+
41
+ ```bash
42
+ PORT=8080 HTTPS_PORT=4443 I3sLayerPath="../datasets/Rancho_Mesh_mesh_v17_1.slpk" DEBUG=i3s-server:* npx i3s-server
43
+ ```
44
+ #### Check the layer availability
45
+
46
+ The layer should be available on URLs:
47
+
48
+ - `http://localhost:8080/SceneServer/layers/0/...`
49
+ - `https://localhost:4443/SceneServer/layers/0/...`
50
+
51
+ #### Open in ArcGIS
52
+
53
+ `https://www.arcgis.com/home/webscene/viewer.html?url=http://localhost:8080/SceneServer`
54
+
55
+ #### Open in I3S Explorer
56
+
57
+ `https://i3s.loaders.gl/viewer?tileset=http://localhost:8080/SceneServer/layers/0`
16
58
 
17
59
  ## ENV variables
18
60
 
19
61
  - `I3sLayerPath` - path to converted data or SLPK file.
62
+ - `PORT` - HTTP port. Eg for `PORT = 8080 npx i3s-server` the server will work on host `http://localhost:8080/...`. Default value is `80`;
63
+ - `HTTPS_PORT` - HTTPS port. Eg for `PORT = 4443 npx i3s-server` the server will work on host `https://localhost:4443/...`. Default value is `443`
@@ -4,7 +4,6 @@ const logger = require('morgan');
4
4
  const cors = require('cors');
5
5
 
6
6
  const indexRouter = require('./routes/index');
7
- const {sceneServerRouter, router} = require('./routes/slpk-router');
8
7
 
9
8
  const I3S_LAYER_PATH = process.env.I3sLayerPath || ''; // eslint-disable-line no-process-env, no-undef
10
9
  const app = express();
@@ -16,6 +15,7 @@ app.use(express.static(path.join(__dirname, 'public')));
16
15
  app.use(cors());
17
16
 
18
17
  if (/\.slpk$/.test(I3S_LAYER_PATH)) {
18
+ const {sceneServerRouter, router} = require('./routes/slpk-router');
19
19
  app.use('/SceneServer/layers/0', router);
20
20
  app.use('/SceneServer', sceneServerRouter);
21
21
  } else {
@@ -72,22 +72,22 @@ function formErrorHandler(optionalPort) {
72
72
  throw error;
73
73
  }
74
74
 
75
- const bind = typeof port === 'string' ? `Pipe ${optionalPort}`: `Port ${optionalPort}`;
75
+ const bind = typeof global.port === 'string' ? `Pipe ${optionalPort}` : `Port ${optionalPort}`;
76
76
 
77
77
  // handle specific listen errors with friendly messages
78
78
  switch (error.code) {
79
79
  case 'EACCES':
80
- console.error(`${bind} requires elevated privileges`);// eslint-disable-line no-console, no-undef
81
- process.exit(1);// eslint-disable-line no-process-exit, no-undef
80
+ console.error(`${bind} requires elevated privileges`); // eslint-disable-line no-console, no-undef
81
+ process.exit(1); // eslint-disable-line no-process-exit, no-undef
82
82
  break;
83
83
  case 'EADDRINUSE':
84
- console.error(`${bind} is already in use`);// eslint-disable-line no-console, no-undef
85
- process.exit(1);// eslint-disable-line no-process-exit, no-undef
84
+ console.error(`${bind} is already in use`); // eslint-disable-line no-console, no-undef
85
+ process.exit(1); // eslint-disable-line no-process-exit, no-undef
86
86
  break;
87
87
  default:
88
88
  throw error;
89
89
  }
90
- }
90
+ };
91
91
  }
92
92
 
93
93
  /**
@@ -98,5 +98,5 @@ function formListeningHandler(optionalServer) {
98
98
  const addr = optionalServer.address();
99
99
  const bind = typeof addr === 'string' ? `pipe ${addr}` : `port ${addr.port}`;
100
100
  debug(`Listening on ${bind}`);
101
- }
101
+ };
102
102
  }
@@ -1,12 +1,12 @@
1
1
  require('@loaders.gl/polyfills');
2
- const {fetchFile, parse} = require('@loaders.gl/core');
3
- const {SLPKLoader} = require('@loaders.gl/i3s');
2
+ const {parseSLPK} = require('@loaders.gl/i3s');
4
3
  const path = require('path');
4
+ const {FileHandleProvider} = require('@loaders.gl/tile-converter');
5
5
 
6
6
  let slpkArchive;
7
7
 
8
8
  const loadArchive = async (fullLayerPath) => {
9
- slpkArchive = await (await fetchFile(fullLayerPath)).arrayBuffer();
9
+ slpkArchive = await parseSLPK(await FileHandleProvider.from(fullLayerPath));
10
10
  };
11
11
 
12
12
  const I3S_LAYER_PATH = process.env.I3sLayerPath || ''; // eslint-disable-line no-process-env, no-undef
@@ -19,14 +19,7 @@ async function getFileByUrl(url) {
19
19
  let uncompressedFile;
20
20
  if (trimmedPath) {
21
21
  try {
22
- uncompressedFile = Buffer.from(
23
- await parse(slpkArchive, SLPKLoader, {
24
- slpk: {
25
- path: trimmedPath[1],
26
- pathMode: 'http'
27
- }
28
- })
29
- );
22
+ uncompressedFile = Buffer.from(await slpkArchive.getFile(trimmedPath[1], 'http'));
30
23
  } catch (e) {}
31
24
  }
32
25
  return uncompressedFile;
package/src/index.ts CHANGED
@@ -1,2 +1,3 @@
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';
@@ -1,5 +1,5 @@
1
1
  import {FileProvider} from '@loaders.gl/i3s';
2
- import {promises as fsPromises, PathLike} from 'fs';
2
+ import {FileHandle} from './fs-promises';
3
3
 
4
4
  /**
5
5
  * Provides file data using node fs library
@@ -9,31 +9,31 @@ export class FileHandleProvider implements FileProvider {
9
9
  * Returns a new copy of FileHandleProvider
10
10
  * @param path The path to the file in file system
11
11
  */
12
- static async from(path: PathLike): Promise<FileHandleProvider> {
13
- const fileDescriptor = await fsPromises.open(path);
14
- return new FileHandleProvider(fileDescriptor, (await fileDescriptor.stat()).size);
12
+ static async from(path: string): Promise<FileHandleProvider> {
13
+ const fileDescriptor = await FileHandle.open(path);
14
+ return new FileHandleProvider(fileDescriptor, fileDescriptor.stat.size);
15
15
  }
16
16
 
17
17
  /**
18
18
  * The FileHandle from which data is provided
19
19
  */
20
- private fileDescriptor: fsPromises.FileHandle;
20
+ private fileDescriptor: FileHandle;
21
21
 
22
22
  /**
23
23
  * The file length in bytes
24
24
  */
25
- private size: number;
25
+ private size: bigint;
26
26
 
27
- private constructor(fileDescriptor: fsPromises.FileHandle, size: number) {
27
+ private constructor(fileDescriptor: FileHandle, size: bigint) {
28
28
  this.fileDescriptor = fileDescriptor;
29
29
  this.size = size;
30
30
  }
31
31
 
32
32
  /**
33
- * Gets an unsigned 8-bit integer (unsigned byte) at the specified byte offset from the start of the file.
33
+ * Gets an unsigned 8-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
- async getUint8(offset: number): Promise<number> {
36
+ async getUint8(offset: bigint): Promise<number> {
37
37
  const val = new Uint8Array(
38
38
  (await this.fileDescriptor.read(Buffer.alloc(1), 0, 1, offset)).buffer.buffer
39
39
  ).at(0);
@@ -44,10 +44,10 @@ export class FileHandleProvider implements FileProvider {
44
44
  }
45
45
 
46
46
  /**
47
- * Gets an unsigned 16-bit integer (unsigned byte) at the specified byte offset from the start of the file.
47
+ * Gets an unsigned 16-bit integer at the specified byte offset from the start of the file.
48
48
  * @param offset The offset, in bytes, from the start of the file where to read the data.
49
49
  */
50
- async getUint16(offset: number): Promise<number> {
50
+ async getUint16(offset: bigint): Promise<number> {
51
51
  const val = new Uint16Array(
52
52
  (await this.fileDescriptor.read(Buffer.alloc(2), 0, 2, offset)).buffer.buffer
53
53
  ).at(0);
@@ -58,10 +58,10 @@ export class FileHandleProvider implements FileProvider {
58
58
  }
59
59
 
60
60
  /**
61
- * Gets an unsigned 32-bit integer (unsigned byte) at the specified byte offset from the start of the file.
61
+ * Gets an unsigned 32-bit integer at the specified byte offset from the start of the file.
62
62
  * @param offset The offset, in bytes, from the start of the file where to read the data.
63
63
  */
64
- async getUint32(offset: number): Promise<number> {
64
+ async getUint32(offset: bigint): Promise<number> {
65
65
  const val = new Uint32Array(
66
66
  (await this.fileDescriptor.read(Buffer.alloc(4), 0, 4, offset)).buffer.buffer
67
67
  ).at(0);
@@ -71,21 +71,39 @@ export class FileHandleProvider implements FileProvider {
71
71
  return val;
72
72
  }
73
73
 
74
+ /**
75
+ * Gets an unsigned 32-bit integer at the specified byte offset from the start of the file.
76
+ * @param offset The offset, in bytes, from the start of the file where to read the data.
77
+ */
78
+ async getBigUint64(offset: bigint): Promise<bigint> {
79
+ const val = new BigInt64Array(
80
+ (await this.fileDescriptor.read(Buffer.alloc(8), 0, 4, offset)).buffer.buffer
81
+ ).at(0);
82
+ if (val === undefined) {
83
+ throw new Error('something went wrong');
84
+ }
85
+ return val;
86
+ }
87
+
74
88
  /**
75
89
  * returns an ArrayBuffer whose contents are a copy of this file bytes from startOffset, inclusive, up to endOffset, exclusive.
76
- * @param startOffset The offset, in bytes, from the start of the file where to start reading the data.
90
+ * @param startOffsset The offset, in byte, from the start of the file where to start reading the data.
77
91
  * @param endOffset The offset, in bytes, from the start of the file where to end reading the data.
78
92
  */
79
- async slice(startOffset: number, endOffset: number): Promise<ArrayBuffer> {
80
- const length = endOffset - startOffset;
81
- return (await this.fileDescriptor.read(Buffer.alloc(length), 0, length, startOffset)).buffer
93
+ async slice(startOffsset: bigint, endOffset: bigint): Promise<ArrayBuffer> {
94
+ const bigLength = endOffset - startOffsset;
95
+ if (bigLength > Number.MAX_SAFE_INTEGER) {
96
+ throw new Error('too big slice');
97
+ }
98
+ const length = Number(bigLength);
99
+ return (await this.fileDescriptor.read(Buffer.alloc(length), 0, length, startOffsset)).buffer
82
100
  .buffer;
83
101
  }
84
102
 
85
103
  /**
86
104
  * the length (in bytes) of the data.
87
105
  */
88
- get length(): number {
106
+ get length(): bigint {
89
107
  return this.size;
90
108
  }
91
109
  }
@@ -0,0 +1,66 @@
1
+ import {read, open, stat, BigIntStats} from 'fs';
2
+
3
+ /** file reading result */
4
+ export type FileReadResult = {
5
+ /** amount of the bytes read */
6
+ bytesRead: number;
7
+ /** the buffer filled with data from file*/
8
+ buffer: Buffer;
9
+ };
10
+
11
+ /** Object handling file info */
12
+ export class FileHandle {
13
+ private fileDescriptor: number;
14
+ private stats: BigIntStats;
15
+ private constructor(fileDescriptor: number, stats: BigIntStats) {
16
+ this.fileDescriptor = fileDescriptor;
17
+ this.stats = stats;
18
+ }
19
+ /**
20
+ * Opens a `FileHandle`.
21
+ *
22
+ * @param path path to the file
23
+ * @return Fulfills with a {FileHandle} object.
24
+ */
25
+
26
+ static open = async (path: string): Promise<FileHandle> => {
27
+ const [fd, stats] = await Promise.all([
28
+ new Promise<number>((s) => {
29
+ open(path, undefined, undefined, (_err, fd) => s(fd));
30
+ }),
31
+ new Promise<BigIntStats>((s) => {
32
+ stat(path, {bigint: true}, (_err, stats) => s(stats));
33
+ })
34
+ ]);
35
+ return new FileHandle(fd, stats);
36
+ };
37
+
38
+ /**
39
+ * Reads data from the file and stores that in the given buffer.
40
+ *
41
+ * If the file is not modified concurrently, the end-of-file is reached when the
42
+ * number of bytes read is zero.
43
+ * @param buffer A buffer that will be filled with the file data read.
44
+ * @param offset The location in the buffer at which to start filling.
45
+ * @param length The number of bytes to read.
46
+ * @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
47
+ * integer, the current file position will remain unchanged.
48
+ * @return Fulfills upon success with a FileReadResult object
49
+ */
50
+ read = (
51
+ buffer: Buffer,
52
+ offset: number,
53
+ length: number,
54
+ position: number | bigint
55
+ ): Promise<FileReadResult> => {
56
+ return new Promise((s) => {
57
+ read(this.fileDescriptor, buffer, offset, length, position, (_err, bytesRead, buffer) =>
58
+ s({bytesRead, buffer})
59
+ );
60
+ });
61
+ };
62
+
63
+ get stat(): BigIntStats {
64
+ return this.stats;
65
+ }
66
+ }
@@ -7,9 +7,6 @@ import {path} from '@loaders.gl/loader-utils';
7
7
  import {GZipCompression} from '@loaders.gl/compression';
8
8
  import {writeFile} from '../lib/utils/file-utils';
9
9
 
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',
@@ -27,9 +24,9 @@ type File = {
27
24
  /**
28
25
  * Converter from slpk to i3s
29
26
  */
30
- export default class SLPKExtractor {
27
+ export default class SLPKConverter {
31
28
  /**
32
- * extract slpk to i3s
29
+ * Extract slpk to i3s
33
30
  * @param options
34
31
  * @param options.inputUrl the url to read SLPK file
35
32
  * @param options.outputPath the output filename
@@ -43,7 +40,7 @@ export default class SLPKExtractor {
43
40
 
44
41
  const provider = await FileHandleProvider.from(inputUrl);
45
42
 
46
- let localHeader = await parseZipLocalFileHeader(0, provider);
43
+ let localHeader = await parseZipLocalFileHeader(0n, provider);
47
44
  while (localHeader) {
48
45
  await this.writeFile(
49
46
  await this.unGzip({
@@ -68,6 +65,7 @@ export default class SLPKExtractor {
68
65
  * Defines file name and path for i3s format
69
66
  * @param fileName initial file name and path
70
67
  */
68
+
71
69
  private correctIndexNames(fileName: string): string | null {
72
70
  if (indexNames.includes(path.filename(path.join('/', fileName)))) {
73
71
  return path.join(path.dirname(fileName), 'index.json.gz');
@@ -85,6 +83,7 @@ export default class SLPKExtractor {
85
83
  const compression = new GZipCompression();
86
84
 
87
85
  const decompressedData = await compression.decompress(file.data);
86
+
88
87
  return {data: decompressedData, name: (file.name ?? '').slice(0, -3)};
89
88
  }
90
89
  return Promise.resolve(file);
@@ -1,102 +0,0 @@
1
- #!/usr/bin/env node
2
-
3
- /**
4
- * Module dependencies.
5
- */
6
-
7
- const app = require('../app');
8
- const debug = require('debug')('i3s-server:server');
9
- const https = require('https');
10
- const http = require('http');
11
- const fs = require('fs');
12
- const path = require('path');
13
-
14
- /**
15
- * Get port from environment and store in Express.
16
- */
17
-
18
- const httpPort = normalizePort(process.env.PORT || '80'); // eslint-disable-line no-process-env, no-undef
19
- const httpsPort = normalizePort(process.env.HTTPS_PORT || '443'); // eslint-disable-line no-process-env, no-undef
20
-
21
- /**
22
- * Create HTTP server.
23
- */
24
-
25
- const options = {
26
- key: fs.readFileSync(path.join(__dirname, '../certs/key.pem')),
27
- cert: fs.readFileSync(path.join(__dirname, '../certs/cert.pem'))
28
- };
29
-
30
- const httpServer = http.createServer(app);
31
- const httpsServer = https.createServer(options, app);
32
-
33
- /**
34
- * Listen on provided port, on all network interfaces.
35
- */
36
-
37
- httpServer.listen(httpPort);
38
- httpServer.on('error', formErrorHandler(httpPort));
39
- httpServer.on('listening', formListeningHandler(httpServer));
40
-
41
- httpsServer.listen(httpsPort);
42
- httpsServer.on('error', formErrorHandler(httpsPort));
43
- httpsServer.on('listening', formListeningHandler(httpsServer));
44
-
45
- /**
46
- * Normalize a port into a number, string, or false.
47
- */
48
-
49
- function normalizePort(val) {
50
- const chkPort = parseInt(val, 10);
51
-
52
- if (isNaN(chkPort)) {
53
- // named pipe
54
- return val;
55
- }
56
-
57
- if (chkPort >= 0) {
58
- // port number
59
- return chkPort;
60
- }
61
-
62
- return false;
63
- }
64
-
65
- /**
66
- * Event listener for HTTP/HTTPS server "error" event.
67
- */
68
-
69
- function formErrorHandler(optionalPort) {
70
- return function onError(error) {
71
- if (error.syscall !== 'listen') {
72
- throw error;
73
- }
74
-
75
- const bind = typeof port === 'string' ? `Pipe ${optionalPort}`: `Port ${optionalPort}`;
76
-
77
- // handle specific listen errors with friendly messages
78
- switch (error.code) {
79
- case 'EACCES':
80
- console.error(`${bind} requires elevated privileges`);// eslint-disable-line no-console, no-undef
81
- process.exit(1);// eslint-disable-line no-process-exit, no-undef
82
- break;
83
- case 'EADDRINUSE':
84
- console.error(`${bind} is already in use`);// eslint-disable-line no-console, no-undef
85
- process.exit(1);// eslint-disable-line no-process-exit, no-undef
86
- break;
87
- default:
88
- throw error;
89
- }
90
- }
91
- }
92
-
93
- /**
94
- * Event listener for HTTP/HTTPS server "listening" event.
95
- */
96
- function formListeningHandler(optionalServer) {
97
- return function onListening() {
98
- const addr = optionalServer.address();
99
- const bind = typeof addr === 'string' ? `pipe ${addr}` : `port ${addr.port}`;
100
- debug(`Listening on ${bind}`);
101
- }
102
- }