@loaders.gl/i3s 4.0.0-alpha.18 → 4.0.0-alpha.20

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 (107) hide show
  1. package/dist/dist.min.js +338 -307
  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 +3 -3
  9. package/dist/es5/i3s-slpk-loader.js.map +1 -1
  10. package/dist/es5/index.js +0 -7
  11. package/dist/es5/index.js.map +1 -1
  12. package/dist/es5/lib/parsers/parse-i3s.js +1 -0
  13. package/dist/es5/lib/parsers/parse-i3s.js.map +1 -1
  14. package/dist/es5/lib/parsers/parse-slpk/parse-slpk.js +9 -25
  15. package/dist/es5/lib/parsers/parse-slpk/parse-slpk.js.map +1 -1
  16. package/dist/es5/lib/parsers/parse-slpk/slpk-archieve.js +9 -33
  17. package/dist/es5/lib/parsers/parse-slpk/slpk-archieve.js.map +1 -1
  18. package/dist/es5/types.js.map +1 -1
  19. package/dist/esm/arcgis-webscene-loader.js +1 -1
  20. package/dist/esm/i3s-attribute-loader.js +1 -1
  21. package/dist/esm/i3s-building-scene-layer-loader.js +1 -1
  22. package/dist/esm/i3s-content-loader.js +1 -1
  23. package/dist/esm/i3s-loader.js +1 -1
  24. package/dist/esm/i3s-node-page-loader.js +1 -1
  25. package/dist/esm/i3s-slpk-loader.js +3 -3
  26. package/dist/esm/i3s-slpk-loader.js.map +1 -1
  27. package/dist/esm/index.js +0 -1
  28. package/dist/esm/index.js.map +1 -1
  29. package/dist/esm/lib/parsers/parse-i3s.js +1 -0
  30. package/dist/esm/lib/parsers/parse-i3s.js.map +1 -1
  31. package/dist/esm/lib/parsers/parse-slpk/parse-slpk.js +2 -18
  32. package/dist/esm/lib/parsers/parse-slpk/parse-slpk.js.map +1 -1
  33. package/dist/esm/lib/parsers/parse-slpk/slpk-archieve.js +5 -29
  34. package/dist/esm/lib/parsers/parse-slpk/slpk-archieve.js.map +1 -1
  35. package/dist/esm/types.js.map +1 -1
  36. package/dist/i3s-content-worker-node.js +47 -47
  37. package/dist/i3s-content-worker-node.js.map +2 -2
  38. package/dist/i3s-content-worker.js +51 -38
  39. package/dist/i3s-slpk-loader.js +2 -2
  40. package/dist/index.d.ts +0 -2
  41. package/dist/index.d.ts.map +1 -1
  42. package/dist/index.js +1 -3
  43. package/dist/lib/parsers/parse-i3s.d.ts.map +1 -1
  44. package/dist/lib/parsers/parse-i3s.js +1 -0
  45. package/dist/lib/parsers/parse-slpk/parse-slpk.d.ts +1 -1
  46. package/dist/lib/parsers/parse-slpk/parse-slpk.d.ts.map +1 -1
  47. package/dist/lib/parsers/parse-slpk/parse-slpk.js +9 -30
  48. package/dist/lib/parsers/parse-slpk/slpk-archieve.d.ts +2 -21
  49. package/dist/lib/parsers/parse-slpk/slpk-archieve.d.ts.map +1 -1
  50. package/dist/lib/parsers/parse-slpk/slpk-archieve.js +7 -46
  51. package/dist/types.d.ts +3 -0
  52. package/dist/types.d.ts.map +1 -1
  53. package/package.json +9 -9
  54. package/src/i3s-slpk-loader.ts +2 -2
  55. package/src/index.ts +0 -2
  56. package/src/lib/parsers/parse-i3s.ts +1 -0
  57. package/src/lib/parsers/parse-slpk/parse-slpk.ts +12 -32
  58. package/src/lib/parsers/parse-slpk/slpk-archieve.ts +5 -54
  59. package/src/types.ts +3 -0
  60. package/dist/es5/lib/parsers/parse-zip/cd-file-header.js +0 -121
  61. package/dist/es5/lib/parsers/parse-zip/cd-file-header.js.map +0 -1
  62. package/dist/es5/lib/parsers/parse-zip/data-view-file-provider.js +0 -129
  63. package/dist/es5/lib/parsers/parse-zip/data-view-file-provider.js.map +0 -1
  64. package/dist/es5/lib/parsers/parse-zip/end-of-central-directory.js +0 -100
  65. package/dist/es5/lib/parsers/parse-zip/end-of-central-directory.js.map +0 -1
  66. package/dist/es5/lib/parsers/parse-zip/file-provider.js +0 -2
  67. package/dist/es5/lib/parsers/parse-zip/file-provider.js.map +0 -1
  68. package/dist/es5/lib/parsers/parse-zip/local-file-header.js +0 -113
  69. package/dist/es5/lib/parsers/parse-zip/local-file-header.js.map +0 -1
  70. package/dist/es5/lib/parsers/parse-zip/search-from-the-end.js +0 -69
  71. package/dist/es5/lib/parsers/parse-zip/search-from-the-end.js.map +0 -1
  72. package/dist/esm/lib/parsers/parse-zip/cd-file-header.js +0 -45
  73. package/dist/esm/lib/parsers/parse-zip/cd-file-header.js.map +0 -1
  74. package/dist/esm/lib/parsers/parse-zip/data-view-file-provider.js +0 -32
  75. package/dist/esm/lib/parsers/parse-zip/data-view-file-provider.js.map +0 -1
  76. package/dist/esm/lib/parsers/parse-zip/end-of-central-directory.js +0 -33
  77. package/dist/esm/lib/parsers/parse-zip/end-of-central-directory.js.map +0 -1
  78. package/dist/esm/lib/parsers/parse-zip/file-provider.js +0 -2
  79. package/dist/esm/lib/parsers/parse-zip/file-provider.js.map +0 -1
  80. package/dist/esm/lib/parsers/parse-zip/local-file-header.js +0 -40
  81. package/dist/esm/lib/parsers/parse-zip/local-file-header.js.map +0 -1
  82. package/dist/esm/lib/parsers/parse-zip/search-from-the-end.js +0 -16
  83. package/dist/esm/lib/parsers/parse-zip/search-from-the-end.js.map +0 -1
  84. package/dist/lib/parsers/parse-zip/cd-file-header.d.ts +0 -31
  85. package/dist/lib/parsers/parse-zip/cd-file-header.d.ts.map +0 -1
  86. package/dist/lib/parsers/parse-zip/cd-file-header.js +0 -55
  87. package/dist/lib/parsers/parse-zip/data-view-file-provider.d.ts +0 -36
  88. package/dist/lib/parsers/parse-zip/data-view-file-provider.d.ts.map +0 -1
  89. package/dist/lib/parsers/parse-zip/data-view-file-provider.js +0 -61
  90. package/dist/lib/parsers/parse-zip/end-of-central-directory.d.ts +0 -18
  91. package/dist/lib/parsers/parse-zip/end-of-central-directory.d.ts.map +0 -1
  92. package/dist/lib/parsers/parse-zip/end-of-central-directory.js +0 -41
  93. package/dist/lib/parsers/parse-zip/file-provider.d.ts +0 -36
  94. package/dist/lib/parsers/parse-zip/file-provider.d.ts.map +0 -1
  95. package/dist/lib/parsers/parse-zip/file-provider.js +0 -2
  96. package/dist/lib/parsers/parse-zip/local-file-header.d.ts +0 -27
  97. package/dist/lib/parsers/parse-zip/local-file-header.d.ts.map +0 -1
  98. package/dist/lib/parsers/parse-zip/local-file-header.js +0 -53
  99. package/dist/lib/parsers/parse-zip/search-from-the-end.d.ts +0 -11
  100. package/dist/lib/parsers/parse-zip/search-from-the-end.d.ts.map +0 -1
  101. package/dist/lib/parsers/parse-zip/search-from-the-end.js +0 -31
  102. package/src/lib/parsers/parse-zip/cd-file-header.ts +0 -106
  103. package/src/lib/parsers/parse-zip/data-view-file-provider.ts +0 -69
  104. package/src/lib/parsers/parse-zip/end-of-central-directory.ts +0 -78
  105. package/src/lib/parsers/parse-zip/file-provider.ts +0 -40
  106. package/src/lib/parsers/parse-zip/local-file-header.ts +0 -91
  107. package/src/lib/parsers/parse-zip/search-from-the-end.ts +0 -38
@@ -1,55 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.parseZipCDFileHeader = exports.signature = void 0;
4
- const offsets = {
5
- CD_COMPRESSED_SIZE_OFFSET: 20n,
6
- CD_UNCOMPRESSED_SIZE_OFFSET: 24n,
7
- CD_FILE_NAME_LENGTH_OFFSET: 28n,
8
- CD_EXTRA_FIELD_LENGTH_OFFSET: 30n,
9
- CD_LOCAL_HEADER_OFFSET_OFFSET: 42n,
10
- CD_FILE_NAME_OFFSET: 46n
11
- };
12
- exports.signature = [0x50, 0x4b, 0x01, 0x02];
13
- /**
14
- * Parses central directory file header of zip file
15
- * @param headerOffset - offset in the archive where header starts
16
- * @param buffer - buffer containing whole array
17
- * @returns Info from the header
18
- */
19
- const parseZipCDFileHeader = async (headerOffset, buffer) => {
20
- if (Buffer.from(await buffer.slice(headerOffset, headerOffset + 4n)).compare(Buffer.from(exports.signature)) !== 0) {
21
- return null;
22
- }
23
- let compressedSize = BigInt(await buffer.getUint32(headerOffset + offsets.CD_COMPRESSED_SIZE_OFFSET));
24
- let uncompressedSize = BigInt(await buffer.getUint32(headerOffset + offsets.CD_UNCOMPRESSED_SIZE_OFFSET));
25
- const extraFieldLength = await buffer.getUint16(headerOffset + offsets.CD_EXTRA_FIELD_LENGTH_OFFSET);
26
- const fileNameLength = await buffer.getUint16(headerOffset + offsets.CD_FILE_NAME_LENGTH_OFFSET);
27
- const fileName = new TextDecoder().decode(await buffer.slice(headerOffset + offsets.CD_FILE_NAME_OFFSET, headerOffset + offsets.CD_FILE_NAME_OFFSET + BigInt(fileNameLength)));
28
- const extraOffset = headerOffset + offsets.CD_FILE_NAME_OFFSET + BigInt(fileNameLength);
29
- const oldFormatOffset = await buffer.getUint32(headerOffset + offsets.CD_LOCAL_HEADER_OFFSET_OFFSET);
30
- let fileDataOffset = BigInt(oldFormatOffset);
31
- let offsetInZip64Data = 4n;
32
- // looking for info that might be also be in zip64 extra field
33
- if (uncompressedSize === BigInt(0xffffffff)) {
34
- uncompressedSize = await buffer.getBigUint64(extraOffset + offsetInZip64Data);
35
- offsetInZip64Data += 8n;
36
- }
37
- if (compressedSize === BigInt(0xffffffff)) {
38
- compressedSize = await buffer.getBigUint64(extraOffset + offsetInZip64Data);
39
- offsetInZip64Data += 8n;
40
- }
41
- if (fileDataOffset === BigInt(0xffffffff)) {
42
- fileDataOffset = await buffer.getBigUint64(extraOffset + offsetInZip64Data); // setting it to the one from zip64
43
- }
44
- const localHeaderOffset = fileDataOffset;
45
- return {
46
- compressedSize,
47
- uncompressedSize,
48
- extraFieldLength,
49
- fileNameLength,
50
- fileName,
51
- extraOffset,
52
- localHeaderOffset
53
- };
54
- };
55
- exports.parseZipCDFileHeader = parseZipCDFileHeader;
@@ -1,36 +0,0 @@
1
- import { FileProvider } from './file-provider';
2
- /** Provides file data using DataView */
3
- export declare class DataViewFileProvider implements FileProvider {
4
- /** The DataView from which data is provided */
5
- private file;
6
- constructor(file: DataView);
7
- /**
8
- * Gets an unsigned 8-bit integer at the specified byte offset from the start of the file.
9
- * @param offset The offset, in bytes, from the start of the file where to read the data.
10
- */
11
- getUint8(offset: bigint): Promise<number>;
12
- /**
13
- * Gets an unsigned 16-bit intege at the specified byte offset from the start of the file.
14
- * @param offset The offset, in bytes, from the start of the file where to read the data.
15
- */
16
- getUint16(offset: bigint): Promise<number>;
17
- /**
18
- * Gets an unsigned 32-bit integer at the specified byte offset from the start of the file.
19
- * @param offset The offset, in bytes, from the start of the file where to read the data.
20
- */
21
- getUint32(offset: bigint): Promise<number>;
22
- /**
23
- * Gets an unsigned 64-bit integer at the specified byte offset from the start of the file.
24
- * @param offset The offset, in bytes, from the start of the file where to read the data.
25
- */
26
- getBigUint64(offset: bigint): Promise<bigint>;
27
- /**
28
- * returns an ArrayBuffer whose contents are a copy of this file bytes from startOffset, inclusive, up to endOffset, exclusive.
29
- * @param startOffset The offset, in bytes, from the start of the file where to start reading the data.
30
- * @param endOffset The offset, in bytes, from the start of the file where to end reading the data.
31
- */
32
- slice(startOffset: bigint, endOffset: bigint): Promise<ArrayBuffer>;
33
- /** the length (in bytes) of the data. */
34
- get length(): bigint;
35
- }
36
- //# sourceMappingURL=data-view-file-provider.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"data-view-file-provider.d.ts","sourceRoot":"","sources":["../../../../src/lib/parsers/parse-zip/data-view-file-provider.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,YAAY,EAAC,MAAM,iBAAiB,CAAC;AAc7C,wCAAwC;AACxC,qBAAa,oBAAqB,YAAW,YAAY;IACvD,+CAA+C;IAC/C,OAAO,CAAC,IAAI,CAAW;gBAEX,IAAI,EAAE,QAAQ;IAI1B;;;OAGG;IACG,QAAQ,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;IAI/C;;;OAGG;IACG,SAAS,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;IAIhD;;;OAGG;IACG,SAAS,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;IAIhD;;;OAGG;IACG,YAAY,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;IAInD;;;;OAIG;IACG,KAAK,CAAC,WAAW,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,GAAG,OAAO,CAAC,WAAW,CAAC;IAIzE,yCAAyC;IACzC,IAAI,MAAM,WAET;CACF"}
@@ -1,61 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.DataViewFileProvider = void 0;
4
- /**
5
- * Checks if bigint can be converted to number and convert it if possible
6
- * @param bigint bigint to be converted
7
- * @returns number
8
- */
9
- const toNumber = (bigint) => {
10
- if (bigint > Number.MAX_SAFE_INTEGER) {
11
- throw new Error('Offset is out of bounds');
12
- }
13
- return Number(bigint);
14
- };
15
- /** Provides file data using DataView */
16
- class DataViewFileProvider {
17
- constructor(file) {
18
- this.file = file;
19
- }
20
- /**
21
- * Gets an unsigned 8-bit integer at the specified byte offset from the start of the file.
22
- * @param offset The offset, in bytes, from the start of the file where to read the data.
23
- */
24
- async getUint8(offset) {
25
- return this.file.getUint8(toNumber(offset));
26
- }
27
- /**
28
- * Gets an unsigned 16-bit intege at the specified byte offset from the start of the file.
29
- * @param offset The offset, in bytes, from the start of the file where to read the data.
30
- */
31
- async getUint16(offset) {
32
- return this.file.getUint16(toNumber(offset), true);
33
- }
34
- /**
35
- * Gets an unsigned 32-bit integer at the specified byte offset from the start of the file.
36
- * @param offset The offset, in bytes, from the start of the file where to read the data.
37
- */
38
- async getUint32(offset) {
39
- return this.file.getUint32(toNumber(offset), true);
40
- }
41
- /**
42
- * Gets an unsigned 64-bit integer at the specified byte offset from the start of the file.
43
- * @param offset The offset, in bytes, from the start of the file where to read the data.
44
- */
45
- async getBigUint64(offset) {
46
- return this.file.getBigUint64(toNumber(offset), true);
47
- }
48
- /**
49
- * returns an ArrayBuffer whose contents are a copy of this file bytes from startOffset, inclusive, up to endOffset, exclusive.
50
- * @param startOffset The offset, in bytes, from the start of the file where to start reading the data.
51
- * @param endOffset The offset, in bytes, from the start of the file where to end reading the data.
52
- */
53
- async slice(startOffset, endOffset) {
54
- return this.file.buffer.slice(toNumber(startOffset), toNumber(endOffset));
55
- }
56
- /** the length (in bytes) of the data. */
57
- get length() {
58
- return BigInt(this.file.byteLength);
59
- }
60
- }
61
- exports.DataViewFileProvider = DataViewFileProvider;
@@ -1,18 +0,0 @@
1
- import { FileProvider } from './file-provider';
2
- /**
3
- * End of central directory info
4
- * according to https://en.wikipedia.org/wiki/ZIP_(file_format)
5
- */
6
- export type ZipEoCDRecord = {
7
- /** Relative offset of local file header */
8
- cdStartOffset: bigint;
9
- /** Relative offset of local file header */
10
- cdRecordsNumber: bigint;
11
- };
12
- /**
13
- * Parses end of central directory record of zip file
14
- * @param fileProvider - FileProvider instance
15
- * @returns Info from the header
16
- */
17
- export declare const parseEoCDRecord: (fileProvider: FileProvider) => Promise<ZipEoCDRecord>;
18
- //# sourceMappingURL=end-of-central-directory.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"end-of-central-directory.d.ts","sourceRoot":"","sources":["../../../../src/lib/parsers/parse-zip/end-of-central-directory.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,YAAY,EAAC,MAAM,iBAAiB,CAAC;AAG7C;;;GAGG;AACH,MAAM,MAAM,aAAa,GAAG;IAC1B,2CAA2C;IAC3C,aAAa,EAAE,MAAM,CAAC;IACtB,2CAA2C;IAC3C,eAAe,EAAE,MAAM,CAAC;CACzB,CAAC;AAgBF;;;;GAIG;AACH,eAAO,MAAM,eAAe,iBAAwB,YAAY,KAAG,QAAQ,aAAa,CA4CvF,CAAC"}
@@ -1,41 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.parseEoCDRecord = void 0;
4
- const search_from_the_end_1 = require("./search-from-the-end");
5
- const eoCDSignature = [0x50, 0x4b, 0x05, 0x06];
6
- const zip64EoCDLocatorSignature = Buffer.from([0x50, 0x4b, 0x06, 0x07]);
7
- const zip64EoCDSignature = Buffer.from([0x50, 0x4b, 0x06, 0x06]);
8
- const offsets = {
9
- CD_RECORDS_NUMBER_OFFSET: 8n,
10
- CD_START_OFFSET_OFFSET: 16n,
11
- ZIP64_EOCD_START_OFFSET_OFFSET: 8n,
12
- ZIP64_CD_RECORDS_NUMBER_OFFSET: 24n,
13
- ZIP64_CD_START_OFFSET_OFFSET: 48n
14
- };
15
- /**
16
- * Parses end of central directory record of zip file
17
- * @param fileProvider - FileProvider instance
18
- * @returns Info from the header
19
- */
20
- const parseEoCDRecord = async (fileProvider) => {
21
- const zipEoCDOffset = await (0, search_from_the_end_1.searchFromTheEnd)(fileProvider, eoCDSignature);
22
- let cdRecordsNumber = BigInt(await fileProvider.getUint16(zipEoCDOffset + offsets.CD_RECORDS_NUMBER_OFFSET));
23
- let cdStartOffset = BigInt(await fileProvider.getUint32(zipEoCDOffset + offsets.CD_START_OFFSET_OFFSET));
24
- if (cdStartOffset === BigInt(0xffffffff) || cdRecordsNumber === BigInt(0xffffffff)) {
25
- const zip64EoCDLocatorOffset = zipEoCDOffset - 20n;
26
- if (Buffer.from(await fileProvider.slice(zip64EoCDLocatorOffset, zip64EoCDLocatorOffset + 4n)).compare(zip64EoCDLocatorSignature) !== 0) {
27
- throw new Error('zip64 EoCD locator not found');
28
- }
29
- const zip64EoCDOffset = await fileProvider.getBigUint64(zip64EoCDLocatorOffset + offsets.ZIP64_EOCD_START_OFFSET_OFFSET);
30
- if (Buffer.from(await fileProvider.slice(zip64EoCDOffset, zip64EoCDOffset + 4n)).compare(zip64EoCDSignature) !== 0) {
31
- throw new Error('zip64 EoCD not found');
32
- }
33
- cdRecordsNumber = await fileProvider.getBigUint64(zip64EoCDOffset + offsets.ZIP64_CD_RECORDS_NUMBER_OFFSET);
34
- cdStartOffset = await fileProvider.getBigUint64(zip64EoCDOffset + offsets.ZIP64_CD_START_OFFSET_OFFSET);
35
- }
36
- return {
37
- cdRecordsNumber,
38
- cdStartOffset
39
- };
40
- };
41
- exports.parseEoCDRecord = parseEoCDRecord;
@@ -1,36 +0,0 @@
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: bigint): 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: bigint): 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: bigint): Promise<number>;
20
- /**
21
- * Gets an unsigned 32-bit integer at the specified byte offset from the start of the file.
22
- * @param offset The offset, in byte, from the file of the view where to read the data.
23
- */
24
- getBigUint64(offset: bigint): Promise<bigint>;
25
- /**
26
- * returns an ArrayBuffer whose contents are a copy of this file bytes from startOffset, inclusive, up to endOffset, exclusive.
27
- * @param startOffset The offset, in bytes, from the start of the file where to start reading the data.
28
- * @param endOffset The offset, in bytes, from the start of the file where to end reading the data.
29
- */
30
- slice(startOffset: bigint, endOffset: bigint): Promise<ArrayBuffer>;
31
- /**
32
- * the length (in bytes) of the data.
33
- */
34
- length: bigint;
35
- }
36
- //# sourceMappingURL=file-provider.d.ts.map
@@ -1 +0,0 @@
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;;;OAGG;IACH,YAAY,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC;IAE9C;;;;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"}
@@ -1,2 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
@@ -1,27 +0,0 @@
1
- /// <reference types="node" />
2
- import { FileProvider } from './file-provider';
3
- /**
4
- * zip local file header info
5
- * according to https://en.wikipedia.org/wiki/ZIP_(file_format)
6
- */
7
- export type ZipLocalFileHeader = {
8
- /** File name length */
9
- fileNameLength: number;
10
- /** File name */
11
- fileName: string;
12
- /** Extra field length */
13
- extraFieldLength: number;
14
- /** Offset of the file data */
15
- fileDataOffset: bigint;
16
- /** Compressed size */
17
- compressedSize: bigint;
18
- };
19
- export declare const signature: Buffer;
20
- /**
21
- * Parses local 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 parseZipLocalFileHeader: (headerOffset: bigint, buffer: FileProvider) => Promise<ZipLocalFileHeader | null>;
27
- //# sourceMappingURL=local-file-header.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"local-file-header.d.ts","sourceRoot":"","sources":["../../../../src/lib/parsers/parse-zip/local-file-header.ts"],"names":[],"mappings":";AAAA,OAAO,EAAC,YAAY,EAAC,MAAM,iBAAiB,CAAC;AAE7C;;;GAGG;AACH,MAAM,MAAM,kBAAkB,GAAG;IAC/B,uBAAuB;IACvB,cAAc,EAAE,MAAM,CAAC;IACvB,gBAAgB;IAChB,QAAQ,EAAE,MAAM,CAAC;IACjB,yBAAyB;IACzB,gBAAgB,EAAE,MAAM,CAAC;IACzB,8BAA8B;IAC9B,cAAc,EAAE,MAAM,CAAC;IACvB,sBAAsB;IACtB,cAAc,EAAE,MAAM,CAAC;CACxB,CAAC;AAUF,eAAO,MAAM,SAAS,QAAwC,CAAC;AAE/D;;;;;GAKG;AACH,eAAO,MAAM,uBAAuB,iBACpB,MAAM,UACZ,YAAY,KACnB,QAAQ,kBAAkB,GAAG,IAAI,CAoDnC,CAAC"}
@@ -1,53 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.parseZipLocalFileHeader = exports.signature = void 0;
4
- const offsets = {
5
- COMPRESSED_SIZE_OFFSET: 18n,
6
- UNCOMPRESSED_SIZE_OFFSET: 22n,
7
- FILE_NAME_LENGTH_OFFSET: 26n,
8
- EXTRA_FIELD_LENGTH_OFFSET: 28n,
9
- FILE_NAME_OFFSET: 30n
10
- };
11
- exports.signature = Buffer.from([0x50, 0x4b, 0x03, 0x04]);
12
- /**
13
- * Parses local file header of zip file
14
- * @param headerOffset - offset in the archive where header starts
15
- * @param buffer - buffer containing whole array
16
- * @returns Info from the header
17
- */
18
- const parseZipLocalFileHeader = async (headerOffset, buffer) => {
19
- if (Buffer.from(await buffer.slice(headerOffset, headerOffset + 4n)).compare(exports.signature) !== 0) {
20
- return null;
21
- }
22
- const fileNameLength = await buffer.getUint16(headerOffset + offsets.FILE_NAME_LENGTH_OFFSET);
23
- const fileName = new TextDecoder()
24
- .decode(await buffer.slice(headerOffset + offsets.FILE_NAME_OFFSET, headerOffset + offsets.FILE_NAME_OFFSET + BigInt(fileNameLength)))
25
- .split('\\')
26
- .join('/');
27
- const extraFieldLength = await buffer.getUint16(headerOffset + offsets.EXTRA_FIELD_LENGTH_OFFSET);
28
- let fileDataOffset = headerOffset + offsets.FILE_NAME_OFFSET + BigInt(fileNameLength + extraFieldLength);
29
- let compressedSize = BigInt(await buffer.getUint32(headerOffset + offsets.COMPRESSED_SIZE_OFFSET)); // add zip 64 logic
30
- let uncompressedSize = BigInt(await buffer.getUint32(headerOffset + offsets.UNCOMPRESSED_SIZE_OFFSET)); // add zip 64 logic
31
- const extraOffset = headerOffset + offsets.FILE_NAME_OFFSET + BigInt(fileNameLength);
32
- let offsetInZip64Data = 4n;
33
- // looking for info that might be also be in zip64 extra field
34
- if (uncompressedSize === BigInt(0xffffffff)) {
35
- uncompressedSize = await buffer.getBigUint64(extraOffset + offsetInZip64Data);
36
- offsetInZip64Data += 8n;
37
- }
38
- if (compressedSize === BigInt(0xffffffff)) {
39
- compressedSize = await buffer.getBigUint64(extraOffset + offsetInZip64Data);
40
- offsetInZip64Data += 8n;
41
- }
42
- if (fileDataOffset === BigInt(0xffffffff)) {
43
- fileDataOffset = await buffer.getBigUint64(extraOffset + offsetInZip64Data); // setting it to the one from zip64
44
- }
45
- return {
46
- fileNameLength,
47
- fileName,
48
- extraFieldLength,
49
- fileDataOffset,
50
- compressedSize
51
- };
52
- };
53
- exports.parseZipLocalFileHeader = parseZipLocalFileHeader;
@@ -1,11 +0,0 @@
1
- import { FileProvider } from 'modules/i3s/src/lib/parsers/parse-zip/file-provider';
2
- /** Description of zip signature type */
3
- export type ZipSignature = [number, number, number, number];
4
- /**
5
- * looking for the last occurrence of the provided
6
- * @param file
7
- * @param target
8
- * @returns
9
- */
10
- export declare const searchFromTheEnd: (file: FileProvider, target: ZipSignature) => Promise<bigint>;
11
- //# sourceMappingURL=search-from-the-end.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"search-from-the-end.d.ts","sourceRoot":"","sources":["../../../../src/lib/parsers/parse-zip/search-from-the-end.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,YAAY,EAAC,MAAM,qDAAqD,CAAC;AAEjF,wCAAwC;AACxC,MAAM,MAAM,YAAY,GAAG,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,CAAC,CAAC;AAE5D;;;;;GAKG;AACH,eAAO,MAAM,gBAAgB,SACrB,YAAY,2BAEjB,QAAQ,MAAM,CAuBhB,CAAC"}
@@ -1,31 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.searchFromTheEnd = void 0;
4
- /**
5
- * looking for the last occurrence of the provided
6
- * @param file
7
- * @param target
8
- * @returns
9
- */
10
- const searchFromTheEnd = async (file, target) => {
11
- const searchWindow = [
12
- await file.getUint8(file.length - 1n),
13
- await file.getUint8(file.length - 2n),
14
- await file.getUint8(file.length - 3n),
15
- undefined
16
- ];
17
- let targetOffset = 0n;
18
- // looking for the last record in the central directory
19
- for (let i = file.length - 4n; i > -1; i--) {
20
- searchWindow[3] = searchWindow[2];
21
- searchWindow[2] = searchWindow[1];
22
- searchWindow[1] = searchWindow[0];
23
- searchWindow[0] = await file.getUint8(i);
24
- if (searchWindow.every((val, index) => val === target[index])) {
25
- targetOffset = i;
26
- break;
27
- }
28
- }
29
- return targetOffset;
30
- };
31
- exports.searchFromTheEnd = searchFromTheEnd;
@@ -1,106 +0,0 @@
1
- import {FileProvider} from './file-provider';
2
- import {ZipSignature} from './search-from-the-end';
3
-
4
- /**
5
- * zip central directory file header info
6
- * according to https://en.wikipedia.org/wiki/ZIP_(file_format)
7
- */
8
- export type ZipCDFileHeader = {
9
- /** Compressed size */
10
- compressedSize: bigint;
11
- /** Uncompressed size */
12
- uncompressedSize: bigint;
13
- /** Extra field size */
14
- extraFieldLength: number;
15
- /** File name length */
16
- fileNameLength: number;
17
- /** File name */
18
- fileName: string;
19
- /** Extra field offset */
20
- extraOffset: bigint;
21
- /** Relative offset of local file header */
22
- localHeaderOffset: bigint;
23
- };
24
-
25
- const offsets = {
26
- CD_COMPRESSED_SIZE_OFFSET: 20n,
27
- CD_UNCOMPRESSED_SIZE_OFFSET: 24n,
28
- CD_FILE_NAME_LENGTH_OFFSET: 28n,
29
- CD_EXTRA_FIELD_LENGTH_OFFSET: 30n,
30
- CD_LOCAL_HEADER_OFFSET_OFFSET: 42n,
31
- CD_FILE_NAME_OFFSET: 46n
32
- };
33
-
34
- export const signature: ZipSignature = [0x50, 0x4b, 0x01, 0x02];
35
-
36
- /**
37
- * Parses central directory file header of zip file
38
- * @param headerOffset - offset in the archive where header starts
39
- * @param buffer - buffer containing whole array
40
- * @returns Info from the header
41
- */
42
- export const parseZipCDFileHeader = async (
43
- headerOffset: bigint,
44
- buffer: FileProvider
45
- ): Promise<ZipCDFileHeader | null> => {
46
- if (
47
- Buffer.from(await buffer.slice(headerOffset, headerOffset + 4n)).compare(
48
- Buffer.from(signature)
49
- ) !== 0
50
- ) {
51
- return null;
52
- }
53
-
54
- let compressedSize = BigInt(
55
- await buffer.getUint32(headerOffset + offsets.CD_COMPRESSED_SIZE_OFFSET)
56
- );
57
-
58
- let uncompressedSize = BigInt(
59
- await buffer.getUint32(headerOffset + offsets.CD_UNCOMPRESSED_SIZE_OFFSET)
60
- );
61
-
62
- const extraFieldLength = await buffer.getUint16(
63
- headerOffset + offsets.CD_EXTRA_FIELD_LENGTH_OFFSET
64
- );
65
-
66
- const fileNameLength = await buffer.getUint16(headerOffset + offsets.CD_FILE_NAME_LENGTH_OFFSET);
67
-
68
- const fileName = new TextDecoder().decode(
69
- await buffer.slice(
70
- headerOffset + offsets.CD_FILE_NAME_OFFSET,
71
- headerOffset + offsets.CD_FILE_NAME_OFFSET + BigInt(fileNameLength)
72
- )
73
- );
74
-
75
- const extraOffset = headerOffset + offsets.CD_FILE_NAME_OFFSET + BigInt(fileNameLength);
76
-
77
- const oldFormatOffset = await buffer.getUint32(
78
- headerOffset + offsets.CD_LOCAL_HEADER_OFFSET_OFFSET
79
- );
80
-
81
- let fileDataOffset = BigInt(oldFormatOffset);
82
- let offsetInZip64Data = 4n;
83
- // looking for info that might be also be in zip64 extra field
84
- if (uncompressedSize === BigInt(0xffffffff)) {
85
- uncompressedSize = await buffer.getBigUint64(extraOffset + offsetInZip64Data);
86
- offsetInZip64Data += 8n;
87
- }
88
- if (compressedSize === BigInt(0xffffffff)) {
89
- compressedSize = await buffer.getBigUint64(extraOffset + offsetInZip64Data);
90
- offsetInZip64Data += 8n;
91
- }
92
- if (fileDataOffset === BigInt(0xffffffff)) {
93
- fileDataOffset = await buffer.getBigUint64(extraOffset + offsetInZip64Data); // setting it to the one from zip64
94
- }
95
- const localHeaderOffset = fileDataOffset;
96
-
97
- return {
98
- compressedSize,
99
- uncompressedSize,
100
- extraFieldLength,
101
- fileNameLength,
102
- fileName,
103
- extraOffset,
104
- localHeaderOffset
105
- };
106
- };
@@ -1,69 +0,0 @@
1
- import {FileProvider} from './file-provider';
2
-
3
- /**
4
- * Checks if bigint can be converted to number and convert it if possible
5
- * @param bigint bigint to be converted
6
- * @returns number
7
- */
8
- const toNumber = (bigint: bigint) => {
9
- if (bigint > Number.MAX_SAFE_INTEGER) {
10
- throw new Error('Offset is out of bounds');
11
- }
12
- return Number(bigint);
13
- };
14
-
15
- /** Provides file data using DataView */
16
- export class DataViewFileProvider implements FileProvider {
17
- /** The DataView from which data is provided */
18
- private file: DataView;
19
-
20
- constructor(file: DataView) {
21
- this.file = file;
22
- }
23
-
24
- /**
25
- * Gets an unsigned 8-bit integer at the specified byte offset from the start of the file.
26
- * @param offset The offset, in bytes, from the start of the file where to read the data.
27
- */
28
- async getUint8(offset: bigint): Promise<number> {
29
- return this.file.getUint8(toNumber(offset));
30
- }
31
-
32
- /**
33
- * Gets an unsigned 16-bit intege at the specified byte offset from the start of the file.
34
- * @param offset The offset, in bytes, from the start of the file where to read the data.
35
- */
36
- async getUint16(offset: bigint): Promise<number> {
37
- return this.file.getUint16(toNumber(offset), true);
38
- }
39
-
40
- /**
41
- * Gets an unsigned 32-bit integer at the specified byte offset from the start of the file.
42
- * @param offset The offset, in bytes, from the start of the file where to read the data.
43
- */
44
- async getUint32(offset: bigint): Promise<number> {
45
- return this.file.getUint32(toNumber(offset), true);
46
- }
47
-
48
- /**
49
- * Gets an unsigned 64-bit integer at the specified byte offset from the start of the file.
50
- * @param offset The offset, in bytes, from the start of the file where to read the data.
51
- */
52
- async getBigUint64(offset: bigint): Promise<bigint> {
53
- return this.file.getBigUint64(toNumber(offset), true);
54
- }
55
-
56
- /**
57
- * returns an ArrayBuffer whose contents are a copy of this file bytes from startOffset, inclusive, up to endOffset, exclusive.
58
- * @param startOffset The offset, in bytes, from the start of the file where to start reading the data.
59
- * @param endOffset The offset, in bytes, from the start of the file where to end reading the data.
60
- */
61
- async slice(startOffset: bigint, endOffset: bigint): Promise<ArrayBuffer> {
62
- return this.file.buffer.slice(toNumber(startOffset), toNumber(endOffset));
63
- }
64
-
65
- /** the length (in bytes) of the data. */
66
- get length() {
67
- return BigInt(this.file.byteLength);
68
- }
69
- }
@@ -1,78 +0,0 @@
1
- import {FileProvider} from './file-provider';
2
- import {ZipSignature, searchFromTheEnd} from './search-from-the-end';
3
-
4
- /**
5
- * End of central directory info
6
- * according to https://en.wikipedia.org/wiki/ZIP_(file_format)
7
- */
8
- export type ZipEoCDRecord = {
9
- /** Relative offset of local file header */
10
- cdStartOffset: bigint;
11
- /** Relative offset of local file header */
12
- cdRecordsNumber: bigint;
13
- };
14
-
15
- const eoCDSignature: ZipSignature = [0x50, 0x4b, 0x05, 0x06];
16
- const zip64EoCDLocatorSignature = Buffer.from([0x50, 0x4b, 0x06, 0x07]);
17
- const zip64EoCDSignature = Buffer.from([0x50, 0x4b, 0x06, 0x06]);
18
-
19
- const offsets = {
20
- CD_RECORDS_NUMBER_OFFSET: 8n,
21
- CD_START_OFFSET_OFFSET: 16n,
22
-
23
- ZIP64_EOCD_START_OFFSET_OFFSET: 8n,
24
-
25
- ZIP64_CD_RECORDS_NUMBER_OFFSET: 24n,
26
- ZIP64_CD_START_OFFSET_OFFSET: 48n
27
- };
28
-
29
- /**
30
- * Parses end of central directory record of zip file
31
- * @param fileProvider - FileProvider instance
32
- * @returns Info from the header
33
- */
34
- export const parseEoCDRecord = async (fileProvider: FileProvider): Promise<ZipEoCDRecord> => {
35
- const zipEoCDOffset = await searchFromTheEnd(fileProvider, eoCDSignature);
36
-
37
- let cdRecordsNumber = BigInt(
38
- await fileProvider.getUint16(zipEoCDOffset + offsets.CD_RECORDS_NUMBER_OFFSET)
39
- );
40
- let cdStartOffset = BigInt(
41
- await fileProvider.getUint32(zipEoCDOffset + offsets.CD_START_OFFSET_OFFSET)
42
- );
43
-
44
- if (cdStartOffset === BigInt(0xffffffff) || cdRecordsNumber === BigInt(0xffffffff)) {
45
- const zip64EoCDLocatorOffset = zipEoCDOffset - 20n;
46
-
47
- if (
48
- Buffer.from(
49
- await fileProvider.slice(zip64EoCDLocatorOffset, zip64EoCDLocatorOffset + 4n)
50
- ).compare(zip64EoCDLocatorSignature) !== 0
51
- ) {
52
- throw new Error('zip64 EoCD locator not found');
53
- }
54
- const zip64EoCDOffset = await fileProvider.getBigUint64(
55
- zip64EoCDLocatorOffset + offsets.ZIP64_EOCD_START_OFFSET_OFFSET
56
- );
57
-
58
- if (
59
- Buffer.from(await fileProvider.slice(zip64EoCDOffset, zip64EoCDOffset + 4n)).compare(
60
- zip64EoCDSignature
61
- ) !== 0
62
- ) {
63
- throw new Error('zip64 EoCD not found');
64
- }
65
-
66
- cdRecordsNumber = await fileProvider.getBigUint64(
67
- zip64EoCDOffset + offsets.ZIP64_CD_RECORDS_NUMBER_OFFSET
68
- );
69
- cdStartOffset = await fileProvider.getBigUint64(
70
- zip64EoCDOffset + offsets.ZIP64_CD_START_OFFSET_OFFSET
71
- );
72
- }
73
-
74
- return {
75
- cdRecordsNumber,
76
- cdStartOffset
77
- };
78
- };