@loaders.gl/i3s 4.0.0-alpha.19 → 4.0.0-alpha.21

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 (95) hide show
  1. package/dist/dist.min.js +300 -275
  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-slpk/parse-slpk.js +6 -69
  13. package/dist/es5/lib/parsers/parse-slpk/parse-slpk.js.map +1 -1
  14. package/dist/es5/lib/parsers/parse-slpk/slpk-archieve.js +9 -33
  15. package/dist/es5/lib/parsers/parse-slpk/slpk-archieve.js.map +1 -1
  16. package/dist/esm/arcgis-webscene-loader.js +1 -1
  17. package/dist/esm/i3s-attribute-loader.js +1 -1
  18. package/dist/esm/i3s-building-scene-layer-loader.js +1 -1
  19. package/dist/esm/i3s-content-loader.js +1 -1
  20. package/dist/esm/i3s-loader.js +1 -1
  21. package/dist/esm/i3s-node-page-loader.js +1 -1
  22. package/dist/esm/i3s-slpk-loader.js +3 -3
  23. package/dist/esm/i3s-slpk-loader.js.map +1 -1
  24. package/dist/esm/index.js +0 -1
  25. package/dist/esm/index.js.map +1 -1
  26. package/dist/esm/lib/parsers/parse-slpk/parse-slpk.js +2 -35
  27. package/dist/esm/lib/parsers/parse-slpk/parse-slpk.js.map +1 -1
  28. package/dist/esm/lib/parsers/parse-slpk/slpk-archieve.js +5 -29
  29. package/dist/esm/lib/parsers/parse-slpk/slpk-archieve.js.map +1 -1
  30. package/dist/i3s-content-worker-node.js +2 -2
  31. package/dist/i3s-content-worker-node.js.map +2 -2
  32. package/dist/i3s-content-worker.js +21 -21
  33. package/dist/i3s-slpk-loader.js +2 -2
  34. package/dist/index.d.ts +0 -2
  35. package/dist/index.d.ts.map +1 -1
  36. package/dist/index.js +1 -3
  37. package/dist/lib/parsers/parse-slpk/parse-slpk.d.ts +1 -1
  38. package/dist/lib/parsers/parse-slpk/parse-slpk.d.ts.map +1 -1
  39. package/dist/lib/parsers/parse-slpk/parse-slpk.js +6 -50
  40. package/dist/lib/parsers/parse-slpk/slpk-archieve.d.ts +2 -21
  41. package/dist/lib/parsers/parse-slpk/slpk-archieve.d.ts.map +1 -1
  42. package/dist/lib/parsers/parse-slpk/slpk-archieve.js +7 -46
  43. package/package.json +9 -9
  44. package/src/i3s-slpk-loader.ts +2 -2
  45. package/src/index.ts +0 -2
  46. package/src/lib/parsers/parse-slpk/parse-slpk.ts +11 -56
  47. package/src/lib/parsers/parse-slpk/slpk-archieve.ts +5 -54
  48. package/dist/es5/lib/parsers/parse-zip/cd-file-header.js +0 -121
  49. package/dist/es5/lib/parsers/parse-zip/cd-file-header.js.map +0 -1
  50. package/dist/es5/lib/parsers/parse-zip/data-view-file-provider.js +0 -129
  51. package/dist/es5/lib/parsers/parse-zip/data-view-file-provider.js.map +0 -1
  52. package/dist/es5/lib/parsers/parse-zip/end-of-central-directory.js +0 -100
  53. package/dist/es5/lib/parsers/parse-zip/end-of-central-directory.js.map +0 -1
  54. package/dist/es5/lib/parsers/parse-zip/file-provider.js +0 -2
  55. package/dist/es5/lib/parsers/parse-zip/file-provider.js.map +0 -1
  56. package/dist/es5/lib/parsers/parse-zip/local-file-header.js +0 -113
  57. package/dist/es5/lib/parsers/parse-zip/local-file-header.js.map +0 -1
  58. package/dist/es5/lib/parsers/parse-zip/search-from-the-end.js +0 -69
  59. package/dist/es5/lib/parsers/parse-zip/search-from-the-end.js.map +0 -1
  60. package/dist/esm/lib/parsers/parse-zip/cd-file-header.js +0 -45
  61. package/dist/esm/lib/parsers/parse-zip/cd-file-header.js.map +0 -1
  62. package/dist/esm/lib/parsers/parse-zip/data-view-file-provider.js +0 -32
  63. package/dist/esm/lib/parsers/parse-zip/data-view-file-provider.js.map +0 -1
  64. package/dist/esm/lib/parsers/parse-zip/end-of-central-directory.js +0 -33
  65. package/dist/esm/lib/parsers/parse-zip/end-of-central-directory.js.map +0 -1
  66. package/dist/esm/lib/parsers/parse-zip/file-provider.js +0 -2
  67. package/dist/esm/lib/parsers/parse-zip/file-provider.js.map +0 -1
  68. package/dist/esm/lib/parsers/parse-zip/local-file-header.js +0 -40
  69. package/dist/esm/lib/parsers/parse-zip/local-file-header.js.map +0 -1
  70. package/dist/esm/lib/parsers/parse-zip/search-from-the-end.js +0 -16
  71. package/dist/esm/lib/parsers/parse-zip/search-from-the-end.js.map +0 -1
  72. package/dist/lib/parsers/parse-zip/cd-file-header.d.ts +0 -31
  73. package/dist/lib/parsers/parse-zip/cd-file-header.d.ts.map +0 -1
  74. package/dist/lib/parsers/parse-zip/cd-file-header.js +0 -55
  75. package/dist/lib/parsers/parse-zip/data-view-file-provider.d.ts +0 -36
  76. package/dist/lib/parsers/parse-zip/data-view-file-provider.d.ts.map +0 -1
  77. package/dist/lib/parsers/parse-zip/data-view-file-provider.js +0 -61
  78. package/dist/lib/parsers/parse-zip/end-of-central-directory.d.ts +0 -18
  79. package/dist/lib/parsers/parse-zip/end-of-central-directory.d.ts.map +0 -1
  80. package/dist/lib/parsers/parse-zip/end-of-central-directory.js +0 -41
  81. package/dist/lib/parsers/parse-zip/file-provider.d.ts +0 -36
  82. package/dist/lib/parsers/parse-zip/file-provider.d.ts.map +0 -1
  83. package/dist/lib/parsers/parse-zip/file-provider.js +0 -2
  84. package/dist/lib/parsers/parse-zip/local-file-header.d.ts +0 -27
  85. package/dist/lib/parsers/parse-zip/local-file-header.d.ts.map +0 -1
  86. package/dist/lib/parsers/parse-zip/local-file-header.js +0 -53
  87. package/dist/lib/parsers/parse-zip/search-from-the-end.d.ts +0 -11
  88. package/dist/lib/parsers/parse-zip/search-from-the-end.d.ts.map +0 -1
  89. package/dist/lib/parsers/parse-zip/search-from-the-end.js +0 -31
  90. package/src/lib/parsers/parse-zip/cd-file-header.ts +0 -106
  91. package/src/lib/parsers/parse-zip/data-view-file-provider.ts +0 -69
  92. package/src/lib/parsers/parse-zip/end-of-central-directory.ts +0 -78
  93. package/src/lib/parsers/parse-zip/file-provider.ts +0 -40
  94. package/src/lib/parsers/parse-zip/local-file-header.ts +0 -91
  95. package/src/lib/parsers/parse-zip/search-from-the-end.ts +0 -38
@@ -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
- };
@@ -1,40 +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
- /**
12
- * Gets an unsigned 16-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
- getUint16(offset: bigint): Promise<number>;
16
-
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 file of the view where to read the data.
20
- */
21
- getUint32(offset: bigint): Promise<number>;
22
-
23
- /**
24
- * Gets an unsigned 32-bit integer at the specified byte offset from the start of the file.
25
- * @param offset The offset, in byte, from the file of the view where to read the data.
26
- */
27
- getBigUint64(offset: bigint): Promise<bigint>;
28
-
29
- /**
30
- * returns an ArrayBuffer whose contents are a copy of this file bytes from startOffset, inclusive, up to endOffset, exclusive.
31
- * @param startOffset The offset, in bytes, from the start of the file where to start reading the data.
32
- * @param endOffset The offset, in bytes, from the start of the file where to end reading the data.
33
- */
34
- slice(startOffset: bigint, endOffset: bigint): Promise<ArrayBuffer>;
35
-
36
- /**
37
- * the length (in bytes) of the data.
38
- */
39
- length: bigint;
40
- }
@@ -1,91 +0,0 @@
1
- import {FileProvider} from './file-provider';
2
-
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
-
20
- const offsets = {
21
- COMPRESSED_SIZE_OFFSET: 18n,
22
- UNCOMPRESSED_SIZE_OFFSET: 22n,
23
- FILE_NAME_LENGTH_OFFSET: 26n,
24
- EXTRA_FIELD_LENGTH_OFFSET: 28n,
25
- FILE_NAME_OFFSET: 30n
26
- };
27
-
28
- export const signature = Buffer.from([0x50, 0x4b, 0x03, 0x04]);
29
-
30
- /**
31
- * Parses local file header of zip file
32
- * @param headerOffset - offset in the archive where header starts
33
- * @param buffer - buffer containing whole array
34
- * @returns Info from the header
35
- */
36
- export const parseZipLocalFileHeader = async (
37
- headerOffset: bigint,
38
- buffer: FileProvider
39
- ): Promise<ZipLocalFileHeader | null> => {
40
- if (Buffer.from(await buffer.slice(headerOffset, headerOffset + 4n)).compare(signature) !== 0) {
41
- return null;
42
- }
43
-
44
- const fileNameLength = await buffer.getUint16(headerOffset + offsets.FILE_NAME_LENGTH_OFFSET);
45
-
46
- const fileName = new TextDecoder()
47
- .decode(
48
- await buffer.slice(
49
- headerOffset + offsets.FILE_NAME_OFFSET,
50
- headerOffset + offsets.FILE_NAME_OFFSET + BigInt(fileNameLength)
51
- )
52
- )
53
- .split('\\')
54
- .join('/');
55
- const extraFieldLength = await buffer.getUint16(headerOffset + offsets.EXTRA_FIELD_LENGTH_OFFSET);
56
-
57
- let fileDataOffset =
58
- headerOffset + offsets.FILE_NAME_OFFSET + BigInt(fileNameLength + extraFieldLength);
59
-
60
- let compressedSize = BigInt(
61
- await buffer.getUint32(headerOffset + offsets.COMPRESSED_SIZE_OFFSET)
62
- ); // add zip 64 logic
63
-
64
- let uncompressedSize = BigInt(
65
- await buffer.getUint32(headerOffset + offsets.UNCOMPRESSED_SIZE_OFFSET)
66
- ); // add zip 64 logic
67
-
68
- const extraOffset = headerOffset + offsets.FILE_NAME_OFFSET + BigInt(fileNameLength);
69
-
70
- let offsetInZip64Data = 4n;
71
- // looking for info that might be also be in zip64 extra field
72
- if (uncompressedSize === BigInt(0xffffffff)) {
73
- uncompressedSize = await buffer.getBigUint64(extraOffset + offsetInZip64Data);
74
- offsetInZip64Data += 8n;
75
- }
76
- if (compressedSize === BigInt(0xffffffff)) {
77
- compressedSize = await buffer.getBigUint64(extraOffset + offsetInZip64Data);
78
- offsetInZip64Data += 8n;
79
- }
80
- if (fileDataOffset === BigInt(0xffffffff)) {
81
- fileDataOffset = await buffer.getBigUint64(extraOffset + offsetInZip64Data); // setting it to the one from zip64
82
- }
83
-
84
- return {
85
- fileNameLength,
86
- fileName,
87
- extraFieldLength,
88
- fileDataOffset,
89
- compressedSize
90
- };
91
- };
@@ -1,38 +0,0 @@
1
- import {FileProvider} from 'modules/i3s/src/lib/parsers/parse-zip/file-provider';
2
-
3
- /** Description of zip signature type */
4
- export type ZipSignature = [number, number, number, number];
5
-
6
- /**
7
- * looking for the last occurrence of the provided
8
- * @param file
9
- * @param target
10
- * @returns
11
- */
12
- export const searchFromTheEnd = async (
13
- file: FileProvider,
14
- target: ZipSignature
15
- ): Promise<bigint> => {
16
- const searchWindow = [
17
- await file.getUint8(file.length - 1n),
18
- await file.getUint8(file.length - 2n),
19
- await file.getUint8(file.length - 3n),
20
- undefined
21
- ];
22
-
23
- let targetOffset = 0n;
24
-
25
- // looking for the last record in the central directory
26
- for (let i = file.length - 4n; i > -1; i--) {
27
- searchWindow[3] = searchWindow[2];
28
- searchWindow[2] = searchWindow[1];
29
- searchWindow[1] = searchWindow[0];
30
- searchWindow[0] = await file.getUint8(i);
31
- if (searchWindow.every((val, index) => val === target[index])) {
32
- targetOffset = i;
33
- break;
34
- }
35
- }
36
-
37
- return targetOffset;
38
- };