@loaders.gl/zip 4.0.0-beta.2 → 4.0.0-beta.4

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 (105) hide show
  1. package/dist/{dist.min.js → dist.dev.js} +1929 -1728
  2. package/dist/filesystems/zip-filesystem.d.ts +1 -1
  3. package/dist/filesystems/zip-filesystem.d.ts.map +1 -1
  4. package/dist/{esm/filesystems → filesystems}/zip-filesystem.js +16 -21
  5. package/dist/filesystems/zip-filesystem.js.map +1 -0
  6. package/dist/hash-file-utility.d.ts +5 -26
  7. package/dist/hash-file-utility.d.ts.map +1 -1
  8. package/dist/hash-file-utility.js +29 -0
  9. package/dist/hash-file-utility.js.map +1 -0
  10. package/dist/index.cjs +653 -0
  11. package/dist/index.d.ts +2 -3
  12. package/dist/index.d.ts.map +1 -1
  13. package/dist/index.js +10 -0
  14. package/dist/index.js.map +1 -0
  15. package/dist/{esm/lib → lib}/tar/header.js +1 -1
  16. package/dist/lib/tar/header.js.map +1 -0
  17. package/dist/{esm/lib → lib}/tar/tar.js +8 -9
  18. package/dist/lib/tar/tar.js.map +1 -0
  19. package/dist/lib/tar/types.js.map +1 -0
  20. package/dist/lib/tar/utils.js.map +1 -0
  21. package/dist/parse-zip/cd-file-header.d.ts +2 -2
  22. package/dist/parse-zip/cd-file-header.d.ts.map +1 -1
  23. package/dist/parse-zip/cd-file-header.js +57 -0
  24. package/dist/parse-zip/cd-file-header.js.map +1 -0
  25. package/dist/parse-zip/end-of-central-directory.d.ts +2 -2
  26. package/dist/parse-zip/end-of-central-directory.d.ts.map +1 -1
  27. package/dist/parse-zip/end-of-central-directory.js +34 -0
  28. package/dist/parse-zip/end-of-central-directory.js.map +1 -0
  29. package/dist/parse-zip/local-file-header.d.ts +2 -1
  30. package/dist/parse-zip/local-file-header.d.ts.map +1 -1
  31. package/dist/{esm/parse-zip → parse-zip}/local-file-header.js +4 -2
  32. package/dist/parse-zip/local-file-header.js.map +1 -0
  33. package/dist/parse-zip/search-from-the-end.d.ts +1 -1
  34. package/dist/parse-zip/search-from-the-end.d.ts.map +1 -1
  35. package/dist/parse-zip/search-from-the-end.js.map +1 -0
  36. package/dist/{esm/tar-builder.js → tar-builder.js} +4 -5
  37. package/dist/tar-builder.js.map +1 -0
  38. package/dist/{esm/zip-loader.js → zip-loader.js} +3 -3
  39. package/dist/zip-loader.js.map +1 -0
  40. package/dist/{esm/zip-writer.js → zip-writer.js} +1 -1
  41. package/dist/zip-writer.js.map +1 -0
  42. package/package.json +17 -8
  43. package/src/filesystems/zip-filesystem.ts +13 -17
  44. package/src/hash-file-utility.ts +37 -85
  45. package/src/index.ts +3 -3
  46. package/src/parse-zip/cd-file-header.ts +20 -27
  47. package/src/parse-zip/end-of-central-directory.ts +16 -26
  48. package/src/parse-zip/local-file-header.ts +5 -7
  49. package/src/parse-zip/search-from-the-end.ts +1 -1
  50. package/dist/bundle.d.ts +0 -2
  51. package/dist/bundle.d.ts.map +0 -1
  52. package/dist/es5/bundle.js +0 -6
  53. package/dist/es5/bundle.js.map +0 -1
  54. package/dist/es5/filesystems/zip-filesystem.js +0 -372
  55. package/dist/es5/filesystems/zip-filesystem.js.map +0 -1
  56. package/dist/es5/hash-file-utility.js +0 -130
  57. package/dist/es5/hash-file-utility.js.map +0 -1
  58. package/dist/es5/index.js +0 -105
  59. package/dist/es5/index.js.map +0 -1
  60. package/dist/es5/lib/tar/header.js +0 -52
  61. package/dist/es5/lib/tar/header.js.map +0 -1
  62. package/dist/es5/lib/tar/tar.js +0 -137
  63. package/dist/es5/lib/tar/tar.js.map +0 -1
  64. package/dist/es5/lib/tar/types.js +0 -2
  65. package/dist/es5/lib/tar/types.js.map +0 -1
  66. package/dist/es5/lib/tar/utils.js +0 -32
  67. package/dist/es5/lib/tar/utils.js.map +0 -1
  68. package/dist/es5/parse-zip/cd-file-header.js +0 -163
  69. package/dist/es5/parse-zip/cd-file-header.js.map +0 -1
  70. package/dist/es5/parse-zip/end-of-central-directory.js +0 -98
  71. package/dist/es5/parse-zip/end-of-central-directory.js.map +0 -1
  72. package/dist/es5/parse-zip/local-file-header.js +0 -117
  73. package/dist/es5/parse-zip/local-file-header.js.map +0 -1
  74. package/dist/es5/parse-zip/search-from-the-end.js +0 -69
  75. package/dist/es5/parse-zip/search-from-the-end.js.map +0 -1
  76. package/dist/es5/tar-builder.js +0 -69
  77. package/dist/es5/tar-builder.js.map +0 -1
  78. package/dist/es5/zip-loader.js +0 -103
  79. package/dist/es5/zip-loader.js.map +0 -1
  80. package/dist/es5/zip-writer.js +0 -66
  81. package/dist/es5/zip-writer.js.map +0 -1
  82. package/dist/esm/bundle.js +0 -4
  83. package/dist/esm/bundle.js.map +0 -1
  84. package/dist/esm/filesystems/zip-filesystem.js.map +0 -1
  85. package/dist/esm/hash-file-utility.js +0 -55
  86. package/dist/esm/hash-file-utility.js.map +0 -1
  87. package/dist/esm/index.js +0 -10
  88. package/dist/esm/index.js.map +0 -1
  89. package/dist/esm/lib/tar/header.js.map +0 -1
  90. package/dist/esm/lib/tar/tar.js.map +0 -1
  91. package/dist/esm/lib/tar/types.js.map +0 -1
  92. package/dist/esm/lib/tar/utils.js.map +0 -1
  93. package/dist/esm/parse-zip/cd-file-header.js +0 -54
  94. package/dist/esm/parse-zip/cd-file-header.js.map +0 -1
  95. package/dist/esm/parse-zip/end-of-central-directory.js +0 -31
  96. package/dist/esm/parse-zip/end-of-central-directory.js.map +0 -1
  97. package/dist/esm/parse-zip/local-file-header.js.map +0 -1
  98. package/dist/esm/parse-zip/search-from-the-end.js.map +0 -1
  99. package/dist/esm/tar-builder.js.map +0 -1
  100. package/dist/esm/zip-loader.js.map +0 -1
  101. package/dist/esm/zip-writer.js.map +0 -1
  102. package/src/bundle.ts +0 -4
  103. /package/dist/{esm/lib → lib}/tar/types.js +0 -0
  104. /package/dist/{esm/lib → lib}/tar/utils.js +0 -0
  105. /package/dist/{esm/parse-zip → parse-zip}/search-from-the-end.js +0 -0
@@ -1,101 +1,53 @@
1
- import md5 from 'md5';
1
+ import {MD5Hash} from '@loaders.gl/crypto';
2
2
  import {FileProvider} from '@loaders.gl/loader-utils';
3
- import {zipCDFileHeaderGenerator} from './parse-zip/cd-file-header';
4
-
5
- /** Element of hash array */
6
- export type HashElement = {
7
- /** File name hash */
8
- hash: Buffer;
9
- /** File offset in the archive */
10
- offset: bigint;
11
- };
3
+ import {makeZipCDHeaderIterator} from './parse-zip/cd-file-header';
12
4
 
13
5
  /**
14
- * Comparing md5 hashes according to https://github.com/Esri/i3s-spec/blob/master/docs/2.0/slpk_hashtable.pcsl.md step 5
15
- * @param hash1 hash to compare
16
- * @param hash2 hash to compare
17
- * @returns -1 if hash1 < hash2, 0 of hash1 === hash2, 1 if hash1 > hash2
6
+ * Reads hash file from buffer and returns it in ready-to-use form
7
+ * @param arrayBuffer - buffer containing hash file
8
+ * @returns Map containing hash and offset
18
9
  */
19
- export const compareHashes = (hash1: Buffer, hash2: Buffer): number => {
20
- const h1 = new BigUint64Array(hash1.buffer, hash1.byteOffset, 2);
21
- const h2 = new BigUint64Array(hash2.buffer, hash2.byteOffset, 2);
10
+ export function parseHashTable(arrayBuffer: ArrayBuffer): Record<string, bigint> {
11
+ const dataView = new DataView(arrayBuffer);
22
12
 
23
- const diff = h1[0] === h2[0] ? h1[1] - h2[1] : h1[0] - h2[0];
13
+ const hashMap: Record<string, bigint> = {};
24
14
 
25
- if (diff < 0n) {
26
- return -1;
27
- } else if (diff === 0n) {
28
- return 0;
15
+ for (let i = 0; i < arrayBuffer.byteLength; i = i + 24) {
16
+ const offset = dataView.getBigUint64(i + 16, true);
17
+ const hash = bufferToHex(arrayBuffer, i, 16);
18
+ hashMap[hash] = offset;
29
19
  }
30
- return 1;
31
- };
32
20
 
33
- /**
34
- * Reads hash file from buffer and returns it in ready-to-use form
35
- * @param hashFile - bufer containing hash file
36
- * @returns Array containing file info
37
- */
38
- export const parseHashFile = (hashFile: ArrayBuffer): HashElement[] => {
39
- const hashFileBuffer = Buffer.from(hashFile);
40
- const hashArray: HashElement[] = [];
41
- for (let i = 0; i < hashFileBuffer.buffer.byteLength; i = i + 24) {
42
- const offsetBuffer = new DataView(
43
- hashFileBuffer.buffer.slice(
44
- hashFileBuffer.byteOffset + i + 16,
45
- hashFileBuffer.byteOffset + i + 24
46
- )
47
- );
48
- const offset = offsetBuffer.getBigUint64(offsetBuffer.byteOffset, true);
49
- hashArray.push({
50
- hash: Buffer.from(
51
- hashFileBuffer.subarray(hashFileBuffer.byteOffset + i, hashFileBuffer.byteOffset + i + 16)
52
- ),
53
- offset
54
- });
55
- }
56
- return hashArray;
57
- };
21
+ return hashMap;
22
+ }
58
23
 
59
- /**
60
- * Binary search in the hash info
61
- * @param hashToSearch hash that we need to find
62
- * @returns required hash element or undefined if not found
63
- */
64
- export const findBin = (
65
- hashToSearch: Buffer,
66
- hashArray: HashElement[]
67
- ): HashElement | undefined => {
68
- let lowerBorder = 0;
69
- let upperBorder = hashArray.length;
70
-
71
- while (upperBorder - lowerBorder > 1) {
72
- const middle = lowerBorder + Math.floor((upperBorder - lowerBorder) / 2);
73
- const value = compareHashes(hashArray[middle].hash, hashToSearch);
74
- if (value === 0) {
75
- return hashArray[middle];
76
- } else if (value < 0) {
77
- lowerBorder = middle;
78
- } else {
79
- upperBorder = middle;
80
- }
81
- }
82
- return undefined;
83
- };
24
+ function bufferToHex(buffer: ArrayBuffer, start: number, length: number): string {
25
+ // buffer is an ArrayBuffer
26
+ return [...new Uint8Array(buffer, start, length)]
27
+ .map((x) => x.toString(16).padStart(2, '0'))
28
+ .join('');
29
+ }
84
30
 
85
31
  /**
86
- * generates hash info from central directory
32
+ * generates hash info from zip files "central directory"
87
33
  * @param fileProvider - provider of the archive
88
34
  * @returns ready to use hash info
89
35
  */
90
- export const generateHashInfo = async (fileProvider: FileProvider): Promise<HashElement[]> => {
91
- const zipCDIterator = zipCDFileHeaderGenerator(fileProvider);
92
- const hashInfo: HashElement[] = [];
36
+ export async function makeHashTableFromZipHeaders(
37
+ fileProvider: FileProvider
38
+ ): Promise<Record<string, bigint>> {
39
+ const zipCDIterator = makeZipCDHeaderIterator(fileProvider);
40
+ const md5Hash = new MD5Hash();
41
+ const textEncoder = new TextEncoder();
42
+
43
+ const hashTable: Record<string, bigint> = {};
44
+
93
45
  for await (const cdHeader of zipCDIterator) {
94
- hashInfo.push({
95
- hash: Buffer.from(md5(cdHeader.fileName.split('\\').join('/').toLocaleLowerCase()), 'hex'),
96
- offset: cdHeader.localHeaderOffset
97
- });
46
+ const filename = cdHeader.fileName.split('\\').join('/').toLocaleLowerCase();
47
+ const arrayBuffer = textEncoder.encode(filename).buffer;
48
+ const md5 = await md5Hash.hash(arrayBuffer, 'hex');
49
+ hashTable[md5] = cdHeader.localHeaderOffset;
98
50
  }
99
- hashInfo.sort((a, b) => compareHashes(a.hash, b.hash));
100
- return hashInfo;
101
- };
51
+
52
+ return hashTable;
53
+ }
package/src/index.ts CHANGED
@@ -6,7 +6,7 @@ export {TarBuilder} from './tar-builder';
6
6
 
7
7
  export {
8
8
  parseZipCDFileHeader,
9
- zipCDFileHeaderGenerator,
9
+ makeZipCDHeaderIterator,
10
10
  signature as cdSignature
11
11
  } from './parse-zip/cd-file-header';
12
12
  export {
@@ -16,7 +16,7 @@ export {
16
16
  export {parseEoCDRecord} from './parse-zip/end-of-central-directory';
17
17
  export {searchFromTheEnd} from './parse-zip/search-from-the-end';
18
18
 
19
- export type {HashElement} from './hash-file-utility';
20
- export {compareHashes, parseHashFile, findBin, generateHashInfo} from './hash-file-utility';
19
+ // export type {HashElement} from './hash-file-utility';
20
+ export {parseHashTable, makeHashTableFromZipHeaders} from './hash-file-utility';
21
21
 
22
22
  export {ZipFileSystem} from './filesystems/zip-filesystem';
@@ -1,4 +1,4 @@
1
- import {FileProvider} from '@loaders.gl/loader-utils';
1
+ import {FileProvider, compareArrayBuffers} from '@loaders.gl/loader-utils';
2
2
  import {parseEoCDRecord} from './end-of-central-directory';
3
3
  import {ZipSignature} from './search-from-the-end';
4
4
 
@@ -31,7 +31,7 @@ const CD_EXTRA_FIELD_LENGTH_OFFSET = 30n;
31
31
  const CD_LOCAL_HEADER_OFFSET_OFFSET = 42n;
32
32
  const CD_FILE_NAME_OFFSET = 46n;
33
33
 
34
- export const signature: ZipSignature = [0x50, 0x4b, 0x01, 0x02];
34
+ export const signature: ZipSignature = new Uint8Array([0x50, 0x4b, 0x01, 0x02]);
35
35
 
36
36
  /**
37
37
  * Parses central directory file header of zip file
@@ -41,48 +41,39 @@ export const signature: ZipSignature = [0x50, 0x4b, 0x01, 0x02];
41
41
  */
42
42
  export const parseZipCDFileHeader = async (
43
43
  headerOffset: bigint,
44
- buffer: FileProvider
44
+ file: FileProvider
45
45
  ): Promise<ZipCDFileHeader | null> => {
46
- if (
47
- Buffer.from(await buffer.slice(headerOffset, headerOffset + 4n)).compare(
48
- Buffer.from(signature)
49
- ) !== 0
50
- ) {
46
+ const magicBytes = await file.slice(headerOffset, headerOffset + 4n);
47
+ if (!compareArrayBuffers(magicBytes, signature.buffer)) {
51
48
  return null;
52
49
  }
53
50
 
54
- let compressedSize = BigInt(await buffer.getUint32(headerOffset + CD_COMPRESSED_SIZE_OFFSET));
55
-
56
- let uncompressedSize = BigInt(await buffer.getUint32(headerOffset + CD_UNCOMPRESSED_SIZE_OFFSET));
57
-
58
- const extraFieldLength = await buffer.getUint16(headerOffset + CD_EXTRA_FIELD_LENGTH_OFFSET);
59
-
60
- const fileNameLength = await buffer.getUint16(headerOffset + CD_FILE_NAME_LENGTH_OFFSET);
61
-
62
- const fileName = new TextDecoder().decode(
63
- await buffer.slice(
64
- headerOffset + CD_FILE_NAME_OFFSET,
65
- headerOffset + CD_FILE_NAME_OFFSET + BigInt(fileNameLength)
66
- )
51
+ let compressedSize = BigInt(await file.getUint32(headerOffset + CD_COMPRESSED_SIZE_OFFSET));
52
+ let uncompressedSize = BigInt(await file.getUint32(headerOffset + CD_UNCOMPRESSED_SIZE_OFFSET));
53
+ const extraFieldLength = await file.getUint16(headerOffset + CD_EXTRA_FIELD_LENGTH_OFFSET);
54
+ const fileNameLength = await file.getUint16(headerOffset + CD_FILE_NAME_LENGTH_OFFSET);
55
+ const filenameBytes = await file.slice(
56
+ headerOffset + CD_FILE_NAME_OFFSET,
57
+ headerOffset + CD_FILE_NAME_OFFSET + BigInt(fileNameLength)
67
58
  );
59
+ const fileName = new TextDecoder().decode(filenameBytes);
68
60
 
69
61
  const extraOffset = headerOffset + CD_FILE_NAME_OFFSET + BigInt(fileNameLength);
70
-
71
- const oldFormatOffset = await buffer.getUint32(headerOffset + CD_LOCAL_HEADER_OFFSET_OFFSET);
62
+ const oldFormatOffset = await file.getUint32(headerOffset + CD_LOCAL_HEADER_OFFSET_OFFSET);
72
63
 
73
64
  let fileDataOffset = BigInt(oldFormatOffset);
74
65
  let offsetInZip64Data = 4n;
75
66
  // looking for info that might be also be in zip64 extra field
76
67
  if (uncompressedSize === BigInt(0xffffffff)) {
77
- uncompressedSize = await buffer.getBigUint64(extraOffset + offsetInZip64Data);
68
+ uncompressedSize = await file.getBigUint64(extraOffset + offsetInZip64Data);
78
69
  offsetInZip64Data += 8n;
79
70
  }
80
71
  if (compressedSize === BigInt(0xffffffff)) {
81
- compressedSize = await buffer.getBigUint64(extraOffset + offsetInZip64Data);
72
+ compressedSize = await file.getBigUint64(extraOffset + offsetInZip64Data);
82
73
  offsetInZip64Data += 8n;
83
74
  }
84
75
  if (fileDataOffset === BigInt(0xffffffff)) {
85
- fileDataOffset = await buffer.getBigUint64(extraOffset + offsetInZip64Data); // setting it to the one from zip64
76
+ fileDataOffset = await file.getBigUint64(extraOffset + offsetInZip64Data); // setting it to the one from zip64
86
77
  }
87
78
  const localHeaderOffset = fileDataOffset;
88
79
 
@@ -101,7 +92,9 @@ export const parseZipCDFileHeader = async (
101
92
  * Create iterator over files of zip archive
102
93
  * @param fileProvider - file provider that provider random access to the file
103
94
  */
104
- export async function* zipCDFileHeaderGenerator(fileProvider: FileProvider) {
95
+ export async function* makeZipCDHeaderIterator(
96
+ fileProvider: FileProvider
97
+ ): AsyncIterable<ZipCDFileHeader> {
105
98
  const {cdStartOffset} = await parseEoCDRecord(fileProvider);
106
99
  let cdHeader = await parseZipCDFileHeader(cdStartOffset, fileProvider);
107
100
  while (cdHeader) {
@@ -1,4 +1,4 @@
1
- import {FileProvider} from '@loaders.gl/loader-utils';
1
+ import {FileProvider, compareArrayBuffers} from '@loaders.gl/loader-utils';
2
2
  import {ZipSignature, searchFromTheEnd} from './search-from-the-end';
3
3
 
4
4
  /**
@@ -12,9 +12,9 @@ export type ZipEoCDRecord = {
12
12
  cdRecordsNumber: bigint;
13
13
  };
14
14
 
15
- const eoCDSignature: ZipSignature = [0x50, 0x4b, 0x05, 0x06];
16
- const zip64EoCDLocatorSignature = [0x50, 0x4b, 0x06, 0x07];
17
- const zip64EoCDSignature = [0x50, 0x4b, 0x06, 0x06];
15
+ const eoCDSignature: ZipSignature = new Uint8Array([0x50, 0x4b, 0x05, 0x06]);
16
+ const zip64EoCDLocatorSignature = new Uint8Array([0x50, 0x4b, 0x06, 0x07]);
17
+ const zip64EoCDSignature = new Uint8Array([0x50, 0x4b, 0x06, 0x06]);
18
18
 
19
19
  // offsets accroding to https://en.wikipedia.org/wiki/ZIP_(file_format)
20
20
  const CD_RECORDS_NUMBER_OFFSET = 8n;
@@ -25,43 +25,33 @@ const ZIP64_CD_START_OFFSET_OFFSET = 48n;
25
25
 
26
26
  /**
27
27
  * Parses end of central directory record of zip file
28
- * @param fileProvider - FileProvider instance
28
+ * @param file - FileProvider instance
29
29
  * @returns Info from the header
30
30
  */
31
- export const parseEoCDRecord = async (fileProvider: FileProvider): Promise<ZipEoCDRecord> => {
32
- const zipEoCDOffset = await searchFromTheEnd(fileProvider, eoCDSignature);
31
+ export const parseEoCDRecord = async (file: FileProvider): Promise<ZipEoCDRecord> => {
32
+ const zipEoCDOffset = await searchFromTheEnd(file, eoCDSignature);
33
33
 
34
- let cdRecordsNumber = BigInt(
35
- await fileProvider.getUint16(zipEoCDOffset + CD_RECORDS_NUMBER_OFFSET)
36
- );
37
- let cdStartOffset = BigInt(await fileProvider.getUint32(zipEoCDOffset + CD_START_OFFSET_OFFSET));
34
+ let cdRecordsNumber = BigInt(await file.getUint16(zipEoCDOffset + CD_RECORDS_NUMBER_OFFSET));
35
+ let cdStartOffset = BigInt(await file.getUint32(zipEoCDOffset + CD_START_OFFSET_OFFSET));
38
36
 
39
37
  if (cdStartOffset === BigInt(0xffffffff) || cdRecordsNumber === BigInt(0xffffffff)) {
40
38
  const zip64EoCDLocatorOffset = zipEoCDOffset - 20n;
41
39
 
42
- if (
43
- Buffer.from(
44
- await fileProvider.slice(zip64EoCDLocatorOffset, zip64EoCDLocatorOffset + 4n)
45
- ).compare(Buffer.from(zip64EoCDLocatorSignature)) !== 0
46
- ) {
40
+ const magicBytes = await file.slice(zip64EoCDLocatorOffset, zip64EoCDLocatorOffset + 4n);
41
+ if (!compareArrayBuffers(magicBytes, zip64EoCDLocatorSignature)) {
47
42
  throw new Error('zip64 EoCD locator not found');
48
43
  }
49
- const zip64EoCDOffset = await fileProvider.getBigUint64(
44
+ const zip64EoCDOffset = await file.getBigUint64(
50
45
  zip64EoCDLocatorOffset + ZIP64_EOCD_START_OFFSET_OFFSET
51
46
  );
52
47
 
53
- if (
54
- Buffer.from(await fileProvider.slice(zip64EoCDOffset, zip64EoCDOffset + 4n)).compare(
55
- Buffer.from(zip64EoCDSignature)
56
- ) !== 0
57
- ) {
48
+ const endOfCDMagicBytes = await file.slice(zip64EoCDOffset, zip64EoCDOffset + 4n);
49
+ if (!compareArrayBuffers(endOfCDMagicBytes, zip64EoCDSignature.buffer)) {
58
50
  throw new Error('zip64 EoCD not found');
59
51
  }
60
52
 
61
- cdRecordsNumber = await fileProvider.getBigUint64(
62
- zip64EoCDOffset + ZIP64_CD_RECORDS_NUMBER_OFFSET
63
- );
64
- cdStartOffset = await fileProvider.getBigUint64(zip64EoCDOffset + ZIP64_CD_START_OFFSET_OFFSET);
53
+ cdRecordsNumber = await file.getBigUint64(zip64EoCDOffset + ZIP64_CD_RECORDS_NUMBER_OFFSET);
54
+ cdStartOffset = await file.getBigUint64(zip64EoCDOffset + ZIP64_CD_START_OFFSET_OFFSET);
65
55
  }
66
56
 
67
57
  return {
@@ -1,4 +1,5 @@
1
- import {FileProvider} from '@loaders.gl/loader-utils';
1
+ import {FileProvider, compareArrayBuffers} from '@loaders.gl/loader-utils';
2
+ import {ZipSignature} from './search-from-the-end';
2
3
 
3
4
  /**
4
5
  * zip local file header info
@@ -27,7 +28,7 @@ const FILE_NAME_LENGTH_OFFSET = 26n;
27
28
  const EXTRA_FIELD_LENGTH_OFFSET = 28n;
28
29
  const FILE_NAME_OFFSET = 30n;
29
30
 
30
- export const signature = [0x50, 0x4b, 0x03, 0x04];
31
+ export const signature: ZipSignature = new Uint8Array([0x50, 0x4b, 0x03, 0x04]);
31
32
 
32
33
  /**
33
34
  * Parses local file header of zip file
@@ -39,11 +40,8 @@ export const parseZipLocalFileHeader = async (
39
40
  headerOffset: bigint,
40
41
  buffer: FileProvider
41
42
  ): Promise<ZipLocalFileHeader | null> => {
42
- if (
43
- Buffer.from(await buffer.slice(headerOffset, headerOffset + 4n)).compare(
44
- Buffer.from(signature)
45
- ) !== 0
46
- ) {
43
+ const magicBytes = await buffer.slice(headerOffset, headerOffset + 4n);
44
+ if (!compareArrayBuffers(magicBytes, signature)) {
47
45
  return null;
48
46
  }
49
47
 
@@ -1,7 +1,7 @@
1
1
  import {FileProvider} from '@loaders.gl/loader-utils';
2
2
 
3
3
  /** Description of zip signature type */
4
- export type ZipSignature = [number, number, number, number];
4
+ export type ZipSignature = Uint8Array;
5
5
 
6
6
  /**
7
7
  * looking for the last occurrence of the provided
package/dist/bundle.d.ts DELETED
@@ -1,2 +0,0 @@
1
- declare const moduleExports: any;
2
- //# sourceMappingURL=bundle.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"bundle.d.ts","sourceRoot":"","sources":["../src/bundle.ts"],"names":[],"mappings":"AACA,QAAA,MAAM,aAAa,KAAqB,CAAC"}
@@ -1,6 +0,0 @@
1
- "use strict";
2
-
3
- var moduleExports = require('./index');
4
- globalThis.loaders = globalThis.loaders || {};
5
- module.exports = Object.assign(globalThis.loaders, moduleExports);
6
- //# sourceMappingURL=bundle.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"bundle.js","names":["moduleExports","require","globalThis","loaders","module","exports","Object","assign"],"sources":["../../src/bundle.ts"],"sourcesContent":["// @ts-nocheck\nconst moduleExports = require('./index');\nglobalThis.loaders = globalThis.loaders || {};\nmodule.exports = Object.assign(globalThis.loaders, moduleExports);\n"],"mappings":";;AACA,IAAMA,aAAa,GAAGC,OAAO,CAAC,SAAS,CAAC;AACxCC,UAAU,CAACC,OAAO,GAAGD,UAAU,CAACC,OAAO,IAAI,CAAC,CAAC;AAC7CC,MAAM,CAACC,OAAO,GAAGC,MAAM,CAACC,MAAM,CAACL,UAAU,CAACC,OAAO,EAAEH,aAAa,CAAC"}