@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.
- package/bin/i3s-server.js +4 -0
- package/dist/3d-tiles-converter/3d-tiles-converter.d.ts +0 -1
- package/dist/3d-tiles-converter/3d-tiles-converter.d.ts.map +1 -1
- package/dist/3d-tiles-converter/3d-tiles-converter.js +8 -19
- package/dist/3d-tiles-converter/helpers/b3dm-converter.d.ts +4 -1
- package/dist/3d-tiles-converter/helpers/b3dm-converter.d.ts.map +1 -1
- package/dist/converter.min.js +65 -65
- package/dist/dist.min.js +881 -261
- package/dist/es5/3d-tiles-converter/3d-tiles-converter.js +34 -67
- package/dist/es5/3d-tiles-converter/3d-tiles-converter.js.map +1 -1
- package/dist/es5/3d-tiles-converter/helpers/b3dm-converter.js.map +1 -1
- package/dist/es5/deps-installer/deps-installer.js +1 -1
- package/dist/es5/i3s-converter/helpers/batch-ids-extensions.js.map +1 -1
- package/dist/es5/i3s-converter/helpers/geometry-converter.js.map +1 -1
- package/dist/es5/i3s-converter/helpers/gltf-attributes.js.map +1 -1
- package/dist/es5/i3s-converter/i3s-converter.js +36 -43
- package/dist/es5/i3s-converter/i3s-converter.js.map +1 -1
- package/dist/es5/i3s-converter/types.js.map +1 -1
- package/dist/es5/i3s-server/README.md +46 -2
- package/dist/es5/i3s-server/app.js +3 -3
- package/dist/es5/i3s-server/app.js.map +1 -1
- package/dist/es5/i3s-server/bin/www.js +61 -0
- package/dist/es5/i3s-server/bin/www.js.map +1 -0
- package/dist/es5/i3s-server/controllers/slpk-controller.js +14 -18
- package/dist/es5/i3s-server/controllers/slpk-controller.js.map +1 -1
- package/dist/es5/index.js +7 -0
- package/dist/es5/index.js.map +1 -1
- package/dist/es5/pgm-loader.js +1 -1
- package/dist/es5/slpk-extractor/helpers/file-handle-provider.js +59 -26
- package/dist/es5/slpk-extractor/helpers/file-handle-provider.js.map +1 -1
- package/dist/es5/slpk-extractor/helpers/fs-promises.js +77 -0
- package/dist/es5/slpk-extractor/helpers/fs-promises.js.map +1 -0
- package/dist/es5/slpk-extractor/slpk-extractor.js +7 -7
- package/dist/es5/slpk-extractor/slpk-extractor.js.map +1 -1
- package/dist/esm/3d-tiles-converter/3d-tiles-converter.js +8 -18
- package/dist/esm/3d-tiles-converter/3d-tiles-converter.js.map +1 -1
- package/dist/esm/3d-tiles-converter/helpers/b3dm-converter.js.map +1 -1
- package/dist/esm/deps-installer/deps-installer.js +1 -1
- package/dist/esm/i3s-converter/helpers/batch-ids-extensions.js.map +1 -1
- package/dist/esm/i3s-converter/helpers/geometry-converter.js.map +1 -1
- package/dist/esm/i3s-converter/helpers/gltf-attributes.js.map +1 -1
- package/dist/esm/i3s-converter/i3s-converter.js +5 -8
- package/dist/esm/i3s-converter/i3s-converter.js.map +1 -1
- package/dist/esm/i3s-converter/types.js.map +1 -1
- package/dist/esm/i3s-server/README.md +46 -2
- package/dist/esm/i3s-server/app.js +4 -4
- package/dist/esm/i3s-server/app.js.map +1 -1
- package/dist/esm/i3s-server/bin/i3s-server.min.js +614 -0
- package/{src/i3s-server/bin/www → dist/esm/i3s-server/bin/www.js} +12 -55
- package/dist/esm/i3s-server/bin/www.js.map +1 -0
- package/dist/esm/i3s-server/controllers/slpk-controller.js +6 -12
- package/dist/esm/i3s-server/controllers/slpk-controller.js.map +1 -1
- package/dist/esm/index.js +1 -0
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/pgm-loader.js +1 -1
- package/dist/esm/slpk-extractor/helpers/file-handle-provider.js +17 -6
- package/dist/esm/slpk-extractor/helpers/file-handle-provider.js.map +1 -1
- package/dist/esm/slpk-extractor/helpers/fs-promises.js +32 -0
- package/dist/esm/slpk-extractor/helpers/fs-promises.js.map +1 -0
- package/dist/esm/slpk-extractor/slpk-extractor.js +2 -2
- package/dist/esm/slpk-extractor/slpk-extractor.js.map +1 -1
- package/dist/i3s-converter/helpers/batch-ids-extensions.d.ts +1 -1
- package/dist/i3s-converter/helpers/batch-ids-extensions.d.ts.map +1 -1
- package/dist/i3s-converter/helpers/geometry-converter.d.ts +2 -3
- package/dist/i3s-converter/helpers/geometry-converter.d.ts.map +1 -1
- package/dist/i3s-converter/helpers/gltf-attributes.d.ts +2 -2
- package/dist/i3s-converter/helpers/gltf-attributes.d.ts.map +1 -1
- package/dist/i3s-converter/i3s-converter.d.ts.map +1 -1
- package/dist/i3s-converter/i3s-converter.js +5 -6
- package/dist/i3s-converter/types.d.ts +32 -1
- package/dist/i3s-converter/types.d.ts.map +1 -1
- package/dist/i3s-server/app.d.ts.map +1 -1
- package/dist/i3s-server/app.js +1 -1
- package/dist/i3s-server/bin/www.d.ts +3 -0
- package/dist/i3s-server/bin/www.d.ts.map +1 -0
- package/dist/i3s-server/bin/www.js +83 -0
- package/dist/i3s-server/controllers/slpk-controller.d.ts.map +1 -1
- package/dist/i3s-server/controllers/slpk-controller.js +4 -9
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3 -1
- package/dist/slpk-extractor/helpers/file-handle-provider.d.ts +15 -12
- package/dist/slpk-extractor/helpers/file-handle-provider.d.ts.map +1 -1
- package/dist/slpk-extractor/helpers/file-handle-provider.js +25 -10
- package/dist/slpk-extractor/helpers/fs-promises.d.ts +38 -0
- package/dist/slpk-extractor/helpers/fs-promises.d.ts.map +1 -0
- package/dist/slpk-extractor/helpers/fs-promises.js +51 -0
- package/dist/slpk-extractor/slpk-extractor.d.ts +2 -2
- package/dist/slpk-extractor/slpk-extractor.d.ts.map +1 -1
- package/dist/slpk-extractor/slpk-extractor.js +4 -7
- package/dist/slpk-extractor.min.js +44 -44
- package/package.json +20 -21
- package/src/3d-tiles-converter/3d-tiles-converter.ts +10 -28
- package/src/3d-tiles-converter/helpers/b3dm-converter.ts +5 -2
- package/src/i3s-converter/helpers/batch-ids-extensions.ts +1 -1
- package/src/i3s-converter/helpers/geometry-converter.ts +2 -7
- package/src/i3s-converter/helpers/gltf-attributes.ts +2 -2
- package/src/i3s-converter/i3s-converter.ts +5 -6
- package/src/i3s-converter/types.ts +32 -1
- package/src/i3s-server/README.md +46 -2
- package/src/i3s-server/app.js +1 -1
- package/{dist/es5/i3s-server/bin/www → src/i3s-server/bin/www.js} +7 -7
- package/src/i3s-server/controllers/slpk-controller.js +4 -11
- package/src/index.ts +1 -0
- package/src/slpk-extractor/helpers/file-handle-provider.ts +36 -18
- package/src/slpk-extractor/helpers/fs-promises.ts +66 -0
- package/src/slpk-extractor/slpk-extractor.ts +5 -6
- package/dist/3d-tiles-attributes-worker.d.ts +0 -28
- package/dist/3d-tiles-attributes-worker.d.ts.map +0 -1
- package/dist/3d-tiles-attributes-worker.js +0 -3
- package/dist/3d-tiles-attributes-worker.js.map +0 -7
- package/dist/es5/3d-tiles-attributes-worker.js +0 -25
- package/dist/es5/3d-tiles-attributes-worker.js.map +0 -1
- package/dist/es5/i3s-attributes-worker.js +0 -25
- package/dist/es5/i3s-attributes-worker.js.map +0 -1
- package/dist/es5/workers/3d-tiles-attributes-worker.js +0 -28
- package/dist/es5/workers/3d-tiles-attributes-worker.js.map +0 -1
- package/dist/es5/workers/i3s-attributes-worker.js +0 -30
- package/dist/es5/workers/i3s-attributes-worker.js.map +0 -1
- package/dist/esm/3d-tiles-attributes-worker.js +0 -16
- package/dist/esm/3d-tiles-attributes-worker.js.map +0 -1
- package/dist/esm/i3s-attributes-worker.js +0 -16
- package/dist/esm/i3s-attributes-worker.js.map +0 -1
- package/dist/esm/i3s-server/bin/www +0 -102
- package/dist/esm/workers/3d-tiles-attributes-worker.js +0 -8
- package/dist/esm/workers/3d-tiles-attributes-worker.js.map +0 -1
- package/dist/esm/workers/i3s-attributes-worker.js +0 -7
- package/dist/esm/workers/i3s-attributes-worker.js.map +0 -1
- package/dist/i3s-attributes-worker.d.ts +0 -45
- package/dist/i3s-attributes-worker.d.ts.map +0 -1
- package/dist/i3s-attributes-worker.js +0 -9
- package/dist/i3s-attributes-worker.js.map +0 -7
- package/dist/workers/3d-tiles-attributes-worker.d.ts +0 -2
- package/dist/workers/3d-tiles-attributes-worker.d.ts.map +0 -1
- package/dist/workers/3d-tiles-attributes-worker.js +0 -9
- package/dist/workers/i3s-attributes-worker.d.ts +0 -2
- package/dist/workers/i3s-attributes-worker.d.ts.map +0 -1
- package/dist/workers/i3s-attributes-worker.js +0 -5
- package/src/3d-tiles-attributes-worker.ts +0 -43
- package/src/i3s-attributes-worker.ts +0 -59
- package/src/workers/3d-tiles-attributes-worker.ts +0 -6
- package/src/workers/i3s-attributes-worker.ts +0 -7
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@loaders.gl/tile-converter",
|
|
3
|
-
"version": "4.0.0-alpha.
|
|
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": "./
|
|
25
|
+
"i3s-server": "./bin/i3s-server.js"
|
|
26
26
|
},
|
|
27
27
|
"files": [
|
|
28
28
|
"src",
|
|
@@ -38,26 +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-
|
|
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
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-
|
|
46
|
-
"build-3d-tiles-attributes-worker": "esbuild src/workers/3d-tiles-attributes-worker.ts --outfile=dist/3d-tiles-attributes-worker.js --platform=node --target=esnext,node14 --external:join-images --minify --bundle --sourcemap --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\\\""
|
|
47
46
|
},
|
|
48
47
|
"dependencies": {
|
|
49
|
-
"@loaders.gl/3d-tiles": "4.0.0-alpha.
|
|
50
|
-
"@loaders.gl/crypto": "4.0.0-alpha.
|
|
51
|
-
"@loaders.gl/draco": "4.0.0-alpha.
|
|
52
|
-
"@loaders.gl/gltf": "4.0.0-alpha.
|
|
53
|
-
"@loaders.gl/i3s": "4.0.0-alpha.
|
|
54
|
-
"@loaders.gl/images": "4.0.0-alpha.
|
|
55
|
-
"@loaders.gl/loader-utils": "4.0.0-alpha.
|
|
56
|
-
"@loaders.gl/polyfills": "4.0.0-alpha.
|
|
57
|
-
"@loaders.gl/textures": "4.0.0-alpha.
|
|
58
|
-
"@loaders.gl/tiles": "4.0.0-alpha.
|
|
59
|
-
"@loaders.gl/worker-utils": "4.0.0-alpha.
|
|
60
|
-
"@loaders.gl/zip": "4.0.0-alpha.
|
|
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",
|
|
61
60
|
"@math.gl/core": "^3.5.1",
|
|
62
61
|
"@math.gl/culling": "^3.5.1",
|
|
63
62
|
"@math.gl/geoid": "^3.5.1",
|
|
@@ -65,13 +64,13 @@
|
|
|
65
64
|
"archiver": "^5.0.0",
|
|
66
65
|
"cors": "^2.8.5",
|
|
67
66
|
"crypt": "^0.0.2",
|
|
68
|
-
"debug": "~
|
|
69
|
-
"express": "~4.
|
|
67
|
+
"debug": "~4.3.4",
|
|
68
|
+
"express": "~4.18.2",
|
|
70
69
|
"json-map-transform": "^1.2.6",
|
|
71
70
|
"jszip": "^3.5.0",
|
|
72
71
|
"md5": "^2.3.0",
|
|
73
72
|
"morgan": "~1.9.1",
|
|
74
|
-
"uuid": "^
|
|
73
|
+
"uuid": "^9.0.0"
|
|
75
74
|
},
|
|
76
75
|
"peerDependencies": {
|
|
77
76
|
"@loaders.gl/core": "^4.0.0-alpha.8"
|
|
@@ -80,5 +79,5 @@
|
|
|
80
79
|
"join-images": "^1.1.3",
|
|
81
80
|
"sharp": "^0.31.3"
|
|
82
81
|
},
|
|
83
|
-
"gitHead": "
|
|
82
|
+
"gitHead": "47467ab23c65917e4642730e99b5d005af333c76"
|
|
84
83
|
}
|
|
@@ -4,7 +4,7 @@ import type {Tiles3DTileJSON} from '@loaders.gl/3d-tiles';
|
|
|
4
4
|
import {join} from 'path';
|
|
5
5
|
import process from 'process';
|
|
6
6
|
import transform from 'json-map-transform';
|
|
7
|
-
import {
|
|
7
|
+
import {load, isBrowser} from '@loaders.gl/core';
|
|
8
8
|
import {I3SLoader, I3SAttributeLoader, COORDINATE_SYSTEM} from '@loaders.gl/i3s';
|
|
9
9
|
import {Tileset3D, Tile3D} from '@loaders.gl/tiles';
|
|
10
10
|
import {Geoid} from '@math.gl/geoid';
|
|
@@ -16,13 +16,9 @@ import {writeFile, removeDir} from '../lib/utils/file-utils';
|
|
|
16
16
|
import {calculateFilesSize, timeConverter} from '../lib/utils/statistic-utills';
|
|
17
17
|
import {TILESET as tilesetTemplate} from './json-templates/tileset';
|
|
18
18
|
import {createObbFromMbs} from '../i3s-converter/helpers/coordinate-converter';
|
|
19
|
-
import {
|
|
20
|
-
I3SAttributesData,
|
|
21
|
-
Tile3dAttributesWorker,
|
|
22
|
-
transform3DTilesAttributesOnWorker
|
|
23
|
-
} from '../3d-tiles-attributes-worker';
|
|
24
|
-
import {getWorkerURL, WorkerFarm} from '@loaders.gl/worker-utils';
|
|
19
|
+
import {WorkerFarm} from '@loaders.gl/worker-utils';
|
|
25
20
|
import {BROWSER_ERROR_MESSAGE} from '../constants';
|
|
21
|
+
import B3dmConverter, {I3SAttributesData} from './helpers/b3dm-converter';
|
|
26
22
|
|
|
27
23
|
const I3S = 'I3S';
|
|
28
24
|
|
|
@@ -78,19 +74,17 @@ export default class Tiles3DConverter {
|
|
|
78
74
|
this.geoidHeightModel = await load(egmFilePath, PGMLoader);
|
|
79
75
|
console.log('Loading egm file completed!'); // eslint-disable-line
|
|
80
76
|
|
|
81
|
-
await this.loadWorkers();
|
|
82
|
-
|
|
83
77
|
const sourceTilesetJson = await load(inputUrl, I3SLoader, {});
|
|
84
78
|
|
|
85
79
|
this.sourceTileset = new Tileset3D(sourceTilesetJson, {
|
|
86
80
|
loadOptions: {
|
|
87
81
|
_nodeWorkers: true,
|
|
88
82
|
reuseWorkers: true,
|
|
89
|
-
i3s: {coordinateSystem: COORDINATE_SYSTEM.LNGLAT_OFFSETS, decodeTextures: false}
|
|
90
|
-
//
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
83
|
+
i3s: {coordinateSystem: COORDINATE_SYSTEM.LNGLAT_OFFSETS, decodeTextures: false},
|
|
84
|
+
// We need to load local fs workers because nodejs can't load workers from the Internet
|
|
85
|
+
'i3s-content': {
|
|
86
|
+
workerUrl: './modules/i3s/dist/i3s-content-worker-node.js'
|
|
87
|
+
}
|
|
94
88
|
}
|
|
95
89
|
});
|
|
96
90
|
|
|
@@ -171,10 +165,8 @@ export default class Tiles3DConverter {
|
|
|
171
165
|
textureFormat: sourceChild?.header?.textureFormat
|
|
172
166
|
};
|
|
173
167
|
|
|
174
|
-
const
|
|
175
|
-
|
|
176
|
-
featureAttributes
|
|
177
|
-
});
|
|
168
|
+
const b3dmConverter = new B3dmConverter();
|
|
169
|
+
const b3dm = await b3dmConverter.convert(i3sAttributesData, featureAttributes);
|
|
178
170
|
|
|
179
171
|
child.content = {
|
|
180
172
|
uri: `${sourceChild.id}.b3dm`,
|
|
@@ -342,14 +334,4 @@ export default class Tiles3DConverter {
|
|
|
342
334
|
console.log(`File(s) size: `, filesSize, ' bytes'); // eslint-disable-line
|
|
343
335
|
console.log(`------------------------------------------------`); // eslint-disable-line
|
|
344
336
|
}
|
|
345
|
-
|
|
346
|
-
private async loadWorkers(): Promise<void> {
|
|
347
|
-
console.log(`Loading workers source...`); // eslint-disable-line no-undef, no-console
|
|
348
|
-
const tile3dAttributesWorkerUrl = getWorkerURL(Tile3dAttributesWorker, {...getLoaderOptions()});
|
|
349
|
-
const sourceResponse = await fetchFile(tile3dAttributesWorkerUrl);
|
|
350
|
-
const source = await sourceResponse.text();
|
|
351
|
-
|
|
352
|
-
this.workerSource.tile3dWorkerSource = source;
|
|
353
|
-
console.log(`Loading workers source completed!`); // eslint-disable-line no-undef, no-console
|
|
354
|
-
}
|
|
355
337
|
}
|
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
import type {I3SAttributesData} from '../../3d-tiles-attributes-worker';
|
|
2
|
-
|
|
3
1
|
import {encodeSync} from '@loaders.gl/core';
|
|
4
2
|
import {GLTFScenegraph, GLTFWriter} from '@loaders.gl/gltf';
|
|
5
3
|
import {Tile3DWriter} from '@loaders.gl/3d-tiles';
|
|
@@ -11,6 +9,11 @@ import {generateSyntheticIndices} from '../../lib/utils/geometry-utils';
|
|
|
11
9
|
const Z_UP_TO_Y_UP_MATRIX = new Matrix4([1, 0, 0, 0, 0, 0, -1, 0, 0, 1, 0, 0, 0, 0, 0, 1]);
|
|
12
10
|
const scratchVector = new Vector3();
|
|
13
11
|
|
|
12
|
+
export type I3SAttributesData = {
|
|
13
|
+
tileContent: any;
|
|
14
|
+
textureFormat: string;
|
|
15
|
+
};
|
|
16
|
+
|
|
14
17
|
/**
|
|
15
18
|
* Converts content of an I3S node to *.b3dm's file content
|
|
16
19
|
*/
|
|
@@ -5,7 +5,7 @@ import type {
|
|
|
5
5
|
GLTF_EXT_feature_metadata_Primitive
|
|
6
6
|
} from '@loaders.gl/gltf';
|
|
7
7
|
import {TypedArray} from '@math.gl/core';
|
|
8
|
-
import {TextureImageProperties} from '
|
|
8
|
+
import {TextureImageProperties} from '../types';
|
|
9
9
|
|
|
10
10
|
const EXT_MESH_FEATURES = 'EXT_mesh_features';
|
|
11
11
|
const EXT_FEATURE_METADATA = 'EXT_feature_metadata';
|
|
@@ -34,11 +34,6 @@ import {
|
|
|
34
34
|
} from '@loaders.gl/i3s';
|
|
35
35
|
import {NumberArray, TypedArray} from '@loaders.gl/loader-utils';
|
|
36
36
|
import {Geoid} from '@math.gl/geoid';
|
|
37
|
-
/** Usage of worker here brings more overhead than advantage */
|
|
38
|
-
import {
|
|
39
|
-
B3DMAttributesData /*, transformI3SAttributesOnWorker*/,
|
|
40
|
-
TextureImageProperties
|
|
41
|
-
} from '../../i3s-attributes-worker';
|
|
42
37
|
import {prepareDataForAttributesConversion} from './gltf-attributes';
|
|
43
38
|
import {handleBatchIdsExtensions} from './batch-ids-extensions';
|
|
44
39
|
import {checkPropertiesLength, flattenPropertyTableByFeatureIds} from './feature-attributes';
|
|
@@ -49,7 +44,7 @@ import {GL} from '@loaders.gl/math';
|
|
|
49
44
|
So the following import is replaced with the local import
|
|
50
45
|
import type {TypedArrayConstructor} from '@math.gl/types';
|
|
51
46
|
*/
|
|
52
|
-
import type {TypedArrayConstructor} from '../types';
|
|
47
|
+
import type {GLTFAttributesData, TextureImageProperties, TypedArrayConstructor} from '../types';
|
|
53
48
|
import {generateSyntheticIndices} from '../../lib/utils/geometry-utils';
|
|
54
49
|
import {BoundingSphere, OrientedBoundingBox} from '@math.gl/culling';
|
|
55
50
|
|
|
@@ -320,7 +315,7 @@ async function _makeNodeResources({
|
|
|
320
315
|
* @returns map of converted geometry attributes
|
|
321
316
|
*/
|
|
322
317
|
export async function convertAttributes(
|
|
323
|
-
attributesData:
|
|
318
|
+
attributesData: GLTFAttributesData,
|
|
324
319
|
materialAndTextureList: I3SMaterialWithTexture[],
|
|
325
320
|
useCartesianPositions: boolean
|
|
326
321
|
): Promise<Map<string, ConvertedAttributes>> {
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import type {Tiles3DTileContent} from '@loaders.gl/3d-tiles';
|
|
2
2
|
import type {GLTFAccessorPostprocessed, GLTFNodePostprocessed} from '@loaders.gl/gltf';
|
|
3
|
-
import type {B3DMAttributesData} from '../../i3s-attributes-worker';
|
|
4
3
|
import {Matrix4, TypedArray, Vector3} from '@math.gl/core';
|
|
5
4
|
import {BoundingSphere, OrientedBoundingBox} from '@math.gl/culling';
|
|
6
5
|
import {Ellipsoid} from '@math.gl/geospatial';
|
|
6
|
+
import {GLTFAttributesData} from '../types';
|
|
7
7
|
|
|
8
8
|
/**
|
|
9
9
|
* Prepare attributes for conversion to avoid binary data breaking in worker thread.
|
|
@@ -17,7 +17,7 @@ export function prepareDataForAttributesConversion(
|
|
|
17
17
|
tileContent: Tiles3DTileContent,
|
|
18
18
|
tileTransform: Matrix4,
|
|
19
19
|
boundingVolume: OrientedBoundingBox | BoundingSphere
|
|
20
|
-
):
|
|
20
|
+
): GLTFAttributesData {
|
|
21
21
|
let nodes =
|
|
22
22
|
tileContent.gltf?.scene?.nodes ||
|
|
23
23
|
tileContent.gltf?.scenes?.[0]?.nodes ||
|
|
@@ -59,7 +59,6 @@ import {
|
|
|
59
59
|
import {getWorkerURL, WorkerFarm} from '@loaders.gl/worker-utils';
|
|
60
60
|
import {DracoWriterWorker} from '@loaders.gl/draco';
|
|
61
61
|
import WriteQueue from '../lib/utils/write-queue';
|
|
62
|
-
import {I3SAttributesWorker} from '../i3s-attributes-worker';
|
|
63
62
|
import {BROWSER_ERROR_MESSAGE} from '../constants';
|
|
64
63
|
import {
|
|
65
64
|
createdStorageAttribute,
|
|
@@ -241,10 +240,14 @@ export default class I3SConverter {
|
|
|
241
240
|
|
|
242
241
|
try {
|
|
243
242
|
const preloadOptions = await this._fetchPreloadOptions();
|
|
243
|
+
let tilesetUrl = inputUrl;
|
|
244
|
+
if (preloadOptions.url) {
|
|
245
|
+
tilesetUrl = preloadOptions.url;
|
|
246
|
+
}
|
|
244
247
|
if (preloadOptions.headers) {
|
|
245
248
|
this.loadOptions.fetch = {headers: preloadOptions.headers};
|
|
246
249
|
}
|
|
247
|
-
this.sourceTileset = await load(
|
|
250
|
+
this.sourceTileset = await load(tilesetUrl, this.Loader, this.loadOptions);
|
|
248
251
|
|
|
249
252
|
const preprocessResult = await this.preprocessConversion();
|
|
250
253
|
|
|
@@ -1211,10 +1214,6 @@ export default class I3SConverter {
|
|
|
1211
1214
|
this.workerSource.ktx2 = source;
|
|
1212
1215
|
}
|
|
1213
1216
|
|
|
1214
|
-
const i3sAttributesWorkerUrl = getWorkerURL(I3SAttributesWorker, {...getLoaderOptions()});
|
|
1215
|
-
const sourceResponse = await fetchFile(i3sAttributesWorkerUrl);
|
|
1216
|
-
const source = await sourceResponse.text();
|
|
1217
|
-
this.workerSource.I3SAttributes = source;
|
|
1218
1217
|
console.log(`Loading workers source completed!`); // eslint-disable-line no-undef, no-console
|
|
1219
1218
|
}
|
|
1220
1219
|
}
|
|
@@ -1,10 +1,11 @@
|
|
|
1
|
-
import {GLTFImagePostprocessed} from '@loaders.gl/gltf';
|
|
1
|
+
import {GLTFImagePostprocessed, GLTFNodePostprocessed} from '@loaders.gl/gltf';
|
|
2
2
|
import {
|
|
3
3
|
BoundingVolumes,
|
|
4
4
|
I3SMaterialDefinition,
|
|
5
5
|
MaterialDefinitionInfo,
|
|
6
6
|
TextureDefinitionInfo
|
|
7
7
|
} from '@loaders.gl/i3s';
|
|
8
|
+
import {Matrix4, Vector3} from '@math.gl/core';
|
|
8
9
|
|
|
9
10
|
/** Converted resources for specific node */
|
|
10
11
|
export type I3SConvertedResources = {
|
|
@@ -183,3 +184,33 @@ export type PreprocessData = {
|
|
|
183
184
|
/** Mesh topology types used in gltf primitives of the tileset */
|
|
184
185
|
meshTopologyTypes: Set<GltfPrimitiveModeString>;
|
|
185
186
|
};
|
|
187
|
+
|
|
188
|
+
/** Texture image properties required for conversion */
|
|
189
|
+
export type TextureImageProperties = {
|
|
190
|
+
/** Array with image data */
|
|
191
|
+
data: Uint8Array;
|
|
192
|
+
/** Is the texture compressed */
|
|
193
|
+
compressed?: boolean;
|
|
194
|
+
/** Height of the texture's image */
|
|
195
|
+
height?: number;
|
|
196
|
+
/** Width of the texture's image */
|
|
197
|
+
width?: number;
|
|
198
|
+
/** Number of components (3 for RGB, 4 for RGBA) */
|
|
199
|
+
components?: number;
|
|
200
|
+
/** Mime type of the texture's image */
|
|
201
|
+
mimeType?: string;
|
|
202
|
+
};
|
|
203
|
+
|
|
204
|
+
/** glTF attributes data, prepared for conversion */
|
|
205
|
+
export type GLTFAttributesData = {
|
|
206
|
+
/** glTF PBR materials (only id is required) */
|
|
207
|
+
gltfMaterials?: {id: string}[];
|
|
208
|
+
/** glTF geometry nodes */
|
|
209
|
+
nodes: GLTFNodePostprocessed[];
|
|
210
|
+
/** glTF texture images (set to null for compressed textures) */
|
|
211
|
+
images: (null | TextureImageProperties)[];
|
|
212
|
+
/** Source tile origin coordinates in cartographic coordinate system */
|
|
213
|
+
cartographicOrigin: Vector3;
|
|
214
|
+
/** Model matrix to convert coordinate system of POSITION and NORMAL attributes from METER_OFFSETS to CARTESIAN */
|
|
215
|
+
cartesianModelMatrix: Matrix4;
|
|
216
|
+
};
|
package/src/i3s-server/README.md
CHANGED
|
@@ -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
|
|
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
|
-
|
|
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`
|
package/src/i3s-server/app.js
CHANGED
|
@@ -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}
|
|
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`)
|
|
81
|
-
process.exit(1)
|
|
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`)
|
|
85
|
-
process.exit(1)
|
|
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 {
|
|
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
|
|
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,5 +1,5 @@
|
|
|
1
1
|
import {FileProvider} from '@loaders.gl/i3s';
|
|
2
|
-
import {
|
|
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:
|
|
13
|
-
const fileDescriptor = await
|
|
14
|
-
return new FileHandleProvider(fileDescriptor,
|
|
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:
|
|
20
|
+
private fileDescriptor: FileHandle;
|
|
21
21
|
|
|
22
22
|
/**
|
|
23
23
|
* The file length in bytes
|
|
24
24
|
*/
|
|
25
|
-
private size:
|
|
25
|
+
private size: bigint;
|
|
26
26
|
|
|
27
|
-
private constructor(fileDescriptor:
|
|
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
|
|
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:
|
|
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
|
|
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:
|
|
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
|
|
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:
|
|
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
|
|
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(
|
|
80
|
-
const
|
|
81
|
-
|
|
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():
|
|
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
|
+
}
|