@loaders.gl/i3s 4.0.0-alpha.1 → 4.0.0-alpha.11

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (242) hide show
  1. package/dist/arcgis-webscene-loader.d.ts +7 -0
  2. package/dist/arcgis-webscene-loader.d.ts.map +1 -0
  3. package/dist/arcgis-webscene-loader.js +28 -0
  4. package/dist/bundle.d.ts +2 -0
  5. package/dist/bundle.d.ts.map +1 -0
  6. package/dist/bundle.js +2 -2
  7. package/dist/dist.min.js +15501 -0
  8. package/dist/es5/arcgis-webscene-loader.js +40 -0
  9. package/dist/es5/arcgis-webscene-loader.js.map +1 -0
  10. package/dist/es5/bundle.js +6 -0
  11. package/dist/es5/bundle.js.map +1 -0
  12. package/dist/es5/i3s-attribute-loader.js +195 -0
  13. package/dist/es5/i3s-attribute-loader.js.map +1 -0
  14. package/dist/es5/i3s-building-scene-layer-loader.js +46 -0
  15. package/dist/es5/i3s-building-scene-layer-loader.js.map +1 -0
  16. package/dist/es5/i3s-content-loader.js +56 -0
  17. package/dist/es5/i3s-content-loader.js.map +1 -0
  18. package/dist/es5/i3s-loader.js +193 -0
  19. package/dist/es5/i3s-loader.js.map +1 -0
  20. package/dist/es5/i3s-node-page-loader.js +39 -0
  21. package/dist/es5/i3s-node-page-loader.js.map +1 -0
  22. package/dist/es5/i3s-slpk-loader.js +20 -0
  23. package/dist/es5/i3s-slpk-loader.js.map +1 -0
  24. package/dist/es5/index.js +82 -0
  25. package/dist/es5/index.js.map +1 -0
  26. package/dist/es5/lib/helpers/i3s-nodepages-tiles.js +312 -0
  27. package/dist/es5/lib/helpers/i3s-nodepages-tiles.js.map +1 -0
  28. package/dist/es5/lib/parsers/constants.js +72 -0
  29. package/dist/es5/lib/parsers/constants.js.map +1 -0
  30. package/dist/es5/lib/parsers/parse-arcgis-webscene.js +158 -0
  31. package/dist/es5/lib/parsers/parse-arcgis-webscene.js.map +1 -0
  32. package/dist/es5/lib/parsers/parse-i3s-attribute.js +76 -0
  33. package/dist/es5/lib/parsers/parse-i3s-attribute.js.map +1 -0
  34. package/dist/es5/lib/parsers/parse-i3s-building-scene-layer.js +65 -0
  35. package/dist/es5/lib/parsers/parse-i3s-building-scene-layer.js.map +1 -0
  36. package/dist/es5/lib/parsers/parse-i3s-tile-content.js +510 -0
  37. package/dist/es5/lib/parsers/parse-i3s-tile-content.js.map +1 -0
  38. package/dist/es5/lib/parsers/parse-i3s.js +116 -0
  39. package/dist/es5/lib/parsers/parse-i3s.js.map +1 -0
  40. package/dist/es5/lib/parsers/parse-slpk/parse-slpk.js +107 -0
  41. package/dist/es5/lib/parsers/parse-slpk/parse-slpk.js.map +1 -0
  42. package/dist/es5/lib/parsers/parse-slpk/slpk-archieve.js +258 -0
  43. package/dist/es5/lib/parsers/parse-slpk/slpk-archieve.js.map +1 -0
  44. package/dist/es5/lib/parsers/parse-zip/buffer-file-provider.js +46 -0
  45. package/dist/es5/lib/parsers/parse-zip/buffer-file-provider.js.map +1 -0
  46. package/dist/es5/lib/parsers/parse-zip/cd-file-header.js +84 -0
  47. package/dist/es5/lib/parsers/parse-zip/cd-file-header.js.map +1 -0
  48. package/dist/es5/lib/parsers/parse-zip/file-provider.js +2 -0
  49. package/dist/es5/lib/parsers/parse-zip/file-provider.js.map +1 -0
  50. package/dist/es5/lib/parsers/parse-zip/local-file-header.js +72 -0
  51. package/dist/es5/lib/parsers/parse-zip/local-file-header.js.map +1 -0
  52. package/dist/es5/lib/utils/convert-i3s-obb-to-mbs.js +17 -0
  53. package/dist/es5/lib/utils/convert-i3s-obb-to-mbs.js.map +1 -0
  54. package/dist/es5/lib/utils/customize-/321/201olors.js +184 -0
  55. package/dist/es5/lib/utils/customize-/321/201olors.js.map +1 -0
  56. package/dist/es5/lib/utils/url-utils.js +33 -0
  57. package/dist/es5/lib/utils/url-utils.js.map +1 -0
  58. package/dist/es5/types.js +26 -0
  59. package/dist/es5/types.js.map +1 -0
  60. package/dist/es5/workers/i3s-content-worker-node.js +7 -0
  61. package/dist/es5/workers/i3s-content-worker-node.js.map +1 -0
  62. package/dist/es5/workers/i3s-content-worker.js +6 -0
  63. package/dist/es5/workers/i3s-content-worker.js.map +1 -0
  64. package/dist/esm/arcgis-webscene-loader.js +16 -0
  65. package/dist/esm/arcgis-webscene-loader.js.map +1 -0
  66. package/dist/esm/bundle.js +4 -0
  67. package/dist/esm/bundle.js.map +1 -0
  68. package/dist/esm/i3s-attribute-loader.js +119 -0
  69. package/dist/esm/i3s-attribute-loader.js.map +1 -0
  70. package/dist/esm/i3s-building-scene-layer-loader.js +19 -0
  71. package/dist/esm/i3s-building-scene-layer-loader.js.map +1 -0
  72. package/dist/esm/i3s-content-loader.js +30 -0
  73. package/dist/esm/i3s-content-loader.js.map +1 -0
  74. package/dist/esm/i3s-loader.js +87 -0
  75. package/dist/esm/i3s-loader.js.map +1 -0
  76. package/dist/esm/i3s-node-page-loader.js +15 -0
  77. package/dist/esm/i3s-node-page-loader.js.map +1 -0
  78. package/dist/esm/i3s-slpk-loader.js +13 -0
  79. package/dist/esm/i3s-slpk-loader.js.map +1 -0
  80. package/dist/esm/index.js +11 -0
  81. package/dist/esm/index.js.map +1 -0
  82. package/dist/esm/lib/helpers/i3s-nodepages-tiles.js +198 -0
  83. package/dist/esm/lib/helpers/i3s-nodepages-tiles.js.map +1 -0
  84. package/dist/esm/lib/parsers/constants.js +57 -0
  85. package/dist/esm/lib/parsers/constants.js.map +1 -0
  86. package/dist/esm/lib/parsers/parse-arcgis-webscene.js +70 -0
  87. package/dist/esm/lib/parsers/parse-arcgis-webscene.js.map +1 -0
  88. package/dist/esm/lib/parsers/parse-i3s-attribute.js +60 -0
  89. package/dist/esm/lib/parsers/parse-i3s-attribute.js.map +1 -0
  90. package/dist/esm/lib/parsers/parse-i3s-building-scene-layer.js +39 -0
  91. package/dist/esm/lib/parsers/parse-i3s-building-scene-layer.js.map +1 -0
  92. package/dist/esm/lib/parsers/parse-i3s-tile-content.js +435 -0
  93. package/dist/esm/lib/parsers/parse-i3s-tile-content.js.map +1 -0
  94. package/dist/esm/lib/parsers/parse-i3s.js +83 -0
  95. package/dist/esm/lib/parsers/parse-i3s.js.map +1 -0
  96. package/dist/esm/lib/parsers/parse-slpk/parse-slpk.js +41 -0
  97. package/dist/esm/lib/parsers/parse-slpk/parse-slpk.js.map +1 -0
  98. package/dist/esm/lib/parsers/parse-slpk/slpk-archieve.js +107 -0
  99. package/dist/esm/lib/parsers/parse-slpk/slpk-archieve.js.map +1 -0
  100. package/dist/esm/lib/parsers/parse-zip/buffer-file-provider.js +23 -0
  101. package/dist/esm/lib/parsers/parse-zip/buffer-file-provider.js.map +1 -0
  102. package/dist/esm/lib/parsers/parse-zip/cd-file-header.js +37 -0
  103. package/dist/esm/lib/parsers/parse-zip/cd-file-header.js.map +1 -0
  104. package/dist/esm/lib/parsers/parse-zip/file-provider.js +2 -0
  105. package/dist/esm/lib/parsers/parse-zip/file-provider.js.map +1 -0
  106. package/dist/esm/lib/parsers/parse-zip/local-file-header.js +25 -0
  107. package/dist/esm/lib/parsers/parse-zip/local-file-header.js.map +1 -0
  108. package/dist/esm/lib/utils/convert-i3s-obb-to-mbs.js +9 -0
  109. package/dist/esm/lib/utils/convert-i3s-obb-to-mbs.js.map +1 -0
  110. package/dist/esm/lib/utils/customize-/321/201olors.js +98 -0
  111. package/dist/esm/lib/utils/customize-/321/201olors.js.map +1 -0
  112. package/dist/esm/lib/utils/url-utils.js +28 -0
  113. package/dist/esm/lib/utils/url-utils.js.map +1 -0
  114. package/dist/esm/types.js +18 -0
  115. package/dist/esm/types.js.map +1 -0
  116. package/dist/esm/workers/i3s-content-worker-node.js +5 -0
  117. package/dist/esm/workers/i3s-content-worker-node.js.map +1 -0
  118. package/dist/esm/workers/i3s-content-worker.js +4 -0
  119. package/dist/esm/workers/i3s-content-worker.js.map +1 -0
  120. package/dist/i3s-attribute-loader.d.ts +21 -0
  121. package/dist/i3s-attribute-loader.d.ts.map +1 -0
  122. package/dist/i3s-attribute-loader.js +155 -132
  123. package/dist/i3s-building-scene-layer-loader.d.ts +6 -0
  124. package/dist/i3s-building-scene-layer-loader.d.ts.map +1 -0
  125. package/dist/i3s-building-scene-layer-loader.js +23 -18
  126. package/dist/i3s-content-loader.d.ts +6 -0
  127. package/dist/i3s-content-loader.d.ts.map +1 -0
  128. package/dist/i3s-content-loader.js +29 -22
  129. package/dist/i3s-content-worker-node.js +197 -0
  130. package/dist/i3s-content-worker-node.js.map +7 -0
  131. package/dist/i3s-content-worker.js +2308 -1376
  132. package/dist/i3s-loader.d.ts +11 -0
  133. package/dist/i3s-loader.d.ts.map +1 -0
  134. package/dist/i3s-loader.js +88 -81
  135. package/dist/i3s-node-page-loader.d.ts +7 -0
  136. package/dist/i3s-node-page-loader.d.ts.map +1 -0
  137. package/dist/i3s-node-page-loader.js +20 -20
  138. package/dist/i3s-slpk-loader.d.ts +13 -0
  139. package/dist/i3s-slpk-loader.d.ts.map +1 -0
  140. package/dist/i3s-slpk-loader.js +20 -0
  141. package/dist/index.d.ts +12 -0
  142. package/dist/index.d.ts.map +1 -0
  143. package/dist/index.js +23 -5
  144. package/dist/lib/helpers/i3s-nodepages-tiles.d.ts +74 -0
  145. package/dist/lib/helpers/i3s-nodepages-tiles.d.ts.map +1 -0
  146. package/dist/lib/helpers/i3s-nodepages-tiles.js +232 -219
  147. package/dist/lib/parsers/constants.d.ts +40 -0
  148. package/dist/lib/parsers/constants.d.ts.map +1 -0
  149. package/dist/lib/parsers/constants.js +87 -42
  150. package/dist/lib/parsers/parse-arcgis-webscene.d.ts +7 -0
  151. package/dist/lib/parsers/parse-arcgis-webscene.d.ts.map +1 -0
  152. package/dist/lib/parsers/parse-arcgis-webscene.js +88 -0
  153. package/dist/lib/parsers/parse-i3s-attribute.d.ts +12 -0
  154. package/dist/lib/parsers/parse-i3s-attribute.d.ts.map +1 -0
  155. package/dist/lib/parsers/parse-i3s-attribute.js +87 -62
  156. package/dist/lib/parsers/parse-i3s-building-scene-layer.d.ts +9 -0
  157. package/dist/lib/parsers/parse-i3s-building-scene-layer.d.ts.map +1 -0
  158. package/dist/lib/parsers/parse-i3s-building-scene-layer.js +41 -38
  159. package/dist/lib/parsers/parse-i3s-tile-content.d.ts +4 -0
  160. package/dist/lib/parsers/parse-i3s-tile-content.d.ts.map +1 -0
  161. package/dist/lib/parsers/parse-i3s-tile-content.js +460 -415
  162. package/dist/lib/parsers/parse-i3s.d.ts +6 -0
  163. package/dist/lib/parsers/parse-i3s.d.ts.map +1 -0
  164. package/dist/lib/parsers/parse-i3s.js +92 -73
  165. package/dist/lib/parsers/parse-slpk/parse-slpk.d.ts +4 -0
  166. package/dist/lib/parsers/parse-slpk/parse-slpk.d.ts.map +1 -0
  167. package/dist/lib/parsers/parse-slpk/parse-slpk.js +54 -0
  168. package/dist/lib/parsers/parse-slpk/slpk-archieve.d.ts +38 -0
  169. package/dist/lib/parsers/parse-slpk/slpk-archieve.d.ts.map +1 -0
  170. package/dist/lib/parsers/parse-slpk/slpk-archieve.js +142 -0
  171. package/dist/lib/parsers/parse-zip/buffer-file-provider.d.ts +37 -0
  172. package/dist/lib/parsers/parse-zip/buffer-file-provider.d.ts.map +1 -0
  173. package/dist/lib/parsers/parse-zip/buffer-file-provider.js +47 -0
  174. package/dist/lib/parsers/parse-zip/cd-file-header.d.ts +27 -0
  175. package/dist/lib/parsers/parse-zip/cd-file-header.d.ts.map +1 -0
  176. package/dist/lib/parsers/parse-zip/cd-file-header.js +48 -0
  177. package/dist/lib/parsers/parse-zip/file-provider.d.ts +31 -0
  178. package/dist/lib/parsers/parse-zip/file-provider.d.ts.map +1 -0
  179. package/dist/lib/parsers/parse-zip/file-provider.js +2 -0
  180. package/dist/lib/parsers/parse-zip/local-file-header.d.ts +25 -0
  181. package/dist/lib/parsers/parse-zip/local-file-header.d.ts.map +1 -0
  182. package/dist/lib/parsers/parse-zip/local-file-header.js +34 -0
  183. package/dist/lib/utils/convert-i3s-obb-to-mbs.d.ts +2 -0
  184. package/dist/lib/utils/convert-i3s-obb-to-mbs.d.ts.map +1 -0
  185. package/dist/lib/utils/convert-i3s-obb-to-mbs.js +19 -8
  186. package/dist/lib/utils/customize-/321/201olors.d.ts +14 -0
  187. package/dist/lib/utils/customize-/321/201olors.d.ts.map +1 -0
  188. package/dist/lib/utils/customize-/321/201olors.js +104 -0
  189. package/dist/lib/utils/url-utils.d.ts +22 -0
  190. package/dist/lib/utils/url-utils.d.ts.map +1 -0
  191. package/dist/lib/utils/url-utils.js +41 -29
  192. package/dist/types.d.ts +1065 -0
  193. package/dist/types.d.ts.map +1 -0
  194. package/dist/types.js +20 -2
  195. package/dist/workers/i3s-content-worker-node.d.ts +2 -0
  196. package/dist/workers/i3s-content-worker-node.d.ts.map +1 -0
  197. package/dist/workers/i3s-content-worker-node.js +7 -0
  198. package/dist/workers/i3s-content-worker.d.ts +2 -0
  199. package/dist/workers/i3s-content-worker.d.ts.map +1 -0
  200. package/dist/workers/i3s-content-worker.js +5 -4
  201. package/package.json +18 -16
  202. package/src/arcgis-webscene-loader.ts +31 -0
  203. package/src/i3s-attribute-loader.ts +9 -9
  204. package/src/i3s-content-loader.ts +17 -5
  205. package/src/i3s-loader.ts +24 -13
  206. package/src/i3s-node-page-loader.ts +6 -10
  207. package/src/i3s-slpk-loader.ts +27 -0
  208. package/src/index.ts +28 -7
  209. package/src/lib/helpers/i3s-nodepages-tiles.ts +84 -57
  210. package/src/lib/parsers/constants.ts +71 -37
  211. package/src/lib/parsers/parse-arcgis-webscene.ts +102 -0
  212. package/src/lib/parsers/parse-i3s-attribute.ts +21 -14
  213. package/src/lib/parsers/parse-i3s-building-scene-layer.ts +2 -1
  214. package/src/lib/parsers/parse-i3s-tile-content.ts +278 -194
  215. package/src/lib/parsers/parse-i3s.ts +55 -39
  216. package/src/lib/parsers/parse-slpk/parse-slpk.ts +72 -0
  217. package/src/lib/parsers/parse-slpk/slpk-archieve.ts +173 -0
  218. package/src/lib/parsers/parse-zip/buffer-file-provider.ts +55 -0
  219. package/src/lib/parsers/parse-zip/cd-file-header.ts +86 -0
  220. package/src/lib/parsers/parse-zip/file-provider.ts +34 -0
  221. package/src/lib/parsers/parse-zip/local-file-header.ts +65 -0
  222. package/src/lib/utils/customize-/321/201olors.ts +144 -0
  223. package/src/lib/utils/url-utils.ts +7 -7
  224. package/src/types.ts +875 -86
  225. package/src/workers/i3s-content-worker-node.ts +6 -0
  226. package/dist/bundle.js.map +0 -1
  227. package/dist/i3s-attribute-loader.js.map +0 -1
  228. package/dist/i3s-building-scene-layer-loader.js.map +0 -1
  229. package/dist/i3s-content-loader.js.map +0 -1
  230. package/dist/i3s-loader.js.map +0 -1
  231. package/dist/i3s-node-page-loader.js.map +0 -1
  232. package/dist/index.js.map +0 -1
  233. package/dist/lib/helpers/i3s-nodepages-tiles.js.map +0 -1
  234. package/dist/lib/parsers/constants.js.map +0 -1
  235. package/dist/lib/parsers/parse-i3s-attribute.js.map +0 -1
  236. package/dist/lib/parsers/parse-i3s-building-scene-layer.js.map +0 -1
  237. package/dist/lib/parsers/parse-i3s-tile-content.js.map +0 -1
  238. package/dist/lib/parsers/parse-i3s.js.map +0 -1
  239. package/dist/lib/utils/convert-i3s-obb-to-mbs.js.map +0 -1
  240. package/dist/lib/utils/url-utils.js.map +0 -1
  241. package/dist/types.js.map +0 -1
  242. package/dist/workers/i3s-content-worker.js.map +0 -1
@@ -0,0 +1,6 @@
1
+ import { I3STilesetHeader, I3STileHeader, I3SMinimalNodeData, Node3DIndexDocument } from '../../types';
2
+ import type { LoaderOptions, LoaderContext } from '@loaders.gl/loader-utils';
3
+ export declare function normalizeTileData(tile: Node3DIndexDocument, context: LoaderContext): I3STileHeader;
4
+ export declare function normalizeTileNonUrlData(tile: I3SMinimalNodeData): I3STileHeader;
5
+ export declare function normalizeTilesetData(tileset: I3STilesetHeader, options: LoaderOptions, context: LoaderContext): Promise<void>;
6
+ //# sourceMappingURL=parse-i3s.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"parse-i3s.d.ts","sourceRoot":"","sources":["../../../src/lib/parsers/parse-i3s.ts"],"names":[],"mappings":"AAMA,OAAO,EACL,gBAAgB,EAChB,aAAa,EAEb,kBAAkB,EAClB,mBAAmB,EACpB,MAAM,aAAa,CAAC;AACrB,OAAO,KAAK,EAAC,aAAa,EAAE,aAAa,EAAC,MAAM,0BAA0B,CAAC;AAE3E,wBAAgB,iBAAiB,CAAC,IAAI,EAAG,mBAAmB,EAAE,OAAO,EAAE,aAAa,GAAG,aAAa,CAyBnG;AAED,wBAAgB,uBAAuB,CAAC,IAAI,EAAG,kBAAkB,GAAG,aAAa,CAmChF;AAED,wBAAsB,oBAAoB,CAAC,OAAO,EAAG,gBAAgB,EAAE,OAAO,EAAG,aAAa,EAAE,OAAO,EAAE,aAAa,iBA0BrH"}
@@ -1,76 +1,95 @@
1
- import { OrientedBoundingBox } from '@math.gl/culling';
2
- import { Ellipsoid } from '@math.gl/geospatial';
3
- import { load } from '@loaders.gl/core';
4
- import { TILE_TYPE, TILE_REFINEMENT, TILESET_TYPE } from '@loaders.gl/tiles';
5
- import I3SNodePagesTiles from '../helpers/i3s-nodepages-tiles';
6
- import { generateTileAttributeUrls, getUrlWithToken } from '../utils/url-utils';
7
- export function normalizeTileData(tile, options, context) {
8
- tile.url = context.url;
9
-
10
- if (tile.featureData) {
11
- tile.featureUrl = "".concat(tile.url, "/").concat(tile.featureData[0].href);
12
- }
13
-
14
- if (tile.geometryData) {
15
- tile.contentUrl = "".concat(tile.url, "/").concat(tile.geometryData[0].href);
16
- }
17
-
18
- if (tile.textureData) {
19
- tile.textureUrl = "".concat(tile.url, "/").concat(tile.textureData[0].href);
20
- }
21
-
22
- if (tile.attributeData) {
23
- tile.attributeUrls = generateTileAttributeUrls(tile);
24
- }
25
-
26
- return normalizeTileNonUrlData(tile);
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.normalizeTilesetData = exports.normalizeTileNonUrlData = exports.normalizeTileData = void 0;
7
+ const culling_1 = require("@math.gl/culling");
8
+ const geospatial_1 = require("@math.gl/geospatial");
9
+ const core_1 = require("@loaders.gl/core");
10
+ const tiles_1 = require("@loaders.gl/tiles");
11
+ const i3s_nodepages_tiles_1 = __importDefault(require("../helpers/i3s-nodepages-tiles"));
12
+ const url_utils_1 = require("../utils/url-utils");
13
+ function normalizeTileData(tile, context) {
14
+ const url = context.url || '';
15
+ let contentUrl;
16
+ if (tile.geometryData) {
17
+ contentUrl = `${url}/${tile.geometryData[0].href}`;
18
+ }
19
+ let textureUrl;
20
+ if (tile.textureData) {
21
+ textureUrl = `${url}/${tile.textureData[0].href}`;
22
+ }
23
+ let attributeUrls;
24
+ if (tile.attributeData) {
25
+ attributeUrls = (0, url_utils_1.generateTileAttributeUrls)(url, tile);
26
+ }
27
+ return normalizeTileNonUrlData({
28
+ ...tile,
29
+ url,
30
+ contentUrl,
31
+ textureUrl,
32
+ attributeUrls,
33
+ isDracoGeometry: false
34
+ });
27
35
  }
28
- export function normalizeTileNonUrlData(tile) {
29
- const box = tile.obb ? [...Ellipsoid.WGS84.cartographicToCartesian(tile.obb.center), ...tile.obb.halfSize, ...tile.obb.quaternion] : undefined;
30
- let sphere;
31
-
32
- if (tile.mbs) {
33
- sphere = [...Ellipsoid.WGS84.cartographicToCartesian(tile.mbs.slice(0, 3)), tile.mbs[3]];
34
- } else if (box) {
35
- const obb = new OrientedBoundingBox().fromCenterHalfSizeQuaternion(box.slice(0, 3), tile.obb.halfSize, tile.obb.quaternion);
36
- const boundingSphere = obb.getBoundingSphere();
37
- sphere = [...boundingSphere.center, boundingSphere.radius];
38
- tile.mbs = [...tile.obb.center, boundingSphere.radius];
39
- }
40
-
41
- tile.boundingVolume = {
42
- sphere,
43
- box
44
- };
45
- tile.lodMetricType = tile.lodSelection[0].metricType;
46
- tile.lodMetricValue = tile.lodSelection[0].maxError;
47
- tile.transformMatrix = tile.transform;
48
- tile.type = TILE_TYPE.MESH;
49
- tile.refine = TILE_REFINEMENT.REPLACE;
50
- return tile;
36
+ exports.normalizeTileData = normalizeTileData;
37
+ function normalizeTileNonUrlData(tile) {
38
+ const boundingVolume = {};
39
+ let mbs = [0, 0, 0, 1];
40
+ if (tile.mbs) {
41
+ mbs = tile.mbs;
42
+ boundingVolume.sphere = [
43
+ ...geospatial_1.Ellipsoid.WGS84.cartographicToCartesian(tile.mbs.slice(0, 3)),
44
+ tile.mbs[3] // radius of sphere
45
+ ];
46
+ }
47
+ else if (tile.obb) {
48
+ boundingVolume.box = [
49
+ ...geospatial_1.Ellipsoid.WGS84.cartographicToCartesian(tile.obb.center),
50
+ ...tile.obb.halfSize,
51
+ ...tile.obb.quaternion // quaternion
52
+ ];
53
+ const obb = new culling_1.OrientedBoundingBox().fromCenterHalfSizeQuaternion(boundingVolume.box.slice(0, 3), tile.obb.halfSize, tile.obb.quaternion);
54
+ const boundingSphere = obb.getBoundingSphere();
55
+ boundingVolume.sphere = [...boundingSphere.center, boundingSphere.radius];
56
+ mbs = [...tile.obb.center, boundingSphere.radius];
57
+ }
58
+ const lodMetricType = tile.lodSelection?.[0].metricType;
59
+ const lodMetricValue = tile.lodSelection?.[0].maxError;
60
+ const transformMatrix = tile.transform;
61
+ const type = tiles_1.TILE_TYPE.MESH;
62
+ /**
63
+ * I3S specification supports only REPLACE
64
+ */
65
+ const refine = tiles_1.TILE_REFINEMENT.REPLACE;
66
+ return { ...tile, mbs, boundingVolume, lodMetricType, lodMetricValue, transformMatrix, type, refine };
51
67
  }
52
- export async function normalizeTilesetData(tileset, options, context) {
53
- tileset.url = context.url;
54
-
55
- if (tileset.nodePages) {
56
- tileset.nodePagesTile = new I3SNodePagesTiles(tileset, options);
57
- tileset.root = await tileset.nodePagesTile.formTileFromNodePages(0);
58
- } else {
59
- var _options$i3s;
60
-
61
- const rootNodeUrl = getUrlWithToken("".concat(tileset.url, "/nodes/root"), (_options$i3s = options.i3s) === null || _options$i3s === void 0 ? void 0 : _options$i3s.token);
62
- tileset.root = await load(rootNodeUrl, tileset.loader, {
63
- i3s: {
64
- loadContent: false,
65
- isTileHeader: true,
66
- isTileset: false
67
- }
68
- });
69
- }
70
-
71
- tileset.basePath = tileset.url;
72
- tileset.type = TILESET_TYPE.I3S;
73
- tileset.lodMetricType = tileset.root.lodMetricType;
74
- tileset.lodMetricValue = tileset.root.lodMetricValue;
68
+ exports.normalizeTileNonUrlData = normalizeTileNonUrlData;
69
+ async function normalizeTilesetData(tileset, options, context) {
70
+ tileset.url = context.url;
71
+ if (tileset.nodePages) {
72
+ tileset.nodePagesTile = new i3s_nodepages_tiles_1.default(tileset, options);
73
+ tileset.root = tileset.nodePagesTile.formTileFromNodePages(0);
74
+ }
75
+ else {
76
+ // @ts-expect-error options is not properly typed
77
+ const rootNodeUrl = (0, url_utils_1.getUrlWithToken)(`${tileset.url}/nodes/root`, options.i3s?.token);
78
+ // eslint-disable-next-line no-use-before-define
79
+ tileset.root = await (0, core_1.load)(rootNodeUrl, tileset.loader, {
80
+ ...options,
81
+ i3s: {
82
+ // @ts-expect-error options is not properly typed
83
+ ...options.i3s,
84
+ loadContent: false, isTileHeader: true, isTileset: false
85
+ }
86
+ });
87
+ }
88
+ // base path that non-absolute paths in tileset are relative to.
89
+ tileset.basePath = tileset.url;
90
+ tileset.type = tiles_1.TILESET_TYPE.I3S;
91
+ // populate from root node
92
+ tileset.lodMetricType = tileset.root.lodMetricType;
93
+ tileset.lodMetricValue = tileset.root.lodMetricValue;
75
94
  }
76
- //# sourceMappingURL=parse-i3s.js.map
95
+ exports.normalizeTilesetData = normalizeTilesetData;
@@ -0,0 +1,4 @@
1
+ /// <reference types="node" />
2
+ import type { SLPKLoaderOptions } from '../../../i3s-slpk-loader';
3
+ export declare function parseSLPK(data: ArrayBuffer, options?: SLPKLoaderOptions): Promise<Buffer>;
4
+ //# sourceMappingURL=parse-slpk.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"parse-slpk.d.ts","sourceRoot":"","sources":["../../../../src/lib/parsers/parse-slpk/parse-slpk.ts"],"names":[],"mappings":";AAAA,OAAO,KAAK,EAAC,iBAAiB,EAAC,MAAM,0BAA0B,CAAC;AAgBhE,wBAAsB,SAAS,CAAC,IAAI,EAAE,WAAW,EAAE,OAAO,GAAE,iBAAsB,mBAuDjF"}
@@ -0,0 +1,54 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.parseSLPK = void 0;
4
+ const buffer_file_provider_1 = require("../parse-zip/buffer-file-provider");
5
+ const cd_file_header_1 = require("../parse-zip/cd-file-header");
6
+ const local_file_header_1 = require("../parse-zip/local-file-header");
7
+ const slpk_archieve_1 = require("./slpk-archieve");
8
+ /**
9
+ * Returns one byte from the provided buffer at the provided position
10
+ * @param offset - position where to read
11
+ * @param buffer - buffer to read
12
+ * @returns one byte from the provided buffer at the provided position
13
+ */
14
+ const getByteAt = (offset, buffer) => {
15
+ return buffer.getUint8(buffer.byteOffset + offset);
16
+ };
17
+ async function parseSLPK(data, options = {}) {
18
+ const archive = new DataView(data);
19
+ const cdFileHeaderSignature = [80, 75, 1, 2];
20
+ const searchWindow = [
21
+ getByteAt(archive.byteLength - 1, archive),
22
+ getByteAt(archive.byteLength - 2, archive),
23
+ getByteAt(archive.byteLength - 3, archive),
24
+ undefined
25
+ ];
26
+ let hashCDOffset = 0;
27
+ // looking for the last record in the central directory
28
+ for (let i = archive.byteLength - 4; i > -1; i--) {
29
+ searchWindow[3] = searchWindow[2];
30
+ searchWindow[2] = searchWindow[1];
31
+ searchWindow[1] = searchWindow[0];
32
+ searchWindow[0] = getByteAt(i, archive);
33
+ if (searchWindow.every((val, index) => val === cdFileHeaderSignature[index])) {
34
+ hashCDOffset = i;
35
+ break;
36
+ }
37
+ }
38
+ const fileProvider = new buffer_file_provider_1.DataViewFileProvider(archive);
39
+ const cdFileHeader = await (0, cd_file_header_1.parseZipCDFileHeader)(hashCDOffset, fileProvider);
40
+ if (cdFileHeader.fileName !== '@specialIndexFileHASH128@') {
41
+ throw new Error('No hash file in slpk');
42
+ }
43
+ const localFileHeader = await (0, local_file_header_1.parseZipLocalFileHeader)(cdFileHeader.localHeaderOffset, fileProvider);
44
+ if (!localFileHeader) {
45
+ throw new Error('No hash file in slpk');
46
+ }
47
+ const fileDataOffset = localFileHeader.fileDataOffset;
48
+ const hashFile = archive.buffer.slice(fileDataOffset, fileDataOffset + localFileHeader.compressedSize);
49
+ if (!hashFile) {
50
+ throw new Error('No hash file in slpk');
51
+ }
52
+ return await new slpk_archieve_1.SLPKArchive(data, hashFile).getFile(options.slpk?.path ?? '', options.slpk?.pathMode);
53
+ }
54
+ exports.parseSLPK = parseSLPK;
@@ -0,0 +1,38 @@
1
+ /// <reference types="node" />
2
+ /**
3
+ * Class for handling information about slpk file
4
+ */
5
+ export declare class SLPKArchive {
6
+ slpkArchive: DataView;
7
+ hashArray: {
8
+ hash: Buffer;
9
+ offset: number;
10
+ }[];
11
+ constructor(slpkArchiveBuffer: ArrayBuffer, hashFile: ArrayBuffer);
12
+ /**
13
+ * Reads hash file from buffer and returns it in ready-to-use form
14
+ * @param hashFile - bufer containing hash file
15
+ * @returns Array containing file info
16
+ */
17
+ private parseHashFile;
18
+ /**
19
+ * Returns file with the given path from slpk archive
20
+ * @param path - path inside the slpk
21
+ * @param mode - currently only raw mode supported
22
+ * @returns buffer with ready to use file
23
+ */
24
+ getFile(path: string, mode?: 'http' | 'raw'): Promise<Buffer>;
25
+ /**
26
+ * returning uncompressed data for paths that ends with .gz and raw data for all other paths
27
+ * @param path - path inside the archive
28
+ * @returns buffer with the file data
29
+ */
30
+ private getDataByPath;
31
+ /**
32
+ * Trying to get raw file data by adress
33
+ * @param path - path inside the archive
34
+ * @returns buffer with the raw file data
35
+ */
36
+ private getFileBytes;
37
+ }
38
+ //# sourceMappingURL=slpk-archieve.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"slpk-archieve.d.ts","sourceRoot":"","sources":["../../../../src/lib/parsers/parse-slpk/slpk-archieve.ts"],"names":[],"mappings":";AAqDA;;GAEG;AACH,qBAAa,WAAW;IACtB,WAAW,EAAE,QAAQ,CAAC;IACtB,SAAS,EAAE;QAAC,IAAI,EAAE,MAAM,CAAC;QAAC,MAAM,EAAE,MAAM,CAAA;KAAC,EAAE,CAAC;gBAChC,iBAAiB,EAAE,WAAW,EAAE,QAAQ,EAAE,WAAW;IAKjE;;;;OAIG;IACH,OAAO,CAAC,aAAa;IAqBrB;;;;;OAKG;IACG,OAAO,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,GAAE,MAAM,GAAG,KAAa,GAAG,OAAO,CAAC,MAAM,CAAC;IA8B1E;;;;OAIG;YACW,aAAa;IAc3B;;;;OAIG;YACW,YAAY;CAsB3B"}
@@ -0,0 +1,142 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.SLPKArchive = void 0;
7
+ const md5_1 = __importDefault(require("md5"));
8
+ const local_file_header_1 = require("../parse-zip/local-file-header");
9
+ const buffer_file_provider_1 = require("../parse-zip/buffer-file-provider");
10
+ const compression_1 = require("@loaders.gl/compression");
11
+ /** Description of real paths for different file types */
12
+ const PATH_DESCRIPTIONS = [
13
+ {
14
+ test: /^$/,
15
+ extensions: ['3dSceneLayer.json.gz']
16
+ },
17
+ {
18
+ test: /^nodepages\/\d+$/,
19
+ extensions: ['.json.gz']
20
+ },
21
+ {
22
+ test: /^nodes\/\d+$/,
23
+ extensions: ['/3dNodeIndexDocument.json.gz']
24
+ },
25
+ {
26
+ test: /^nodes\/\d+\/textures\/.+$/,
27
+ extensions: ['.jpg', '.png', '.bin.dds.gz', '.ktx']
28
+ },
29
+ {
30
+ test: /^nodes\/\d+\/geometries\/\d+$/,
31
+ extensions: ['.bin.gz', '.draco.gz']
32
+ },
33
+ {
34
+ test: /^nodes\/\d+\/attributes\/f_\d+\/\d+$/,
35
+ extensions: ['.bin.gz']
36
+ },
37
+ {
38
+ test: /^statistics\/f_\d+\/\d+$/,
39
+ extensions: ['.json.gz']
40
+ },
41
+ {
42
+ test: /^nodes\/\d+\/shared$/,
43
+ extensions: ['/sharedResource.json.gz']
44
+ }
45
+ ];
46
+ /**
47
+ * Class for handling information about slpk file
48
+ */
49
+ class SLPKArchive {
50
+ constructor(slpkArchiveBuffer, hashFile) {
51
+ this.slpkArchive = new DataView(slpkArchiveBuffer);
52
+ this.hashArray = this.parseHashFile(hashFile);
53
+ }
54
+ /**
55
+ * Reads hash file from buffer and returns it in ready-to-use form
56
+ * @param hashFile - bufer containing hash file
57
+ * @returns Array containing file info
58
+ */
59
+ parseHashFile(hashFile) {
60
+ const hashFileBuffer = Buffer.from(hashFile);
61
+ const hashArray = [];
62
+ for (let i = 0; i < hashFileBuffer.buffer.byteLength; i = i + 24) {
63
+ const offsetBuffer = new DataView(hashFileBuffer.buffer.slice(hashFileBuffer.byteOffset + i + 16, hashFileBuffer.byteOffset + i + 24));
64
+ const offset = offsetBuffer.getUint32(offsetBuffer.byteOffset, true);
65
+ hashArray.push({
66
+ hash: Buffer.from(hashFileBuffer.subarray(hashFileBuffer.byteOffset + i, hashFileBuffer.byteOffset + i + 16)),
67
+ offset
68
+ });
69
+ }
70
+ return hashArray;
71
+ }
72
+ /**
73
+ * Returns file with the given path from slpk archive
74
+ * @param path - path inside the slpk
75
+ * @param mode - currently only raw mode supported
76
+ * @returns buffer with ready to use file
77
+ */
78
+ async getFile(path, mode = 'raw') {
79
+ if (mode === 'http') {
80
+ const extensions = PATH_DESCRIPTIONS.find((val) => val.test.test(path))?.extensions;
81
+ if (extensions) {
82
+ let data;
83
+ for (const ext of extensions) {
84
+ data = await this.getDataByPath(`${path}${ext}`);
85
+ if (data) {
86
+ break;
87
+ }
88
+ }
89
+ if (data) {
90
+ return Buffer.from(data);
91
+ }
92
+ }
93
+ }
94
+ if (mode === 'raw') {
95
+ const decompressedFile = await this.getDataByPath(`${path}.gz`);
96
+ if (decompressedFile) {
97
+ return Buffer.from(decompressedFile);
98
+ }
99
+ const fileWithoutCompression = await this.getFileBytes(path);
100
+ if (fileWithoutCompression) {
101
+ return Buffer.from(fileWithoutCompression);
102
+ }
103
+ }
104
+ throw new Error('No such file in the archieve');
105
+ }
106
+ /**
107
+ * returning uncompressed data for paths that ends with .gz and raw data for all other paths
108
+ * @param path - path inside the archive
109
+ * @returns buffer with the file data
110
+ */
111
+ async getDataByPath(path) {
112
+ const data = await this.getFileBytes(path);
113
+ if (!data) {
114
+ return undefined;
115
+ }
116
+ if (/\.gz$/.test(path)) {
117
+ const compression = new compression_1.GZipCompression();
118
+ const decompressedData = await compression.decompress(data);
119
+ return decompressedData;
120
+ }
121
+ return Buffer.from(data);
122
+ }
123
+ /**
124
+ * Trying to get raw file data by adress
125
+ * @param path - path inside the archive
126
+ * @returns buffer with the raw file data
127
+ */
128
+ async getFileBytes(path) {
129
+ const nameHash = Buffer.from((0, md5_1.default)(path), 'hex');
130
+ const fileInfo = this.hashArray.find((val) => Buffer.compare(val.hash, nameHash) === 0);
131
+ if (!fileInfo) {
132
+ return undefined;
133
+ }
134
+ const localFileHeader = await (0, local_file_header_1.parseZipLocalFileHeader)(this.slpkArchive.byteOffset + fileInfo?.offset, new buffer_file_provider_1.DataViewFileProvider(this.slpkArchive));
135
+ if (!localFileHeader) {
136
+ return undefined;
137
+ }
138
+ const compressedFile = this.slpkArchive.buffer.slice(localFileHeader.fileDataOffset, localFileHeader.fileDataOffset + localFileHeader.compressedSize);
139
+ return compressedFile;
140
+ }
141
+ }
142
+ exports.SLPKArchive = SLPKArchive;
@@ -0,0 +1,37 @@
1
+ import { FileProvider } from './file-provider';
2
+ /**
3
+ * Provides file data using DataView
4
+ */
5
+ export declare class DataViewFileProvider implements FileProvider {
6
+ /**
7
+ * The DataView from which data is provided
8
+ */
9
+ private file;
10
+ constructor(file: DataView);
11
+ /**
12
+ * Gets an unsigned 8-bit integer at the specified byte offset from the start of the file.
13
+ * @param offset The offset, in bytes, from the start of the file where to read the data.
14
+ */
15
+ getUint8(offset: number): Promise<number>;
16
+ /**
17
+ * Gets an unsigned 16-bit integer at the specified byte offset from the start of the file.
18
+ * @param offset The offset, in bytes, from the start of the file where to read the data.
19
+ */
20
+ getUint16(offset: number): Promise<number>;
21
+ /**
22
+ * Gets an unsigned 32-bit integer at the specified byte offset from the start of the file.
23
+ * @param offset The offset, in bytes, from the start of the file where to read the data.
24
+ */
25
+ getUint32(offset: number): Promise<number>;
26
+ /**
27
+ * returns an ArrayBuffer whose contents are a copy of this file bytes from startOffset, inclusive, up to endOffset, exclusive.
28
+ * @param startOffset The offset, in bytes, from the start of the file where to start reading the data.
29
+ * @param endOffset The offset, in bytes, from the start of the file where to end reading the data.
30
+ */
31
+ slice(startOffset: number, endOffset: number): Promise<ArrayBuffer>;
32
+ /**
33
+ * the length (in bytes) of the data.
34
+ */
35
+ get length(): number;
36
+ }
37
+ //# sourceMappingURL=buffer-file-provider.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"buffer-file-provider.d.ts","sourceRoot":"","sources":["../../../../src/lib/parsers/parse-zip/buffer-file-provider.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,YAAY,EAAC,MAAM,iBAAiB,CAAC;AAE7C;;GAEG;AACH,qBAAa,oBAAqB,YAAW,YAAY;IACvD;;OAEG;IACH,OAAO,CAAC,IAAI,CAAW;gBAEX,IAAI,EAAE,QAAQ;IAI1B;;;OAGG;IACH,QAAQ,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;IAIzC;;;OAGG;IACH,SAAS,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;IAI1C;;;OAGG;IACH,SAAS,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;IAI1C;;;;OAIG;IACH,KAAK,CAAC,WAAW,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,GAAG,OAAO,CAAC,WAAW,CAAC;IAInE;;OAEG;IACH,IAAI,MAAM,WAET;CACF"}
@@ -0,0 +1,47 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.DataViewFileProvider = void 0;
4
+ /**
5
+ * Provides file data using DataView
6
+ */
7
+ class DataViewFileProvider {
8
+ constructor(file) {
9
+ this.file = file;
10
+ }
11
+ /**
12
+ * Gets an unsigned 8-bit integer at the specified byte offset from the start of the file.
13
+ * @param offset The offset, in bytes, from the start of the file where to read the data.
14
+ */
15
+ getUint8(offset) {
16
+ return Promise.resolve(this.file.getUint8(offset));
17
+ }
18
+ /**
19
+ * Gets an unsigned 16-bit integer at the specified byte offset from the start of the file.
20
+ * @param offset The offset, in bytes, from the start of the file where to read the data.
21
+ */
22
+ getUint16(offset) {
23
+ return Promise.resolve(this.file.getUint16(offset, true));
24
+ }
25
+ /**
26
+ * Gets an unsigned 32-bit integer at the specified byte offset from the start of the file.
27
+ * @param offset The offset, in bytes, from the start of the file where to read the data.
28
+ */
29
+ getUint32(offset) {
30
+ return Promise.resolve(this.file.getUint32(offset, true));
31
+ }
32
+ /**
33
+ * returns an ArrayBuffer whose contents are a copy of this file bytes from startOffset, inclusive, up to endOffset, exclusive.
34
+ * @param startOffset The offset, in bytes, from the start of the file where to start reading the data.
35
+ * @param endOffset The offset, in bytes, from the start of the file where to end reading the data.
36
+ */
37
+ slice(startOffset, endOffset) {
38
+ return Promise.resolve(this.file.buffer.slice(startOffset, endOffset));
39
+ }
40
+ /**
41
+ * the length (in bytes) of the data.
42
+ */
43
+ get length() {
44
+ return this.file.byteLength;
45
+ }
46
+ }
47
+ exports.DataViewFileProvider = DataViewFileProvider;
@@ -0,0 +1,27 @@
1
+ import { FileProvider } from './file-provider';
2
+ /**
3
+ * zip central directory file header info
4
+ * according to https://en.wikipedia.org/wiki/ZIP_(file_format)
5
+ */
6
+ export type ZipCDFileHeader = {
7
+ /** Compressed size */
8
+ compressedSize: number;
9
+ /** Uncompressed size */
10
+ uncompressedSize: number;
11
+ /** File name length */
12
+ fileNameLength: number;
13
+ /** File name */
14
+ fileName: string;
15
+ /** Extra field offset */
16
+ extraOffset: number;
17
+ /** Relative offset of local file header */
18
+ localHeaderOffset: number;
19
+ };
20
+ /**
21
+ * Parses central directory file header of zip file
22
+ * @param headerOffset - offset in the archive where header starts
23
+ * @param buffer - buffer containing whole array
24
+ * @returns Info from the header
25
+ */
26
+ export declare const parseZipCDFileHeader: (headerOffset: number, buffer: FileProvider) => Promise<ZipCDFileHeader>;
27
+ //# sourceMappingURL=cd-file-header.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cd-file-header.d.ts","sourceRoot":"","sources":["../../../../src/lib/parsers/parse-zip/cd-file-header.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,YAAY,EAAC,MAAM,iBAAiB,CAAC;AAE7C;;;GAGG;AACH,MAAM,MAAM,eAAe,GAAG;IAC5B,sBAAsB;IACtB,cAAc,EAAE,MAAM,CAAC;IACvB,wBAAwB;IACxB,gBAAgB,EAAE,MAAM,CAAC;IACzB,uBAAuB;IACvB,cAAc,EAAE,MAAM,CAAC;IACvB,gBAAgB;IAChB,QAAQ,EAAE,MAAM,CAAC;IACjB,yBAAyB;IACzB,WAAW,EAAE,MAAM,CAAC;IACpB,2CAA2C;IAC3C,iBAAiB,EAAE,MAAM,CAAC;CAC3B,CAAC;AAEF;;;;;GAKG;AACH,eAAO,MAAM,oBAAoB,iBACjB,MAAM,UACZ,YAAY,KACnB,QAAQ,eAAe,CAuDzB,CAAC"}
@@ -0,0 +1,48 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.parseZipCDFileHeader = void 0;
4
+ /**
5
+ * Parses central directory file header of zip file
6
+ * @param headerOffset - offset in the archive where header starts
7
+ * @param buffer - buffer containing whole array
8
+ * @returns Info from the header
9
+ */
10
+ const parseZipCDFileHeader = async (headerOffset, buffer) => {
11
+ const offsets = {
12
+ CD_COMPRESSED_SIZE_OFFSET: 20,
13
+ CD_UNCOMPRESSED_SIZE_OFFSET: 24,
14
+ CD_FILE_NAME_LENGTH_OFFSET: 28,
15
+ CD_EXTRA_FIELD_LENGTH_OFFSET: 30,
16
+ CD_LOCAL_HEADER_OFFSET_OFFSET: 42,
17
+ CD_FILE_NAME_OFFSET: 46
18
+ };
19
+ const compressedSize = await buffer.getUint32(headerOffset + offsets.CD_COMPRESSED_SIZE_OFFSET);
20
+ const uncompressedSize = await buffer.getUint32(headerOffset + offsets.CD_UNCOMPRESSED_SIZE_OFFSET);
21
+ const fileNameLength = await buffer.getUint16(headerOffset + offsets.CD_FILE_NAME_LENGTH_OFFSET);
22
+ const fileName = new TextDecoder().decode(await buffer.slice(headerOffset + offsets.CD_FILE_NAME_OFFSET, headerOffset + offsets.CD_FILE_NAME_OFFSET + fileNameLength));
23
+ const extraOffset = headerOffset + offsets.CD_FILE_NAME_OFFSET + fileNameLength;
24
+ const oldFormatOffset = await buffer.getUint32(headerOffset + offsets.CD_LOCAL_HEADER_OFFSET_OFFSET);
25
+ let fileDataOffset = oldFormatOffset;
26
+ if (fileDataOffset === 0xffffffff) {
27
+ let offsetInZip64Data = 4;
28
+ // looking for info that might be also be in zip64 extra field
29
+ if (compressedSize === 0xffffffff) {
30
+ offsetInZip64Data += 8;
31
+ }
32
+ if (uncompressedSize === 0xffffffff) {
33
+ offsetInZip64Data += 8;
34
+ }
35
+ // getUint32 needs to be replaced with getBigUint64 for archieves bigger than 2gb
36
+ fileDataOffset = await buffer.getUint32(extraOffset + offsetInZip64Data); // setting it to the one from zip64
37
+ }
38
+ const localHeaderOffset = fileDataOffset;
39
+ return {
40
+ compressedSize,
41
+ uncompressedSize,
42
+ fileNameLength,
43
+ fileName,
44
+ extraOffset,
45
+ localHeaderOffset
46
+ };
47
+ };
48
+ exports.parseZipCDFileHeader = parseZipCDFileHeader;
@@ -0,0 +1,31 @@
1
+ /**
2
+ * Interface for providing file data
3
+ */
4
+ export interface FileProvider {
5
+ /**
6
+ * Gets an unsigned 8-bit integer at the specified byte offset from the start of the file.
7
+ * @param offset The offset, in bytes, from the start of the file where to read the data.
8
+ */
9
+ getUint8(offset: number): Promise<number>;
10
+ /**
11
+ * Gets an unsigned 16-bit integer at the specified byte offset from the start of the file.
12
+ * @param offset The offset, in bytes, from the start of the file where to read the data.
13
+ */
14
+ getUint16(offset: number): Promise<number>;
15
+ /**
16
+ * Gets an unsigned 32-bit integer at the specified byte offset from the start of the file.
17
+ * @param offset The offset, in bytes, from the file of the view where to read the data.
18
+ */
19
+ getUint32(offset: number): Promise<number>;
20
+ /**
21
+ * returns an ArrayBuffer whose contents are a copy of this file bytes from startOffset, inclusive, up to endOffset, exclusive.
22
+ * @param startOffset The offset, in bytes, from the start of the file where to start reading the data.
23
+ * @param endOffset The offset, in bytes, from the start of the file where to end reading the data.
24
+ */
25
+ slice(startOffset: number, endOffset: number): Promise<ArrayBuffer>;
26
+ /**
27
+ * the length (in bytes) of the data.
28
+ */
29
+ length: number;
30
+ }
31
+ //# sourceMappingURL=file-provider.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"file-provider.d.ts","sourceRoot":"","sources":["../../../../src/lib/parsers/parse-zip/file-provider.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,MAAM,WAAW,YAAY;IAC3B;;;OAGG;IACH,QAAQ,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC;IAE1C;;;OAGG;IACH,SAAS,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC;IAE3C;;;OAGG;IACH,SAAS,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC;IAE3C;;;;OAIG;IACH,KAAK,CAAC,WAAW,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,GAAG,OAAO,CAAC,WAAW,CAAC,CAAC;IAEpE;;OAEG;IACH,MAAM,EAAE,MAAM,CAAC;CAChB"}
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });