@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.
- package/dist/{dist.min.js → dist.dev.js} +1929 -1728
- package/dist/filesystems/zip-filesystem.d.ts +1 -1
- package/dist/filesystems/zip-filesystem.d.ts.map +1 -1
- package/dist/{esm/filesystems → filesystems}/zip-filesystem.js +16 -21
- package/dist/filesystems/zip-filesystem.js.map +1 -0
- package/dist/hash-file-utility.d.ts +5 -26
- package/dist/hash-file-utility.d.ts.map +1 -1
- package/dist/hash-file-utility.js +29 -0
- package/dist/hash-file-utility.js.map +1 -0
- package/dist/index.cjs +653 -0
- package/dist/index.d.ts +2 -3
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +10 -0
- package/dist/index.js.map +1 -0
- package/dist/{esm/lib → lib}/tar/header.js +1 -1
- package/dist/lib/tar/header.js.map +1 -0
- package/dist/{esm/lib → lib}/tar/tar.js +8 -9
- package/dist/lib/tar/tar.js.map +1 -0
- package/dist/lib/tar/types.js.map +1 -0
- package/dist/lib/tar/utils.js.map +1 -0
- package/dist/parse-zip/cd-file-header.d.ts +2 -2
- package/dist/parse-zip/cd-file-header.d.ts.map +1 -1
- package/dist/parse-zip/cd-file-header.js +57 -0
- package/dist/parse-zip/cd-file-header.js.map +1 -0
- package/dist/parse-zip/end-of-central-directory.d.ts +2 -2
- package/dist/parse-zip/end-of-central-directory.d.ts.map +1 -1
- package/dist/parse-zip/end-of-central-directory.js +34 -0
- package/dist/parse-zip/end-of-central-directory.js.map +1 -0
- package/dist/parse-zip/local-file-header.d.ts +2 -1
- package/dist/parse-zip/local-file-header.d.ts.map +1 -1
- package/dist/{esm/parse-zip → parse-zip}/local-file-header.js +4 -2
- package/dist/parse-zip/local-file-header.js.map +1 -0
- package/dist/parse-zip/search-from-the-end.d.ts +1 -1
- package/dist/parse-zip/search-from-the-end.d.ts.map +1 -1
- package/dist/parse-zip/search-from-the-end.js.map +1 -0
- package/dist/{esm/tar-builder.js → tar-builder.js} +4 -5
- package/dist/tar-builder.js.map +1 -0
- package/dist/{esm/zip-loader.js → zip-loader.js} +3 -3
- package/dist/zip-loader.js.map +1 -0
- package/dist/{esm/zip-writer.js → zip-writer.js} +1 -1
- package/dist/zip-writer.js.map +1 -0
- package/package.json +17 -8
- package/src/filesystems/zip-filesystem.ts +13 -17
- package/src/hash-file-utility.ts +37 -85
- package/src/index.ts +3 -3
- package/src/parse-zip/cd-file-header.ts +20 -27
- package/src/parse-zip/end-of-central-directory.ts +16 -26
- package/src/parse-zip/local-file-header.ts +5 -7
- package/src/parse-zip/search-from-the-end.ts +1 -1
- package/dist/bundle.d.ts +0 -2
- package/dist/bundle.d.ts.map +0 -1
- package/dist/es5/bundle.js +0 -6
- package/dist/es5/bundle.js.map +0 -1
- package/dist/es5/filesystems/zip-filesystem.js +0 -372
- package/dist/es5/filesystems/zip-filesystem.js.map +0 -1
- package/dist/es5/hash-file-utility.js +0 -130
- package/dist/es5/hash-file-utility.js.map +0 -1
- package/dist/es5/index.js +0 -105
- package/dist/es5/index.js.map +0 -1
- package/dist/es5/lib/tar/header.js +0 -52
- package/dist/es5/lib/tar/header.js.map +0 -1
- package/dist/es5/lib/tar/tar.js +0 -137
- package/dist/es5/lib/tar/tar.js.map +0 -1
- package/dist/es5/lib/tar/types.js +0 -2
- package/dist/es5/lib/tar/types.js.map +0 -1
- package/dist/es5/lib/tar/utils.js +0 -32
- package/dist/es5/lib/tar/utils.js.map +0 -1
- package/dist/es5/parse-zip/cd-file-header.js +0 -163
- package/dist/es5/parse-zip/cd-file-header.js.map +0 -1
- package/dist/es5/parse-zip/end-of-central-directory.js +0 -98
- package/dist/es5/parse-zip/end-of-central-directory.js.map +0 -1
- package/dist/es5/parse-zip/local-file-header.js +0 -117
- package/dist/es5/parse-zip/local-file-header.js.map +0 -1
- package/dist/es5/parse-zip/search-from-the-end.js +0 -69
- package/dist/es5/parse-zip/search-from-the-end.js.map +0 -1
- package/dist/es5/tar-builder.js +0 -69
- package/dist/es5/tar-builder.js.map +0 -1
- package/dist/es5/zip-loader.js +0 -103
- package/dist/es5/zip-loader.js.map +0 -1
- package/dist/es5/zip-writer.js +0 -66
- package/dist/es5/zip-writer.js.map +0 -1
- package/dist/esm/bundle.js +0 -4
- package/dist/esm/bundle.js.map +0 -1
- package/dist/esm/filesystems/zip-filesystem.js.map +0 -1
- package/dist/esm/hash-file-utility.js +0 -55
- package/dist/esm/hash-file-utility.js.map +0 -1
- package/dist/esm/index.js +0 -10
- package/dist/esm/index.js.map +0 -1
- package/dist/esm/lib/tar/header.js.map +0 -1
- package/dist/esm/lib/tar/tar.js.map +0 -1
- package/dist/esm/lib/tar/types.js.map +0 -1
- package/dist/esm/lib/tar/utils.js.map +0 -1
- package/dist/esm/parse-zip/cd-file-header.js +0 -54
- package/dist/esm/parse-zip/cd-file-header.js.map +0 -1
- package/dist/esm/parse-zip/end-of-central-directory.js +0 -31
- package/dist/esm/parse-zip/end-of-central-directory.js.map +0 -1
- package/dist/esm/parse-zip/local-file-header.js.map +0 -1
- package/dist/esm/parse-zip/search-from-the-end.js.map +0 -1
- package/dist/esm/tar-builder.js.map +0 -1
- package/dist/esm/zip-loader.js.map +0 -1
- package/dist/esm/zip-writer.js.map +0 -1
- package/src/bundle.ts +0 -4
- /package/dist/{esm/lib → lib}/tar/types.js +0 -0
- /package/dist/{esm/lib → lib}/tar/utils.js +0 -0
- /package/dist/{esm/parse-zip → parse-zip}/search-from-the-end.js +0 -0
package/src/hash-file-utility.ts
CHANGED
|
@@ -1,101 +1,53 @@
|
|
|
1
|
-
import
|
|
1
|
+
import {MD5Hash} from '@loaders.gl/crypto';
|
|
2
2
|
import {FileProvider} from '@loaders.gl/loader-utils';
|
|
3
|
-
import {
|
|
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
|
-
*
|
|
15
|
-
* @param
|
|
16
|
-
* @
|
|
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
|
|
20
|
-
const
|
|
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
|
|
13
|
+
const hashMap: Record<string, bigint> = {};
|
|
24
14
|
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
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
|
-
|
|
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
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
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
|
|
91
|
-
|
|
92
|
-
|
|
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
|
-
|
|
95
|
-
|
|
96
|
-
|
|
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
|
-
|
|
100
|
-
return
|
|
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
|
-
|
|
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 {
|
|
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
|
-
|
|
44
|
+
file: FileProvider
|
|
45
45
|
): Promise<ZipCDFileHeader | null> => {
|
|
46
|
-
|
|
47
|
-
|
|
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
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
const
|
|
59
|
-
|
|
60
|
-
|
|
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
|
|
68
|
+
uncompressedSize = await file.getBigUint64(extraOffset + offsetInZip64Data);
|
|
78
69
|
offsetInZip64Data += 8n;
|
|
79
70
|
}
|
|
80
71
|
if (compressedSize === BigInt(0xffffffff)) {
|
|
81
|
-
compressedSize = await
|
|
72
|
+
compressedSize = await file.getBigUint64(extraOffset + offsetInZip64Data);
|
|
82
73
|
offsetInZip64Data += 8n;
|
|
83
74
|
}
|
|
84
75
|
if (fileDataOffset === BigInt(0xffffffff)) {
|
|
85
|
-
fileDataOffset = await
|
|
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*
|
|
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
|
|
28
|
+
* @param file - FileProvider instance
|
|
29
29
|
* @returns Info from the header
|
|
30
30
|
*/
|
|
31
|
-
export const parseEoCDRecord = async (
|
|
32
|
-
const zipEoCDOffset = await searchFromTheEnd(
|
|
31
|
+
export const parseEoCDRecord = async (file: FileProvider): Promise<ZipEoCDRecord> => {
|
|
32
|
+
const zipEoCDOffset = await searchFromTheEnd(file, eoCDSignature);
|
|
33
33
|
|
|
34
|
-
let cdRecordsNumber = BigInt(
|
|
35
|
-
|
|
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
|
-
|
|
43
|
-
|
|
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
|
|
44
|
+
const zip64EoCDOffset = await file.getBigUint64(
|
|
50
45
|
zip64EoCDLocatorOffset + ZIP64_EOCD_START_OFFSET_OFFSET
|
|
51
46
|
);
|
|
52
47
|
|
|
53
|
-
|
|
54
|
-
|
|
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
|
|
62
|
-
|
|
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
|
-
|
|
43
|
-
|
|
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
|
|
package/dist/bundle.d.ts
DELETED
package/dist/bundle.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"bundle.d.ts","sourceRoot":"","sources":["../src/bundle.ts"],"names":[],"mappings":"AACA,QAAA,MAAM,aAAa,KAAqB,CAAC"}
|
package/dist/es5/bundle.js
DELETED
package/dist/es5/bundle.js.map
DELETED
|
@@ -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"}
|