@loaders.gl/i3s 3.4.0-alpha.4 → 3.4.0-alpha.5

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 (65) hide show
  1. package/dist/dist.min.js +659 -94
  2. package/dist/es5/arcgis-webscene-loader.js +1 -1
  3. package/dist/es5/i3s-attribute-loader.js +1 -1
  4. package/dist/es5/i3s-building-scene-layer-loader.js +1 -1
  5. package/dist/es5/i3s-content-loader.js +1 -1
  6. package/dist/es5/i3s-loader.js +1 -1
  7. package/dist/es5/i3s-node-page-loader.js +1 -1
  8. package/dist/es5/i3s-slpk-loader.js +20 -0
  9. package/dist/es5/i3s-slpk-loader.js.map +1 -0
  10. package/dist/es5/index.js +7 -0
  11. package/dist/es5/index.js.map +1 -1
  12. package/dist/es5/lib/parsers/parse-slpk/parse-slpk.js +94 -0
  13. package/dist/es5/lib/parsers/parse-slpk/parse-slpk.js.map +1 -0
  14. package/dist/es5/lib/parsers/parse-slpk/slpk-archieve.js +112 -0
  15. package/dist/es5/lib/parsers/parse-slpk/slpk-archieve.js.map +1 -0
  16. package/dist/es5/lib/parsers/parse-zip/cd-file-header.js +44 -0
  17. package/dist/es5/lib/parsers/parse-zip/cd-file-header.js.map +1 -0
  18. package/dist/es5/lib/parsers/parse-zip/local-file-header.js +26 -0
  19. package/dist/es5/lib/parsers/parse-zip/local-file-header.js.map +1 -0
  20. package/dist/esm/arcgis-webscene-loader.js +1 -1
  21. package/dist/esm/i3s-attribute-loader.js +1 -1
  22. package/dist/esm/i3s-building-scene-layer-loader.js +1 -1
  23. package/dist/esm/i3s-content-loader.js +1 -1
  24. package/dist/esm/i3s-loader.js +1 -1
  25. package/dist/esm/i3s-node-page-loader.js +1 -1
  26. package/dist/esm/i3s-slpk-loader.js +13 -0
  27. package/dist/esm/i3s-slpk-loader.js.map +1 -0
  28. package/dist/esm/index.js +1 -0
  29. package/dist/esm/index.js.map +1 -1
  30. package/dist/esm/lib/parsers/parse-slpk/parse-slpk.js +37 -0
  31. package/dist/esm/lib/parsers/parse-slpk/parse-slpk.js.map +1 -0
  32. package/dist/esm/lib/parsers/parse-slpk/slpk-archieve.js +58 -0
  33. package/dist/esm/lib/parsers/parse-slpk/slpk-archieve.js.map +1 -0
  34. package/dist/esm/lib/parsers/parse-zip/cd-file-header.js +37 -0
  35. package/dist/esm/lib/parsers/parse-zip/cd-file-header.js.map +1 -0
  36. package/dist/esm/lib/parsers/parse-zip/local-file-header.js +19 -0
  37. package/dist/esm/lib/parsers/parse-zip/local-file-header.js.map +1 -0
  38. package/dist/i3s-content-nodejs-worker.js +48 -48
  39. package/dist/i3s-content-nodejs-worker.js.map +3 -3
  40. package/dist/i3s-content-worker.js +68 -46
  41. package/dist/i3s-slpk-loader.d.ts +10 -0
  42. package/dist/i3s-slpk-loader.d.ts.map +1 -0
  43. package/dist/i3s-slpk-loader.js +20 -0
  44. package/dist/index.d.ts +1 -0
  45. package/dist/index.d.ts.map +1 -1
  46. package/dist/index.js +3 -1
  47. package/dist/lib/parsers/parse-slpk/parse-slpk.d.ts +4 -0
  48. package/dist/lib/parsers/parse-slpk/parse-slpk.d.ts.map +1 -0
  49. package/dist/lib/parsers/parse-slpk/parse-slpk.js +50 -0
  50. package/dist/lib/parsers/parse-slpk/slpk-archieve.d.ts +32 -0
  51. package/dist/lib/parsers/parse-slpk/slpk-archieve.d.ts.map +1 -0
  52. package/dist/lib/parsers/parse-slpk/slpk-archieve.js +79 -0
  53. package/dist/lib/parsers/parse-zip/cd-file-header.d.ts +38 -0
  54. package/dist/lib/parsers/parse-zip/cd-file-header.d.ts.map +1 -0
  55. package/dist/lib/parsers/parse-zip/cd-file-header.js +48 -0
  56. package/dist/lib/parsers/parse-zip/local-file-header.d.ts +30 -0
  57. package/dist/lib/parsers/parse-zip/local-file-header.d.ts.map +1 -0
  58. package/dist/lib/parsers/parse-zip/local-file-header.js +28 -0
  59. package/package.json +9 -8
  60. package/src/i3s-slpk-loader.ts +25 -0
  61. package/src/index.ts +1 -0
  62. package/src/lib/parsers/parse-slpk/parse-slpk.ts +61 -0
  63. package/src/lib/parsers/parse-slpk/slpk-archieve.ts +108 -0
  64. package/src/lib/parsers/parse-zip/cd-file-header.ts +93 -0
  65. package/src/lib/parsers/parse-zip/local-file-header.ts +56 -0
@@ -55,7 +55,7 @@
55
55
  var nodeVersion = matches && parseFloat(matches[1]) || 0;
56
56
 
57
57
  // ../worker-utils/src/lib/env-utils/version.ts
58
- var VERSION = true ? "3.4.0-alpha.4" : DEFAULT_VERSION;
58
+ var VERSION = true ? "3.4.0-alpha.5" : DEFAULT_VERSION;
59
59
  if (false) {
60
60
  console.error("loaders.gl: The __VERSION__ variable is not injected using babel plugin. Latest unstable workers would be fetched from the CDN.");
61
61
  }
@@ -1053,40 +1053,55 @@
1053
1053
  return "";
1054
1054
  }
1055
1055
 
1056
- // ../core/src/lib/utils/resource-utils.ts
1056
+ // ../core/src/lib/utils/url-utils.ts
1057
1057
  var QUERY_STRING_PATTERN = /\?.*/;
1058
- function getResourceUrlAndType(resource) {
1058
+ function extractQueryString(url) {
1059
+ const matches3 = url.match(QUERY_STRING_PATTERN);
1060
+ return matches3 && matches3[0];
1061
+ }
1062
+ function stripQueryString(url) {
1063
+ return url.replace(QUERY_STRING_PATTERN, "");
1064
+ }
1065
+
1066
+ // ../core/src/lib/utils/resource-utils.ts
1067
+ function getResourceUrl(resource) {
1059
1068
  if (isResponse(resource)) {
1060
- const url = stripQueryString(resource.url || "");
1061
- const contentTypeHeader = resource.headers.get("content-type") || "";
1062
- return {
1063
- url,
1064
- type: parseMIMEType(contentTypeHeader) || parseMIMETypeFromURL(url)
1065
- };
1069
+ const response = resource;
1070
+ return response.url;
1066
1071
  }
1067
1072
  if (isBlob(resource)) {
1068
- return {
1069
- url: stripQueryString(resource.name || ""),
1070
- type: resource.type || ""
1071
- };
1073
+ const blob = resource;
1074
+ return blob.name || "";
1072
1075
  }
1073
1076
  if (typeof resource === "string") {
1074
- return {
1075
- url: stripQueryString(resource),
1076
- type: parseMIMETypeFromURL(resource)
1077
- };
1077
+ return resource;
1078
1078
  }
1079
- return {
1080
- url: "",
1081
- type: ""
1082
- };
1079
+ return "";
1080
+ }
1081
+ function getResourceMIMEType(resource) {
1082
+ if (isResponse(resource)) {
1083
+ const response = resource;
1084
+ const contentTypeHeader = response.headers.get("content-type") || "";
1085
+ const noQueryUrl = stripQueryString(response.url);
1086
+ return parseMIMEType(contentTypeHeader) || parseMIMETypeFromURL(noQueryUrl);
1087
+ }
1088
+ if (isBlob(resource)) {
1089
+ const blob = resource;
1090
+ return blob.type || "";
1091
+ }
1092
+ if (typeof resource === "string") {
1093
+ return parseMIMETypeFromURL(resource);
1094
+ }
1095
+ return "";
1083
1096
  }
1084
1097
  function getResourceContentLength(resource) {
1085
1098
  if (isResponse(resource)) {
1086
- return resource.headers["content-length"] || -1;
1099
+ const response = resource;
1100
+ return response.headers["content-length"] || -1;
1087
1101
  }
1088
1102
  if (isBlob(resource)) {
1089
- return resource.size;
1103
+ const blob = resource;
1104
+ return blob.size;
1090
1105
  }
1091
1106
  if (typeof resource === "string") {
1092
1107
  return resource.length;
@@ -1099,9 +1114,6 @@
1099
1114
  }
1100
1115
  return -1;
1101
1116
  }
1102
- function stripQueryString(url) {
1103
- return url.replace(QUERY_STRING_PATTERN, "");
1104
- }
1105
1117
 
1106
1118
  // ../core/src/lib/utils/response-utils.ts
1107
1119
  async function makeResponse(resource) {
@@ -1113,7 +1125,8 @@
1113
1125
  if (contentLength >= 0) {
1114
1126
  headers["content-length"] = String(contentLength);
1115
1127
  }
1116
- const { url, type } = getResourceUrlAndType(resource);
1128
+ const url = getResourceUrl(resource);
1129
+ const type = getResourceMIMEType(resource);
1117
1130
  if (type) {
1118
1131
  headers["content-type"] = type;
1119
1132
  }
@@ -1221,7 +1234,7 @@
1221
1234
  var navigator_ = globalThis.navigator || {};
1222
1235
 
1223
1236
  // ../../node_modules/@probe.gl/env/dist/utils/globals.js
1224
- var VERSION3 = true ? "3.4.0-alpha.4" : "untranspiled source";
1237
+ var VERSION3 = true ? "3.4.0-alpha.5" : "untranspiled source";
1225
1238
  var isBrowser4 = isBrowser3();
1226
1239
 
1227
1240
  // ../../node_modules/@probe.gl/log/dist/utils/local-storage.js
@@ -1973,8 +1986,9 @@
1973
1986
  return loader;
1974
1987
  }
1975
1988
  function selectLoaderInternal(data, loaders, options, context) {
1976
- const { url, type } = getResourceUrlAndType(data);
1977
- const testUrl = url || context?.url;
1989
+ const url = getResourceUrl(data);
1990
+ const type = getResourceMIMEType(data);
1991
+ const testUrl = stripQueryString(url) || context?.url;
1978
1992
  let loader = null;
1979
1993
  let reason = "";
1980
1994
  if (options?.mimeType) {
@@ -2003,7 +2017,8 @@
2003
2017
  return true;
2004
2018
  }
2005
2019
  function getNoValidLoaderMessage(data) {
2006
- const { url, type } = getResourceUrlAndType(data);
2020
+ const url = getResourceUrl(data);
2021
+ const type = getResourceMIMEType(data);
2007
2022
  let message = "No valid loader found (";
2008
2023
  message += url ? `${path_exports.filename(url)}, ` : "no url provided, ";
2009
2024
  message += `MIME type: ${type ? `"${type}"` : "not provided"}, `;
@@ -2277,18 +2292,25 @@
2277
2292
  }
2278
2293
 
2279
2294
  // ../core/src/lib/loader-utils/loader-context.ts
2280
- function getLoaderContext(context, options, previousContext = null) {
2281
- if (previousContext) {
2282
- return previousContext;
2295
+ function getLoaderContext(context, options, parentContext) {
2296
+ if (parentContext) {
2297
+ return parentContext;
2283
2298
  }
2284
- const resolvedContext = {
2299
+ const newContext = {
2285
2300
  fetch: getFetchFunction(options, context),
2286
2301
  ...context
2287
2302
  };
2288
- if (!Array.isArray(resolvedContext.loaders)) {
2289
- resolvedContext.loaders = null;
2303
+ if (newContext.url) {
2304
+ const baseUrl = stripQueryString(newContext.url);
2305
+ newContext.baseUrl = baseUrl;
2306
+ newContext.queryString = extractQueryString(newContext.url);
2307
+ newContext.filename = path_exports.filename(baseUrl);
2308
+ newContext.baseUrl = path_exports.dirname(baseUrl);
2309
+ }
2310
+ if (!Array.isArray(newContext.loaders)) {
2311
+ newContext.loaders = null;
2290
2312
  }
2291
- return resolvedContext;
2313
+ return newContext;
2292
2314
  }
2293
2315
  function getLoadersFromContext(loaders, context) {
2294
2316
  if (!context && loaders && !Array.isArray(loaders)) {
@@ -2315,7 +2337,7 @@
2315
2337
  }
2316
2338
  data = await data;
2317
2339
  options = options || {};
2318
- const { url } = getResourceUrlAndType(data);
2340
+ const url = getResourceUrl(data);
2319
2341
  const typedLoaders = loaders;
2320
2342
  const candidateLoaders = getLoadersFromContext(typedLoaders, context);
2321
2343
  const loader = await selectLoader(data, candidateLoaders, options);
@@ -2323,7 +2345,7 @@
2323
2345
  return null;
2324
2346
  }
2325
2347
  options = normalizeOptions(options, loader, candidateLoaders, url);
2326
- context = getLoaderContext({ url, parse, loaders: candidateLoaders }, options, context);
2348
+ context = getLoaderContext({ url, parse, loaders: candidateLoaders }, options, context || null);
2327
2349
  return await parseWithLoader(loader, data, options, context);
2328
2350
  }
2329
2351
  async function parseWithLoader(loader, data, options, context) {
@@ -4555,7 +4577,7 @@
4555
4577
  _defineProperty(Ellipsoid, "WGS84", new Ellipsoid(WGS84_RADIUS_X, WGS84_RADIUS_Y, WGS84_RADIUS_Z));
4556
4578
 
4557
4579
  // ../images/src/lib/utils/version.ts
4558
- var VERSION4 = true ? "3.4.0-alpha.4" : "latest";
4580
+ var VERSION4 = true ? "3.4.0-alpha.5" : "latest";
4559
4581
 
4560
4582
  // ../images/src/lib/category-api/image-type.ts
4561
4583
  var { _parseImageNode } = globalThis;
@@ -4952,7 +4974,7 @@
4952
4974
  };
4953
4975
 
4954
4976
  // ../draco/src/lib/utils/version.ts
4955
- var VERSION5 = true ? "3.4.0-alpha.4" : "latest";
4977
+ var VERSION5 = true ? "3.4.0-alpha.5" : "latest";
4956
4978
 
4957
4979
  // ../draco/src/draco-loader.ts
4958
4980
  var DEFAULT_DRACO_OPTIONS = {
@@ -5938,10 +5960,10 @@
5938
5960
  }
5939
5961
 
5940
5962
  // ../textures/src/lib/utils/version.ts
5941
- var VERSION6 = true ? "3.4.0-alpha.4" : "beta";
5963
+ var VERSION6 = true ? "3.4.0-alpha.5" : "beta";
5942
5964
 
5943
5965
  // ../textures/src/lib/parsers/basis-module-loader.ts
5944
- var VERSION7 = true ? "3.4.0-alpha.4" : "beta";
5966
+ var VERSION7 = true ? "3.4.0-alpha.5" : "beta";
5945
5967
  var BASIS_CDN_ENCODER_WASM = `https://unpkg.com/@loaders.gl/textures@${VERSION7}/dist/libs/basis_encoder.wasm`;
5946
5968
  var BASIS_CDN_ENCODER_JS = `https://unpkg.com/@loaders.gl/textures@${VERSION7}/dist/libs/basis_encoder.js`;
5947
5969
  var loadBasisTranscoderPromise;
@@ -7639,7 +7661,7 @@
7639
7661
  }
7640
7662
 
7641
7663
  // src/i3s-attribute-loader.ts
7642
- var VERSION8 = true ? "3.4.0-alpha.4" : "latest";
7664
+ var VERSION8 = true ? "3.4.0-alpha.5" : "latest";
7643
7665
  var I3SAttributeLoader = {
7644
7666
  name: "I3S Attribute",
7645
7667
  id: "i3s-attribute",
@@ -8100,7 +8122,7 @@
8100
8122
  }
8101
8123
 
8102
8124
  // src/i3s-content-loader.ts
8103
- var VERSION9 = true ? "3.4.0-alpha.4" : "beta";
8125
+ var VERSION9 = true ? "3.4.0-alpha.5" : "beta";
8104
8126
  var I3SContentLoader = {
8105
8127
  name: "I3S Content (Indexed Scene Layers)",
8106
8128
  id: isBrowser2 ? "i3s-content" : "i3s-content-nodejs",
@@ -0,0 +1,10 @@
1
+ import { LoaderOptions, LoaderWithParser } from '@loaders.gl/loader-utils';
2
+ export type SLPKLoaderOptions = LoaderOptions & {
3
+ path?: string;
4
+ mode?: 'http' | 'raw';
5
+ };
6
+ /**
7
+ * Loader for SLPK - Scene Layer Package
8
+ */
9
+ export declare const SLPKLoader: LoaderWithParser;
10
+ //# sourceMappingURL=i3s-slpk-loader.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"i3s-slpk-loader.d.ts","sourceRoot":"","sources":["../src/i3s-slpk-loader.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,aAAa,EAAE,gBAAgB,EAAC,MAAM,0BAA0B,CAAC;AAOzE,MAAM,MAAM,iBAAiB,GAAG,aAAa,GAAG;IAC9C,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,IAAI,CAAC,EAAE,MAAM,GAAG,KAAK,CAAC;CACvB,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,UAAU,EAAE,gBASxB,CAAC"}
@@ -0,0 +1,20 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.SLPKLoader = void 0;
4
+ const parse_slpk_1 = require("./lib/parsers/parse-slpk/parse-slpk");
5
+ // __VERSION__ is injected by babel-plugin-version-inline
6
+ // @ts-ignore TS2304: Cannot find name '__VERSION__'.
7
+ const VERSION = typeof __VERSION__ !== 'undefined' ? __VERSION__ : 'latest';
8
+ /**
9
+ * Loader for SLPK - Scene Layer Package
10
+ */
11
+ exports.SLPKLoader = {
12
+ name: 'I3S SLPK (Scene Layer Package)',
13
+ id: 'slpk',
14
+ module: 'i3s',
15
+ version: VERSION,
16
+ mimeTypes: ['application/octet-stream'],
17
+ parse: parse_slpk_1.parseSLPK,
18
+ extensions: ['slpk'],
19
+ options: {}
20
+ };
package/dist/index.d.ts CHANGED
@@ -1,4 +1,5 @@
1
1
  export { I3SLoader } from './i3s-loader';
2
+ export { SLPKLoader } from './i3s-slpk-loader';
2
3
  export { I3SContentLoader } from './i3s-content-loader';
3
4
  export { I3SAttributeLoader, loadFeatureAttributes } from './i3s-attribute-loader';
4
5
  export { I3SBuildingSceneLayerLoader } from './i3s-building-scene-layer-loader';
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,SAAS,EAAC,MAAM,cAAc,CAAC;AACvC,OAAO,EAAC,gBAAgB,EAAC,MAAM,sBAAsB,CAAC;AACtD,OAAO,EAAC,kBAAkB,EAAE,qBAAqB,EAAC,MAAM,wBAAwB,CAAC;AACjF,OAAO,EAAC,2BAA2B,EAAC,MAAM,mCAAmC,CAAC;AAC9E,OAAO,EAAC,oBAAoB,EAAC,MAAM,0BAA0B,CAAC;AAC9D,YAAY,EACV,eAAe,EACf,GAAG,EACH,GAAG,EACH,YAAY,EACZ,oBAAoB,EACpB,KAAK,EACL,SAAS,EACT,SAAS,EACT,mBAAmB,EACnB,YAAY,EACZ,aAAa,EACb,QAAQ,EACR,oBAAoB,EACpB,UAAU,EACV,eAAe,EACf,SAAS,EACT,MAAM,EACN,gBAAgB,EAChB,SAAS,EACT,qBAAqB,EACrB,qBAAqB,EACrB,sBAAsB,EACtB,UAAU,EACV,cAAc,EACd,SAAS,EACT,SAAS,EACT,UAAU,EACV,qBAAqB,EACrB,SAAS,EACT,gBAAgB,EACjB,MAAM,SAAS,CAAC;AACjB,OAAO,EAAC,iBAAiB,EAAC,MAAM,yBAAyB,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,SAAS,EAAC,MAAM,cAAc,CAAC;AACvC,OAAO,EAAC,UAAU,EAAC,MAAM,mBAAmB,CAAC;AAC7C,OAAO,EAAC,gBAAgB,EAAC,MAAM,sBAAsB,CAAC;AACtD,OAAO,EAAC,kBAAkB,EAAE,qBAAqB,EAAC,MAAM,wBAAwB,CAAC;AACjF,OAAO,EAAC,2BAA2B,EAAC,MAAM,mCAAmC,CAAC;AAC9E,OAAO,EAAC,oBAAoB,EAAC,MAAM,0BAA0B,CAAC;AAC9D,YAAY,EACV,eAAe,EACf,GAAG,EACH,GAAG,EACH,YAAY,EACZ,oBAAoB,EACpB,KAAK,EACL,SAAS,EACT,SAAS,EACT,mBAAmB,EACnB,YAAY,EACZ,aAAa,EACb,QAAQ,EACR,oBAAoB,EACpB,UAAU,EACV,eAAe,EACf,SAAS,EACT,MAAM,EACN,gBAAgB,EAChB,SAAS,EACT,qBAAqB,EACrB,qBAAqB,EACrB,sBAAsB,EACtB,UAAU,EACV,cAAc,EACd,SAAS,EACT,SAAS,EACT,UAAU,EACV,qBAAqB,EACrB,SAAS,EACT,gBAAgB,EACjB,MAAM,SAAS,CAAC;AACjB,OAAO,EAAC,iBAAiB,EAAC,MAAM,yBAAyB,CAAC"}
package/dist/index.js CHANGED
@@ -1,8 +1,10 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.COORDINATE_SYSTEM = exports.ArcGisWebSceneLoader = exports.I3SBuildingSceneLayerLoader = exports.loadFeatureAttributes = exports.I3SAttributeLoader = exports.I3SContentLoader = exports.I3SLoader = void 0;
3
+ exports.COORDINATE_SYSTEM = exports.ArcGisWebSceneLoader = exports.I3SBuildingSceneLayerLoader = exports.loadFeatureAttributes = exports.I3SAttributeLoader = exports.I3SContentLoader = exports.SLPKLoader = exports.I3SLoader = void 0;
4
4
  var i3s_loader_1 = require("./i3s-loader");
5
5
  Object.defineProperty(exports, "I3SLoader", { enumerable: true, get: function () { return i3s_loader_1.I3SLoader; } });
6
+ var i3s_slpk_loader_1 = require("./i3s-slpk-loader");
7
+ Object.defineProperty(exports, "SLPKLoader", { enumerable: true, get: function () { return i3s_slpk_loader_1.SLPKLoader; } });
6
8
  var i3s_content_loader_1 = require("./i3s-content-loader");
7
9
  Object.defineProperty(exports, "I3SContentLoader", { enumerable: true, get: function () { return i3s_content_loader_1.I3SContentLoader; } });
8
10
  var i3s_attribute_loader_1 = require("./i3s-attribute-loader");
@@ -0,0 +1,4 @@
1
+ /// <reference types="node" />
2
+ import { SLPKLoaderOptions } from 'modules/i3s/src/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,EAAC,iBAAiB,EAAC,MAAM,iCAAiC,CAAC;AAelE,wBAAsB,SAAS,CAAC,IAAI,EAAE,WAAW,EAAE,OAAO,GAAE,iBAAsB,mBA6CjF"}
@@ -0,0 +1,50 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.parseSLPK = void 0;
4
+ const cd_file_header_1 = require("../parse-zip/cd-file-header");
5
+ const local_file_header_1 = require("../parse-zip/local-file-header");
6
+ const slpk_archieve_1 = require("./slpk-archieve");
7
+ /**
8
+ * Returns one byte from the provided buffer at the provided position
9
+ * @param offset - position where to read
10
+ * @param buffer - buffer to read
11
+ * @returns one byte from the provided buffer at the provided position
12
+ */
13
+ const getByteAt = (offset, buffer) => {
14
+ return buffer.getUint8(buffer.byteOffset + offset);
15
+ };
16
+ async function parseSLPK(data, options = {}) {
17
+ const archive = new DataView(data);
18
+ const cdFileHeaderSignature = [80, 75, 1, 2];
19
+ const searchWindow = [
20
+ getByteAt(archive.byteLength - 1, archive),
21
+ getByteAt(archive.byteLength - 2, archive),
22
+ getByteAt(archive.byteLength - 3, archive),
23
+ undefined
24
+ ];
25
+ let hashCDOffset = 0;
26
+ // looking for the last record in the central directory
27
+ for (let i = archive.byteLength - 4; i > -1; i--) {
28
+ searchWindow[3] = searchWindow[2];
29
+ searchWindow[2] = searchWindow[1];
30
+ searchWindow[1] = searchWindow[0];
31
+ searchWindow[0] = getByteAt(i, archive);
32
+ if (searchWindow.every((val, index) => val === cdFileHeaderSignature[index])) {
33
+ hashCDOffset = i;
34
+ break;
35
+ }
36
+ }
37
+ const cdFileHeader = (0, cd_file_header_1.parseZipCDFileHeader)(hashCDOffset, archive);
38
+ const textDecoder = new TextDecoder();
39
+ if (textDecoder.decode(cdFileHeader.fileName) !== '@specialIndexFileHASH128@') {
40
+ throw new Error('No hash file in slpk');
41
+ }
42
+ const localFileHeader = (0, local_file_header_1.parseZipLocalFileHeader)(cdFileHeader.localHeaderOffset, archive);
43
+ const fileDataOffset = localFileHeader.fileDataOffset;
44
+ const hashFile = archive.buffer.slice(fileDataOffset, fileDataOffset + localFileHeader.compressedSize);
45
+ if (!hashFile) {
46
+ throw new Error('No hash file in slpk');
47
+ }
48
+ return await new slpk_archieve_1.SLPKArchive(data, hashFile).getFile(options.path ?? '');
49
+ }
50
+ exports.parseSLPK = parseSLPK;
@@ -0,0 +1,32 @@
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
+ * Trying to get raw file data by adress
27
+ * @param path - path inside the archive
28
+ * @returns buffer with the raw file data
29
+ */
30
+ private getFileBytes;
31
+ }
32
+ //# 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":";AAiBA;;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;IAuB1E;;;;OAIG;IACH,OAAO,CAAC,YAAY;CAmBrB"}
@@ -0,0 +1,79 @@
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 worker_utils_1 = require("@loaders.gl/worker-utils");
8
+ const md5_1 = __importDefault(require("md5"));
9
+ const compression_1 = require("@loaders.gl/compression");
10
+ const local_file_header_1 = require("../parse-zip/local-file-header");
11
+ /**
12
+ * Class for handling information about slpk file
13
+ */
14
+ class SLPKArchive {
15
+ constructor(slpkArchiveBuffer, hashFile) {
16
+ this.slpkArchive = new DataView(slpkArchiveBuffer);
17
+ this.hashArray = this.parseHashFile(hashFile);
18
+ }
19
+ /**
20
+ * Reads hash file from buffer and returns it in ready-to-use form
21
+ * @param hashFile - bufer containing hash file
22
+ * @returns Array containing file info
23
+ */
24
+ parseHashFile(hashFile) {
25
+ const hashFileBuffer = Buffer.from(hashFile);
26
+ const hashArray = [];
27
+ for (let i = 0; i < hashFileBuffer.buffer.byteLength; i = i + 24) {
28
+ const offsetBuffer = new DataView(hashFileBuffer.buffer.slice(hashFileBuffer.byteOffset + i + 16, hashFileBuffer.byteOffset + i + 24));
29
+ const offset = offsetBuffer.getUint32(offsetBuffer.byteOffset, true);
30
+ hashArray.push({
31
+ hash: Buffer.from(hashFileBuffer.subarray(hashFileBuffer.byteOffset + i, hashFileBuffer.byteOffset + i + 16)),
32
+ offset
33
+ });
34
+ }
35
+ return hashArray;
36
+ }
37
+ /**
38
+ * Returns file with the given path from slpk archive
39
+ * @param path - path inside the slpk
40
+ * @param mode - currently only raw mode supported
41
+ * @returns buffer with ready to use file
42
+ */
43
+ async getFile(path, mode = 'raw') {
44
+ if (mode === 'http') {
45
+ throw new Error('http mode is not supported');
46
+ }
47
+ const fileToDecompress = this.getFileBytes(`${path}.gz`);
48
+ if (fileToDecompress) {
49
+ const decompressedData = await (0, worker_utils_1.processOnWorker)(compression_1.CompressionWorker, fileToDecompress, {
50
+ compression: 'gzip',
51
+ operation: 'decompress',
52
+ _workerType: 'test',
53
+ gzip: {}
54
+ });
55
+ return decompressedData;
56
+ }
57
+ const fileWithoutCompression = this.getFileBytes(path);
58
+ if (fileWithoutCompression) {
59
+ return Promise.resolve(Buffer.from(fileWithoutCompression));
60
+ }
61
+ throw new Error('No such file in the archieve');
62
+ }
63
+ /**
64
+ * Trying to get raw file data by adress
65
+ * @param path - path inside the archive
66
+ * @returns buffer with the raw file data
67
+ */
68
+ getFileBytes(path) {
69
+ const nameHash = Buffer.from((0, md5_1.default)(path), 'hex');
70
+ const fileInfo = this.hashArray.find((val) => Buffer.compare(val.hash, nameHash) === 0);
71
+ if (!fileInfo) {
72
+ return undefined;
73
+ }
74
+ const localFileHeader = (0, local_file_header_1.parseZipLocalFileHeader)(this.slpkArchive.byteOffset + fileInfo?.offset, this.slpkArchive);
75
+ const compressedFile = this.slpkArchive.buffer.slice(localFileHeader.fileDataOffset, localFileHeader.fileDataOffset + localFileHeader.compressedSize);
76
+ return compressedFile;
77
+ }
78
+ }
79
+ exports.SLPKArchive = SLPKArchive;
@@ -0,0 +1,38 @@
1
+ /**
2
+ * zip central directory file header info
3
+ * according to https://en.wikipedia.org/wiki/ZIP_(file_format)
4
+ */
5
+ export type ZipCDFileHeader = {
6
+ /**
7
+ * Compressed size
8
+ */
9
+ compressedSize: number;
10
+ /**
11
+ * Uncompressed size
12
+ */
13
+ uncompressedSize: number;
14
+ /**
15
+ * File name length
16
+ */
17
+ fileNameLength: number;
18
+ /**
19
+ * File name
20
+ */
21
+ fileName: ArrayBuffer;
22
+ /**
23
+ * Extra field offset
24
+ */
25
+ extraOffset: number;
26
+ /**
27
+ * Relative offset of local file header
28
+ */
29
+ localHeaderOffset: number;
30
+ };
31
+ /**
32
+ * Parses central directory file header of zip file
33
+ * @param headerOffset - offset in the archive where header starts
34
+ * @param buffer - buffer containing whole array
35
+ * @returns Info from the header
36
+ */
37
+ export declare const parseZipCDFileHeader: (headerOffset: number, buffer: DataView) => ZipCDFileHeader;
38
+ //# 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;;;GAGG;AACH,MAAM,MAAM,eAAe,GAAG;IAC5B;;OAEG;IACH,cAAc,EAAE,MAAM,CAAC;IACvB;;OAEG;IACH,gBAAgB,EAAE,MAAM,CAAC;IACzB;;OAEG;IACH,cAAc,EAAE,MAAM,CAAC;IACvB;;OAEG;IACH,QAAQ,EAAE,WAAW,CAAC;IACtB;;OAEG;IACH,WAAW,EAAE,MAAM,CAAC;IACpB;;OAEG;IACH,iBAAiB,EAAE,MAAM,CAAC;CAC3B,CAAC;AAEF;;;;;GAKG;AACH,eAAO,MAAM,oBAAoB,iBAAkB,MAAM,UAAU,QAAQ,KAAG,eAuD7E,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 = (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 = buffer.getUint32(headerOffset + offsets.CD_COMPRESSED_SIZE_OFFSET, true);
20
+ const uncompressedSize = buffer.getUint32(headerOffset + offsets.CD_UNCOMPRESSED_SIZE_OFFSET, true);
21
+ const fileNameLength = buffer.getUint16(headerOffset + offsets.CD_FILE_NAME_LENGTH_OFFSET, true);
22
+ const fileName = buffer.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 = buffer.getUint32(headerOffset + offsets.CD_LOCAL_HEADER_OFFSET_OFFSET, true);
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 = buffer.getUint32(extraOffset + offsetInZip64Data, true); // 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,30 @@
1
+ /**
2
+ * zip local file header info
3
+ * according to https://en.wikipedia.org/wiki/ZIP_(file_format)
4
+ */
5
+ export type ZipLocalFileHeader = {
6
+ /**
7
+ * File name length
8
+ */
9
+ fileNameLength: number;
10
+ /**
11
+ * Extra field length
12
+ */
13
+ extraFieldLength: number;
14
+ /**
15
+ * Offset of the file data
16
+ */
17
+ fileDataOffset: number;
18
+ /**
19
+ * Compressed size
20
+ */
21
+ compressedSize: number;
22
+ };
23
+ /**
24
+ * Parses local file header of zip file
25
+ * @param headerOffset - offset in the archive where header starts
26
+ * @param buffer - buffer containing whole array
27
+ * @returns Info from the header
28
+ */
29
+ export declare const parseZipLocalFileHeader: (headerOffset: number, buffer: DataView) => ZipLocalFileHeader;
30
+ //# sourceMappingURL=local-file-header.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"local-file-header.d.ts","sourceRoot":"","sources":["../../../../src/lib/parsers/parse-zip/local-file-header.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,MAAM,MAAM,kBAAkB,GAAG;IAC/B;;OAEG;IACH,cAAc,EAAE,MAAM,CAAC;IACvB;;OAEG;IACH,gBAAgB,EAAE,MAAM,CAAC;IACzB;;OAEG;IACH,cAAc,EAAE,MAAM,CAAC;IACvB;;OAEG;IACH,cAAc,EAAE,MAAM,CAAC;CACxB,CAAC;AAEF;;;;;GAKG;AACH,eAAO,MAAM,uBAAuB,iBACpB,MAAM,UACZ,QAAQ,KACf,kBAuBF,CAAC"}
@@ -0,0 +1,28 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.parseZipLocalFileHeader = void 0;
4
+ /**
5
+ * Parses local 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 parseZipLocalFileHeader = (headerOffset, buffer) => {
11
+ const offsets = {
12
+ COMPRESSED_SIZE_OFFSET: 18,
13
+ FILE_NAME_LENGTH_OFFSET: 26,
14
+ EXTRA_FIELD_LENGTH_OFFSET: 28,
15
+ FILE_NAME_OFFSET: 30
16
+ };
17
+ const fileNameLength = buffer.getUint16(headerOffset + offsets.FILE_NAME_LENGTH_OFFSET, true);
18
+ const extraFieldLength = buffer.getUint16(headerOffset + offsets.EXTRA_FIELD_LENGTH_OFFSET, true);
19
+ const fileDataOffset = headerOffset + offsets.FILE_NAME_OFFSET + fileNameLength + extraFieldLength;
20
+ const compressedSize = buffer.getUint32(headerOffset + offsets.COMPRESSED_SIZE_OFFSET, true);
21
+ return {
22
+ fileNameLength,
23
+ extraFieldLength,
24
+ fileDataOffset,
25
+ compressedSize
26
+ };
27
+ };
28
+ exports.parseZipLocalFileHeader = parseZipLocalFileHeader;