@loaders.gl/i3s 4.0.0-alpha.19 → 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.
- package/dist/dist.min.js +277 -260
- package/dist/es5/arcgis-webscene-loader.js +1 -1
- package/dist/es5/i3s-attribute-loader.js +1 -1
- package/dist/es5/i3s-building-scene-layer-loader.js +1 -1
- package/dist/es5/i3s-content-loader.js +1 -1
- package/dist/es5/i3s-loader.js +1 -1
- package/dist/es5/i3s-node-page-loader.js +1 -1
- package/dist/es5/i3s-slpk-loader.js +3 -3
- package/dist/es5/i3s-slpk-loader.js.map +1 -1
- package/dist/es5/index.js +0 -7
- package/dist/es5/index.js.map +1 -1
- package/dist/es5/lib/parsers/parse-slpk/parse-slpk.js +9 -25
- package/dist/es5/lib/parsers/parse-slpk/parse-slpk.js.map +1 -1
- package/dist/es5/lib/parsers/parse-slpk/slpk-archieve.js +9 -33
- package/dist/es5/lib/parsers/parse-slpk/slpk-archieve.js.map +1 -1
- package/dist/esm/arcgis-webscene-loader.js +1 -1
- package/dist/esm/i3s-attribute-loader.js +1 -1
- package/dist/esm/i3s-building-scene-layer-loader.js +1 -1
- package/dist/esm/i3s-content-loader.js +1 -1
- package/dist/esm/i3s-loader.js +1 -1
- package/dist/esm/i3s-node-page-loader.js +1 -1
- package/dist/esm/i3s-slpk-loader.js +3 -3
- package/dist/esm/i3s-slpk-loader.js.map +1 -1
- package/dist/esm/index.js +0 -1
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/lib/parsers/parse-slpk/parse-slpk.js +2 -18
- package/dist/esm/lib/parsers/parse-slpk/parse-slpk.js.map +1 -1
- package/dist/esm/lib/parsers/parse-slpk/slpk-archieve.js +5 -29
- package/dist/esm/lib/parsers/parse-slpk/slpk-archieve.js.map +1 -1
- package/dist/i3s-content-worker-node.js +2 -2
- package/dist/i3s-content-worker-node.js.map +2 -2
- package/dist/i3s-content-worker.js +12 -12
- package/dist/i3s-slpk-loader.js +2 -2
- package/dist/index.d.ts +0 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -3
- package/dist/lib/parsers/parse-slpk/parse-slpk.d.ts +1 -1
- package/dist/lib/parsers/parse-slpk/parse-slpk.d.ts.map +1 -1
- package/dist/lib/parsers/parse-slpk/parse-slpk.js +9 -30
- package/dist/lib/parsers/parse-slpk/slpk-archieve.d.ts +2 -21
- package/dist/lib/parsers/parse-slpk/slpk-archieve.d.ts.map +1 -1
- package/dist/lib/parsers/parse-slpk/slpk-archieve.js +7 -46
- package/package.json +9 -9
- package/src/i3s-slpk-loader.ts +2 -2
- package/src/index.ts +0 -2
- package/src/lib/parsers/parse-slpk/parse-slpk.ts +12 -32
- package/src/lib/parsers/parse-slpk/slpk-archieve.ts +5 -54
- package/dist/es5/lib/parsers/parse-zip/cd-file-header.js +0 -121
- package/dist/es5/lib/parsers/parse-zip/cd-file-header.js.map +0 -1
- package/dist/es5/lib/parsers/parse-zip/data-view-file-provider.js +0 -129
- package/dist/es5/lib/parsers/parse-zip/data-view-file-provider.js.map +0 -1
- package/dist/es5/lib/parsers/parse-zip/end-of-central-directory.js +0 -100
- package/dist/es5/lib/parsers/parse-zip/end-of-central-directory.js.map +0 -1
- package/dist/es5/lib/parsers/parse-zip/file-provider.js +0 -2
- package/dist/es5/lib/parsers/parse-zip/file-provider.js.map +0 -1
- package/dist/es5/lib/parsers/parse-zip/local-file-header.js +0 -113
- package/dist/es5/lib/parsers/parse-zip/local-file-header.js.map +0 -1
- package/dist/es5/lib/parsers/parse-zip/search-from-the-end.js +0 -69
- package/dist/es5/lib/parsers/parse-zip/search-from-the-end.js.map +0 -1
- package/dist/esm/lib/parsers/parse-zip/cd-file-header.js +0 -45
- package/dist/esm/lib/parsers/parse-zip/cd-file-header.js.map +0 -1
- package/dist/esm/lib/parsers/parse-zip/data-view-file-provider.js +0 -32
- package/dist/esm/lib/parsers/parse-zip/data-view-file-provider.js.map +0 -1
- package/dist/esm/lib/parsers/parse-zip/end-of-central-directory.js +0 -33
- package/dist/esm/lib/parsers/parse-zip/end-of-central-directory.js.map +0 -1
- package/dist/esm/lib/parsers/parse-zip/file-provider.js +0 -2
- package/dist/esm/lib/parsers/parse-zip/file-provider.js.map +0 -1
- package/dist/esm/lib/parsers/parse-zip/local-file-header.js +0 -40
- package/dist/esm/lib/parsers/parse-zip/local-file-header.js.map +0 -1
- package/dist/esm/lib/parsers/parse-zip/search-from-the-end.js +0 -16
- package/dist/esm/lib/parsers/parse-zip/search-from-the-end.js.map +0 -1
- package/dist/lib/parsers/parse-zip/cd-file-header.d.ts +0 -31
- package/dist/lib/parsers/parse-zip/cd-file-header.d.ts.map +0 -1
- package/dist/lib/parsers/parse-zip/cd-file-header.js +0 -55
- package/dist/lib/parsers/parse-zip/data-view-file-provider.d.ts +0 -36
- package/dist/lib/parsers/parse-zip/data-view-file-provider.d.ts.map +0 -1
- package/dist/lib/parsers/parse-zip/data-view-file-provider.js +0 -61
- package/dist/lib/parsers/parse-zip/end-of-central-directory.d.ts +0 -18
- package/dist/lib/parsers/parse-zip/end-of-central-directory.d.ts.map +0 -1
- package/dist/lib/parsers/parse-zip/end-of-central-directory.js +0 -41
- package/dist/lib/parsers/parse-zip/file-provider.d.ts +0 -36
- package/dist/lib/parsers/parse-zip/file-provider.d.ts.map +0 -1
- package/dist/lib/parsers/parse-zip/file-provider.js +0 -2
- package/dist/lib/parsers/parse-zip/local-file-header.d.ts +0 -27
- package/dist/lib/parsers/parse-zip/local-file-header.d.ts.map +0 -1
- package/dist/lib/parsers/parse-zip/local-file-header.js +0 -53
- package/dist/lib/parsers/parse-zip/search-from-the-end.d.ts +0 -11
- package/dist/lib/parsers/parse-zip/search-from-the-end.d.ts.map +0 -1
- package/dist/lib/parsers/parse-zip/search-from-the-end.js +0 -31
- package/src/lib/parsers/parse-zip/cd-file-header.ts +0 -106
- package/src/lib/parsers/parse-zip/data-view-file-provider.ts +0 -69
- package/src/lib/parsers/parse-zip/end-of-central-directory.ts +0 -78
- package/src/lib/parsers/parse-zip/file-provider.ts +0 -40
- package/src/lib/parsers/parse-zip/local-file-header.ts +0 -91
- package/src/lib/parsers/parse-zip/search-from-the-end.ts +0 -38
|
@@ -1,45 +0,0 @@
|
|
|
1
|
-
const offsets = {
|
|
2
|
-
CD_COMPRESSED_SIZE_OFFSET: 20n,
|
|
3
|
-
CD_UNCOMPRESSED_SIZE_OFFSET: 24n,
|
|
4
|
-
CD_FILE_NAME_LENGTH_OFFSET: 28n,
|
|
5
|
-
CD_EXTRA_FIELD_LENGTH_OFFSET: 30n,
|
|
6
|
-
CD_LOCAL_HEADER_OFFSET_OFFSET: 42n,
|
|
7
|
-
CD_FILE_NAME_OFFSET: 46n
|
|
8
|
-
};
|
|
9
|
-
export const signature = [0x50, 0x4b, 0x01, 0x02];
|
|
10
|
-
export const parseZipCDFileHeader = async (headerOffset, buffer) => {
|
|
11
|
-
if (Buffer.from(await buffer.slice(headerOffset, headerOffset + 4n)).compare(Buffer.from(signature)) !== 0) {
|
|
12
|
-
return null;
|
|
13
|
-
}
|
|
14
|
-
let compressedSize = BigInt(await buffer.getUint32(headerOffset + offsets.CD_COMPRESSED_SIZE_OFFSET));
|
|
15
|
-
let uncompressedSize = BigInt(await buffer.getUint32(headerOffset + offsets.CD_UNCOMPRESSED_SIZE_OFFSET));
|
|
16
|
-
const extraFieldLength = await buffer.getUint16(headerOffset + offsets.CD_EXTRA_FIELD_LENGTH_OFFSET);
|
|
17
|
-
const fileNameLength = await buffer.getUint16(headerOffset + offsets.CD_FILE_NAME_LENGTH_OFFSET);
|
|
18
|
-
const fileName = new TextDecoder().decode(await buffer.slice(headerOffset + offsets.CD_FILE_NAME_OFFSET, headerOffset + offsets.CD_FILE_NAME_OFFSET + BigInt(fileNameLength)));
|
|
19
|
-
const extraOffset = headerOffset + offsets.CD_FILE_NAME_OFFSET + BigInt(fileNameLength);
|
|
20
|
-
const oldFormatOffset = await buffer.getUint32(headerOffset + offsets.CD_LOCAL_HEADER_OFFSET_OFFSET);
|
|
21
|
-
let fileDataOffset = BigInt(oldFormatOffset);
|
|
22
|
-
let offsetInZip64Data = 4n;
|
|
23
|
-
if (uncompressedSize === BigInt(0xffffffff)) {
|
|
24
|
-
uncompressedSize = await buffer.getBigUint64(extraOffset + offsetInZip64Data);
|
|
25
|
-
offsetInZip64Data += 8n;
|
|
26
|
-
}
|
|
27
|
-
if (compressedSize === BigInt(0xffffffff)) {
|
|
28
|
-
compressedSize = await buffer.getBigUint64(extraOffset + offsetInZip64Data);
|
|
29
|
-
offsetInZip64Data += 8n;
|
|
30
|
-
}
|
|
31
|
-
if (fileDataOffset === BigInt(0xffffffff)) {
|
|
32
|
-
fileDataOffset = await buffer.getBigUint64(extraOffset + offsetInZip64Data);
|
|
33
|
-
}
|
|
34
|
-
const localHeaderOffset = fileDataOffset;
|
|
35
|
-
return {
|
|
36
|
-
compressedSize,
|
|
37
|
-
uncompressedSize,
|
|
38
|
-
extraFieldLength,
|
|
39
|
-
fileNameLength,
|
|
40
|
-
fileName,
|
|
41
|
-
extraOffset,
|
|
42
|
-
localHeaderOffset
|
|
43
|
-
};
|
|
44
|
-
};
|
|
45
|
-
//# sourceMappingURL=cd-file-header.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"cd-file-header.js","names":["offsets","CD_COMPRESSED_SIZE_OFFSET","CD_UNCOMPRESSED_SIZE_OFFSET","CD_FILE_NAME_LENGTH_OFFSET","CD_EXTRA_FIELD_LENGTH_OFFSET","CD_LOCAL_HEADER_OFFSET_OFFSET","CD_FILE_NAME_OFFSET","signature","parseZipCDFileHeader","headerOffset","buffer","Buffer","from","slice","compare","compressedSize","BigInt","getUint32","uncompressedSize","extraFieldLength","getUint16","fileNameLength","fileName","TextDecoder","decode","extraOffset","oldFormatOffset","fileDataOffset","offsetInZip64Data","getBigUint64","localHeaderOffset"],"sources":["../../../../../src/lib/parsers/parse-zip/cd-file-header.ts"],"sourcesContent":["import {FileProvider} from './file-provider';\nimport {ZipSignature} from './search-from-the-end';\n\n/**\n * zip central directory file header info\n * according to https://en.wikipedia.org/wiki/ZIP_(file_format)\n */\nexport type ZipCDFileHeader = {\n /** Compressed size */\n compressedSize: bigint;\n /** Uncompressed size */\n uncompressedSize: bigint;\n /** Extra field size */\n extraFieldLength: number;\n /** File name length */\n fileNameLength: number;\n /** File name */\n fileName: string;\n /** Extra field offset */\n extraOffset: bigint;\n /** Relative offset of local file header */\n localHeaderOffset: bigint;\n};\n\nconst offsets = {\n CD_COMPRESSED_SIZE_OFFSET: 20n,\n CD_UNCOMPRESSED_SIZE_OFFSET: 24n,\n CD_FILE_NAME_LENGTH_OFFSET: 28n,\n CD_EXTRA_FIELD_LENGTH_OFFSET: 30n,\n CD_LOCAL_HEADER_OFFSET_OFFSET: 42n,\n CD_FILE_NAME_OFFSET: 46n\n};\n\nexport const signature: ZipSignature = [0x50, 0x4b, 0x01, 0x02];\n\n/**\n * Parses central directory file header of zip file\n * @param headerOffset - offset in the archive where header starts\n * @param buffer - buffer containing whole array\n * @returns Info from the header\n */\nexport const parseZipCDFileHeader = async (\n headerOffset: bigint,\n buffer: FileProvider\n): Promise<ZipCDFileHeader | null> => {\n if (\n Buffer.from(await buffer.slice(headerOffset, headerOffset + 4n)).compare(\n Buffer.from(signature)\n ) !== 0\n ) {\n return null;\n }\n\n let compressedSize = BigInt(\n await buffer.getUint32(headerOffset + offsets.CD_COMPRESSED_SIZE_OFFSET)\n );\n\n let uncompressedSize = BigInt(\n await buffer.getUint32(headerOffset + offsets.CD_UNCOMPRESSED_SIZE_OFFSET)\n );\n\n const extraFieldLength = await buffer.getUint16(\n headerOffset + offsets.CD_EXTRA_FIELD_LENGTH_OFFSET\n );\n\n const fileNameLength = await buffer.getUint16(headerOffset + offsets.CD_FILE_NAME_LENGTH_OFFSET);\n\n const fileName = new TextDecoder().decode(\n await buffer.slice(\n headerOffset + offsets.CD_FILE_NAME_OFFSET,\n headerOffset + offsets.CD_FILE_NAME_OFFSET + BigInt(fileNameLength)\n )\n );\n\n const extraOffset = headerOffset + offsets.CD_FILE_NAME_OFFSET + BigInt(fileNameLength);\n\n const oldFormatOffset = await buffer.getUint32(\n headerOffset + offsets.CD_LOCAL_HEADER_OFFSET_OFFSET\n );\n\n let fileDataOffset = BigInt(oldFormatOffset);\n let offsetInZip64Data = 4n;\n // looking for info that might be also be in zip64 extra field\n if (uncompressedSize === BigInt(0xffffffff)) {\n uncompressedSize = await buffer.getBigUint64(extraOffset + offsetInZip64Data);\n offsetInZip64Data += 8n;\n }\n if (compressedSize === BigInt(0xffffffff)) {\n compressedSize = await buffer.getBigUint64(extraOffset + offsetInZip64Data);\n offsetInZip64Data += 8n;\n }\n if (fileDataOffset === BigInt(0xffffffff)) {\n fileDataOffset = await buffer.getBigUint64(extraOffset + offsetInZip64Data); // setting it to the one from zip64\n }\n const localHeaderOffset = fileDataOffset;\n\n return {\n compressedSize,\n uncompressedSize,\n extraFieldLength,\n fileNameLength,\n fileName,\n extraOffset,\n localHeaderOffset\n };\n};\n"],"mappings":"AAwBA,MAAMA,OAAO,GAAG;EACdC,yBAAyB,EAAE,GAAG;EAC9BC,2BAA2B,EAAE,GAAG;EAChCC,0BAA0B,EAAE,GAAG;EAC/BC,4BAA4B,EAAE,GAAG;EACjCC,6BAA6B,EAAE,GAAG;EAClCC,mBAAmB,EAAE;AACvB,CAAC;AAED,OAAO,MAAMC,SAAuB,GAAG,CAAC,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,CAAC;AAQ/D,OAAO,MAAMC,oBAAoB,GAAG,MAAAA,CAClCC,YAAoB,EACpBC,MAAoB,KACgB;EACpC,IACEC,MAAM,CAACC,IAAI,CAAC,MAAMF,MAAM,CAACG,KAAK,CAACJ,YAAY,EAAEA,YAAY,GAAG,EAAE,CAAC,CAAC,CAACK,OAAO,CACtEH,MAAM,CAACC,IAAI,CAACL,SAAS,CACvB,CAAC,KAAK,CAAC,EACP;IACA,OAAO,IAAI;EACb;EAEA,IAAIQ,cAAc,GAAGC,MAAM,CACzB,MAAMN,MAAM,CAACO,SAAS,CAACR,YAAY,GAAGT,OAAO,CAACC,yBAAyB,CACzE,CAAC;EAED,IAAIiB,gBAAgB,GAAGF,MAAM,CAC3B,MAAMN,MAAM,CAACO,SAAS,CAACR,YAAY,GAAGT,OAAO,CAACE,2BAA2B,CAC3E,CAAC;EAED,MAAMiB,gBAAgB,GAAG,MAAMT,MAAM,CAACU,SAAS,CAC7CX,YAAY,GAAGT,OAAO,CAACI,4BACzB,CAAC;EAED,MAAMiB,cAAc,GAAG,MAAMX,MAAM,CAACU,SAAS,CAACX,YAAY,GAAGT,OAAO,CAACG,0BAA0B,CAAC;EAEhG,MAAMmB,QAAQ,GAAG,IAAIC,WAAW,CAAC,CAAC,CAACC,MAAM,CACvC,MAAMd,MAAM,CAACG,KAAK,CAChBJ,YAAY,GAAGT,OAAO,CAACM,mBAAmB,EAC1CG,YAAY,GAAGT,OAAO,CAACM,mBAAmB,GAAGU,MAAM,CAACK,cAAc,CACpE,CACF,CAAC;EAED,MAAMI,WAAW,GAAGhB,YAAY,GAAGT,OAAO,CAACM,mBAAmB,GAAGU,MAAM,CAACK,cAAc,CAAC;EAEvF,MAAMK,eAAe,GAAG,MAAMhB,MAAM,CAACO,SAAS,CAC5CR,YAAY,GAAGT,OAAO,CAACK,6BACzB,CAAC;EAED,IAAIsB,cAAc,GAAGX,MAAM,CAACU,eAAe,CAAC;EAC5C,IAAIE,iBAAiB,GAAG,EAAE;EAE1B,IAAIV,gBAAgB,KAAKF,MAAM,CAAC,UAAU,CAAC,EAAE;IAC3CE,gBAAgB,GAAG,MAAMR,MAAM,CAACmB,YAAY,CAACJ,WAAW,GAAGG,iBAAiB,CAAC;IAC7EA,iBAAiB,IAAI,EAAE;EACzB;EACA,IAAIb,cAAc,KAAKC,MAAM,CAAC,UAAU,CAAC,EAAE;IACzCD,cAAc,GAAG,MAAML,MAAM,CAACmB,YAAY,CAACJ,WAAW,GAAGG,iBAAiB,CAAC;IAC3EA,iBAAiB,IAAI,EAAE;EACzB;EACA,IAAID,cAAc,KAAKX,MAAM,CAAC,UAAU,CAAC,EAAE;IACzCW,cAAc,GAAG,MAAMjB,MAAM,CAACmB,YAAY,CAACJ,WAAW,GAAGG,iBAAiB,CAAC;EAC7E;EACA,MAAME,iBAAiB,GAAGH,cAAc;EAExC,OAAO;IACLZ,cAAc;IACdG,gBAAgB;IAChBC,gBAAgB;IAChBE,cAAc;IACdC,QAAQ;IACRG,WAAW;IACXK;EACF,CAAC;AACH,CAAC"}
|
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
|
|
2
|
-
const toNumber = bigint => {
|
|
3
|
-
if (bigint > Number.MAX_SAFE_INTEGER) {
|
|
4
|
-
throw new Error('Offset is out of bounds');
|
|
5
|
-
}
|
|
6
|
-
return Number(bigint);
|
|
7
|
-
};
|
|
8
|
-
export class DataViewFileProvider {
|
|
9
|
-
constructor(file) {
|
|
10
|
-
_defineProperty(this, "file", void 0);
|
|
11
|
-
this.file = file;
|
|
12
|
-
}
|
|
13
|
-
async getUint8(offset) {
|
|
14
|
-
return this.file.getUint8(toNumber(offset));
|
|
15
|
-
}
|
|
16
|
-
async getUint16(offset) {
|
|
17
|
-
return this.file.getUint16(toNumber(offset), true);
|
|
18
|
-
}
|
|
19
|
-
async getUint32(offset) {
|
|
20
|
-
return this.file.getUint32(toNumber(offset), true);
|
|
21
|
-
}
|
|
22
|
-
async getBigUint64(offset) {
|
|
23
|
-
return this.file.getBigUint64(toNumber(offset), true);
|
|
24
|
-
}
|
|
25
|
-
async slice(startOffset, endOffset) {
|
|
26
|
-
return this.file.buffer.slice(toNumber(startOffset), toNumber(endOffset));
|
|
27
|
-
}
|
|
28
|
-
get length() {
|
|
29
|
-
return BigInt(this.file.byteLength);
|
|
30
|
-
}
|
|
31
|
-
}
|
|
32
|
-
//# sourceMappingURL=data-view-file-provider.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"data-view-file-provider.js","names":["toNumber","bigint","Number","MAX_SAFE_INTEGER","Error","DataViewFileProvider","constructor","file","_defineProperty","getUint8","offset","getUint16","getUint32","getBigUint64","slice","startOffset","endOffset","buffer","length","BigInt","byteLength"],"sources":["../../../../../src/lib/parsers/parse-zip/data-view-file-provider.ts"],"sourcesContent":["import {FileProvider} from './file-provider';\n\n/**\n * Checks if bigint can be converted to number and convert it if possible\n * @param bigint bigint to be converted\n * @returns number\n */\nconst toNumber = (bigint: bigint) => {\n if (bigint > Number.MAX_SAFE_INTEGER) {\n throw new Error('Offset is out of bounds');\n }\n return Number(bigint);\n};\n\n/** Provides file data using DataView */\nexport class DataViewFileProvider implements FileProvider {\n /** The DataView from which data is provided */\n private file: DataView;\n\n constructor(file: DataView) {\n this.file = file;\n }\n\n /**\n * Gets an unsigned 8-bit integer at the specified byte offset from the start of the file.\n * @param offset The offset, in bytes, from the start of the file where to read the data.\n */\n async getUint8(offset: bigint): Promise<number> {\n return this.file.getUint8(toNumber(offset));\n }\n\n /**\n * Gets an unsigned 16-bit intege at the specified byte offset from the start of the file.\n * @param offset The offset, in bytes, from the start of the file where to read the data.\n */\n async getUint16(offset: bigint): Promise<number> {\n return this.file.getUint16(toNumber(offset), true);\n }\n\n /**\n * Gets an unsigned 32-bit integer at the specified byte offset from the start of the file.\n * @param offset The offset, in bytes, from the start of the file where to read the data.\n */\n async getUint32(offset: bigint): Promise<number> {\n return this.file.getUint32(toNumber(offset), true);\n }\n\n /**\n * Gets an unsigned 64-bit integer at the specified byte offset from the start of the file.\n * @param offset The offset, in bytes, from the start of the file where to read the data.\n */\n async getBigUint64(offset: bigint): Promise<bigint> {\n return this.file.getBigUint64(toNumber(offset), true);\n }\n\n /**\n * returns an ArrayBuffer whose contents are a copy of this file bytes from startOffset, inclusive, up to endOffset, exclusive.\n * @param startOffset The offset, in bytes, from the start of the file where to start reading the data.\n * @param endOffset The offset, in bytes, from the start of the file where to end reading the data.\n */\n async slice(startOffset: bigint, endOffset: bigint): Promise<ArrayBuffer> {\n return this.file.buffer.slice(toNumber(startOffset), toNumber(endOffset));\n }\n\n /** the length (in bytes) of the data. */\n get length() {\n return BigInt(this.file.byteLength);\n }\n}\n"],"mappings":";AAOA,MAAMA,QAAQ,GAAIC,MAAc,IAAK;EACnC,IAAIA,MAAM,GAAGC,MAAM,CAACC,gBAAgB,EAAE;IACpC,MAAM,IAAIC,KAAK,CAAC,yBAAyB,CAAC;EAC5C;EACA,OAAOF,MAAM,CAACD,MAAM,CAAC;AACvB,CAAC;AAGD,OAAO,MAAMI,oBAAoB,CAAyB;EAIxDC,WAAWA,CAACC,IAAc,EAAE;IAAAC,eAAA;IAC1B,IAAI,CAACD,IAAI,GAAGA,IAAI;EAClB;EAMA,MAAME,QAAQA,CAACC,MAAc,EAAmB;IAC9C,OAAO,IAAI,CAACH,IAAI,CAACE,QAAQ,CAACT,QAAQ,CAACU,MAAM,CAAC,CAAC;EAC7C;EAMA,MAAMC,SAASA,CAACD,MAAc,EAAmB;IAC/C,OAAO,IAAI,CAACH,IAAI,CAACI,SAAS,CAACX,QAAQ,CAACU,MAAM,CAAC,EAAE,IAAI,CAAC;EACpD;EAMA,MAAME,SAASA,CAACF,MAAc,EAAmB;IAC/C,OAAO,IAAI,CAACH,IAAI,CAACK,SAAS,CAACZ,QAAQ,CAACU,MAAM,CAAC,EAAE,IAAI,CAAC;EACpD;EAMA,MAAMG,YAAYA,CAACH,MAAc,EAAmB;IAClD,OAAO,IAAI,CAACH,IAAI,CAACM,YAAY,CAACb,QAAQ,CAACU,MAAM,CAAC,EAAE,IAAI,CAAC;EACvD;EAOA,MAAMI,KAAKA,CAACC,WAAmB,EAAEC,SAAiB,EAAwB;IACxE,OAAO,IAAI,CAACT,IAAI,CAACU,MAAM,CAACH,KAAK,CAACd,QAAQ,CAACe,WAAW,CAAC,EAAEf,QAAQ,CAACgB,SAAS,CAAC,CAAC;EAC3E;EAGA,IAAIE,MAAMA,CAAA,EAAG;IACX,OAAOC,MAAM,CAAC,IAAI,CAACZ,IAAI,CAACa,UAAU,CAAC;EACrC;AACF"}
|
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
import { searchFromTheEnd } from './search-from-the-end';
|
|
2
|
-
const eoCDSignature = [0x50, 0x4b, 0x05, 0x06];
|
|
3
|
-
const zip64EoCDLocatorSignature = Buffer.from([0x50, 0x4b, 0x06, 0x07]);
|
|
4
|
-
const zip64EoCDSignature = Buffer.from([0x50, 0x4b, 0x06, 0x06]);
|
|
5
|
-
const offsets = {
|
|
6
|
-
CD_RECORDS_NUMBER_OFFSET: 8n,
|
|
7
|
-
CD_START_OFFSET_OFFSET: 16n,
|
|
8
|
-
ZIP64_EOCD_START_OFFSET_OFFSET: 8n,
|
|
9
|
-
ZIP64_CD_RECORDS_NUMBER_OFFSET: 24n,
|
|
10
|
-
ZIP64_CD_START_OFFSET_OFFSET: 48n
|
|
11
|
-
};
|
|
12
|
-
export const parseEoCDRecord = async fileProvider => {
|
|
13
|
-
const zipEoCDOffset = await searchFromTheEnd(fileProvider, eoCDSignature);
|
|
14
|
-
let cdRecordsNumber = BigInt(await fileProvider.getUint16(zipEoCDOffset + offsets.CD_RECORDS_NUMBER_OFFSET));
|
|
15
|
-
let cdStartOffset = BigInt(await fileProvider.getUint32(zipEoCDOffset + offsets.CD_START_OFFSET_OFFSET));
|
|
16
|
-
if (cdStartOffset === BigInt(0xffffffff) || cdRecordsNumber === BigInt(0xffffffff)) {
|
|
17
|
-
const zip64EoCDLocatorOffset = zipEoCDOffset - 20n;
|
|
18
|
-
if (Buffer.from(await fileProvider.slice(zip64EoCDLocatorOffset, zip64EoCDLocatorOffset + 4n)).compare(zip64EoCDLocatorSignature) !== 0) {
|
|
19
|
-
throw new Error('zip64 EoCD locator not found');
|
|
20
|
-
}
|
|
21
|
-
const zip64EoCDOffset = await fileProvider.getBigUint64(zip64EoCDLocatorOffset + offsets.ZIP64_EOCD_START_OFFSET_OFFSET);
|
|
22
|
-
if (Buffer.from(await fileProvider.slice(zip64EoCDOffset, zip64EoCDOffset + 4n)).compare(zip64EoCDSignature) !== 0) {
|
|
23
|
-
throw new Error('zip64 EoCD not found');
|
|
24
|
-
}
|
|
25
|
-
cdRecordsNumber = await fileProvider.getBigUint64(zip64EoCDOffset + offsets.ZIP64_CD_RECORDS_NUMBER_OFFSET);
|
|
26
|
-
cdStartOffset = await fileProvider.getBigUint64(zip64EoCDOffset + offsets.ZIP64_CD_START_OFFSET_OFFSET);
|
|
27
|
-
}
|
|
28
|
-
return {
|
|
29
|
-
cdRecordsNumber,
|
|
30
|
-
cdStartOffset
|
|
31
|
-
};
|
|
32
|
-
};
|
|
33
|
-
//# sourceMappingURL=end-of-central-directory.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"end-of-central-directory.js","names":["searchFromTheEnd","eoCDSignature","zip64EoCDLocatorSignature","Buffer","from","zip64EoCDSignature","offsets","CD_RECORDS_NUMBER_OFFSET","CD_START_OFFSET_OFFSET","ZIP64_EOCD_START_OFFSET_OFFSET","ZIP64_CD_RECORDS_NUMBER_OFFSET","ZIP64_CD_START_OFFSET_OFFSET","parseEoCDRecord","fileProvider","zipEoCDOffset","cdRecordsNumber","BigInt","getUint16","cdStartOffset","getUint32","zip64EoCDLocatorOffset","slice","compare","Error","zip64EoCDOffset","getBigUint64"],"sources":["../../../../../src/lib/parsers/parse-zip/end-of-central-directory.ts"],"sourcesContent":["import {FileProvider} from './file-provider';\nimport {ZipSignature, searchFromTheEnd} from './search-from-the-end';\n\n/**\n * End of central directory info\n * according to https://en.wikipedia.org/wiki/ZIP_(file_format)\n */\nexport type ZipEoCDRecord = {\n /** Relative offset of local file header */\n cdStartOffset: bigint;\n /** Relative offset of local file header */\n cdRecordsNumber: bigint;\n};\n\nconst eoCDSignature: ZipSignature = [0x50, 0x4b, 0x05, 0x06];\nconst zip64EoCDLocatorSignature = Buffer.from([0x50, 0x4b, 0x06, 0x07]);\nconst zip64EoCDSignature = Buffer.from([0x50, 0x4b, 0x06, 0x06]);\n\nconst offsets = {\n CD_RECORDS_NUMBER_OFFSET: 8n,\n CD_START_OFFSET_OFFSET: 16n,\n\n ZIP64_EOCD_START_OFFSET_OFFSET: 8n,\n\n ZIP64_CD_RECORDS_NUMBER_OFFSET: 24n,\n ZIP64_CD_START_OFFSET_OFFSET: 48n\n};\n\n/**\n * Parses end of central directory record of zip file\n * @param fileProvider - FileProvider instance\n * @returns Info from the header\n */\nexport const parseEoCDRecord = async (fileProvider: FileProvider): Promise<ZipEoCDRecord> => {\n const zipEoCDOffset = await searchFromTheEnd(fileProvider, eoCDSignature);\n\n let cdRecordsNumber = BigInt(\n await fileProvider.getUint16(zipEoCDOffset + offsets.CD_RECORDS_NUMBER_OFFSET)\n );\n let cdStartOffset = BigInt(\n await fileProvider.getUint32(zipEoCDOffset + offsets.CD_START_OFFSET_OFFSET)\n );\n\n if (cdStartOffset === BigInt(0xffffffff) || cdRecordsNumber === BigInt(0xffffffff)) {\n const zip64EoCDLocatorOffset = zipEoCDOffset - 20n;\n\n if (\n Buffer.from(\n await fileProvider.slice(zip64EoCDLocatorOffset, zip64EoCDLocatorOffset + 4n)\n ).compare(zip64EoCDLocatorSignature) !== 0\n ) {\n throw new Error('zip64 EoCD locator not found');\n }\n const zip64EoCDOffset = await fileProvider.getBigUint64(\n zip64EoCDLocatorOffset + offsets.ZIP64_EOCD_START_OFFSET_OFFSET\n );\n\n if (\n Buffer.from(await fileProvider.slice(zip64EoCDOffset, zip64EoCDOffset + 4n)).compare(\n zip64EoCDSignature\n ) !== 0\n ) {\n throw new Error('zip64 EoCD not found');\n }\n\n cdRecordsNumber = await fileProvider.getBigUint64(\n zip64EoCDOffset + offsets.ZIP64_CD_RECORDS_NUMBER_OFFSET\n );\n cdStartOffset = await fileProvider.getBigUint64(\n zip64EoCDOffset + offsets.ZIP64_CD_START_OFFSET_OFFSET\n );\n }\n\n return {\n cdRecordsNumber,\n cdStartOffset\n };\n};\n"],"mappings":"AACA,SAAsBA,gBAAgB,QAAO,uBAAuB;AAapE,MAAMC,aAA2B,GAAG,CAAC,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,CAAC;AAC5D,MAAMC,yBAAyB,GAAGC,MAAM,CAACC,IAAI,CAAC,CAAC,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,CAAC,CAAC;AACvE,MAAMC,kBAAkB,GAAGF,MAAM,CAACC,IAAI,CAAC,CAAC,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,CAAC,CAAC;AAEhE,MAAME,OAAO,GAAG;EACdC,wBAAwB,EAAE,EAAE;EAC5BC,sBAAsB,EAAE,GAAG;EAE3BC,8BAA8B,EAAE,EAAE;EAElCC,8BAA8B,EAAE,GAAG;EACnCC,4BAA4B,EAAE;AAChC,CAAC;AAOD,OAAO,MAAMC,eAAe,GAAG,MAAOC,YAA0B,IAA6B;EAC3F,MAAMC,aAAa,GAAG,MAAMd,gBAAgB,CAACa,YAAY,EAAEZ,aAAa,CAAC;EAEzE,IAAIc,eAAe,GAAGC,MAAM,CAC1B,MAAMH,YAAY,CAACI,SAAS,CAACH,aAAa,GAAGR,OAAO,CAACC,wBAAwB,CAC/E,CAAC;EACD,IAAIW,aAAa,GAAGF,MAAM,CACxB,MAAMH,YAAY,CAACM,SAAS,CAACL,aAAa,GAAGR,OAAO,CAACE,sBAAsB,CAC7E,CAAC;EAED,IAAIU,aAAa,KAAKF,MAAM,CAAC,UAAU,CAAC,IAAID,eAAe,KAAKC,MAAM,CAAC,UAAU,CAAC,EAAE;IAClF,MAAMI,sBAAsB,GAAGN,aAAa,GAAG,GAAG;IAElD,IACEX,MAAM,CAACC,IAAI,CACT,MAAMS,YAAY,CAACQ,KAAK,CAACD,sBAAsB,EAAEA,sBAAsB,GAAG,EAAE,CAC9E,CAAC,CAACE,OAAO,CAACpB,yBAAyB,CAAC,KAAK,CAAC,EAC1C;MACA,MAAM,IAAIqB,KAAK,CAAC,8BAA8B,CAAC;IACjD;IACA,MAAMC,eAAe,GAAG,MAAMX,YAAY,CAACY,YAAY,CACrDL,sBAAsB,GAAGd,OAAO,CAACG,8BACnC,CAAC;IAED,IACEN,MAAM,CAACC,IAAI,CAAC,MAAMS,YAAY,CAACQ,KAAK,CAACG,eAAe,EAAEA,eAAe,GAAG,EAAE,CAAC,CAAC,CAACF,OAAO,CAClFjB,kBACF,CAAC,KAAK,CAAC,EACP;MACA,MAAM,IAAIkB,KAAK,CAAC,sBAAsB,CAAC;IACzC;IAEAR,eAAe,GAAG,MAAMF,YAAY,CAACY,YAAY,CAC/CD,eAAe,GAAGlB,OAAO,CAACI,8BAC5B,CAAC;IACDQ,aAAa,GAAG,MAAML,YAAY,CAACY,YAAY,CAC7CD,eAAe,GAAGlB,OAAO,CAACK,4BAC5B,CAAC;EACH;EAEA,OAAO;IACLI,eAAe;IACfG;EACF,CAAC;AACH,CAAC"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"file-provider.js","names":[],"sources":["../../../../../src/lib/parsers/parse-zip/file-provider.ts"],"sourcesContent":["/**\n * Interface for providing file data\n */\nexport interface FileProvider {\n /**\n * Gets an unsigned 8-bit integer at the specified byte offset from the start of the file.\n * @param offset The offset, in bytes, from the start of the file where to read the data.\n */\n getUint8(offset: bigint): Promise<number>;\n\n /**\n * Gets an unsigned 16-bit integer at the specified byte offset from the start of the file.\n * @param offset The offset, in bytes, from the start of the file where to read the data.\n */\n getUint16(offset: bigint): Promise<number>;\n\n /**\n * Gets an unsigned 32-bit integer at the specified byte offset from the start of the file.\n * @param offset The offset, in bytes, from the file of the view where to read the data.\n */\n getUint32(offset: bigint): Promise<number>;\n\n /**\n * Gets an unsigned 32-bit integer at the specified byte offset from the start of the file.\n * @param offset The offset, in byte, from the file of the view where to read the data.\n */\n getBigUint64(offset: bigint): Promise<bigint>;\n\n /**\n * returns an ArrayBuffer whose contents are a copy of this file bytes from startOffset, inclusive, up to endOffset, exclusive.\n * @param startOffset The offset, in bytes, from the start of the file where to start reading the data.\n * @param endOffset The offset, in bytes, from the start of the file where to end reading the data.\n */\n slice(startOffset: bigint, endOffset: bigint): Promise<ArrayBuffer>;\n\n /**\n * the length (in bytes) of the data.\n */\n length: bigint;\n}\n"],"mappings":""}
|
|
@@ -1,40 +0,0 @@
|
|
|
1
|
-
const offsets = {
|
|
2
|
-
COMPRESSED_SIZE_OFFSET: 18n,
|
|
3
|
-
UNCOMPRESSED_SIZE_OFFSET: 22n,
|
|
4
|
-
FILE_NAME_LENGTH_OFFSET: 26n,
|
|
5
|
-
EXTRA_FIELD_LENGTH_OFFSET: 28n,
|
|
6
|
-
FILE_NAME_OFFSET: 30n
|
|
7
|
-
};
|
|
8
|
-
export const signature = Buffer.from([0x50, 0x4b, 0x03, 0x04]);
|
|
9
|
-
export const parseZipLocalFileHeader = async (headerOffset, buffer) => {
|
|
10
|
-
if (Buffer.from(await buffer.slice(headerOffset, headerOffset + 4n)).compare(signature) !== 0) {
|
|
11
|
-
return null;
|
|
12
|
-
}
|
|
13
|
-
const fileNameLength = await buffer.getUint16(headerOffset + offsets.FILE_NAME_LENGTH_OFFSET);
|
|
14
|
-
const fileName = new TextDecoder().decode(await buffer.slice(headerOffset + offsets.FILE_NAME_OFFSET, headerOffset + offsets.FILE_NAME_OFFSET + BigInt(fileNameLength))).split('\\').join('/');
|
|
15
|
-
const extraFieldLength = await buffer.getUint16(headerOffset + offsets.EXTRA_FIELD_LENGTH_OFFSET);
|
|
16
|
-
let fileDataOffset = headerOffset + offsets.FILE_NAME_OFFSET + BigInt(fileNameLength + extraFieldLength);
|
|
17
|
-
let compressedSize = BigInt(await buffer.getUint32(headerOffset + offsets.COMPRESSED_SIZE_OFFSET));
|
|
18
|
-
let uncompressedSize = BigInt(await buffer.getUint32(headerOffset + offsets.UNCOMPRESSED_SIZE_OFFSET));
|
|
19
|
-
const extraOffset = headerOffset + offsets.FILE_NAME_OFFSET + BigInt(fileNameLength);
|
|
20
|
-
let offsetInZip64Data = 4n;
|
|
21
|
-
if (uncompressedSize === BigInt(0xffffffff)) {
|
|
22
|
-
uncompressedSize = await buffer.getBigUint64(extraOffset + offsetInZip64Data);
|
|
23
|
-
offsetInZip64Data += 8n;
|
|
24
|
-
}
|
|
25
|
-
if (compressedSize === BigInt(0xffffffff)) {
|
|
26
|
-
compressedSize = await buffer.getBigUint64(extraOffset + offsetInZip64Data);
|
|
27
|
-
offsetInZip64Data += 8n;
|
|
28
|
-
}
|
|
29
|
-
if (fileDataOffset === BigInt(0xffffffff)) {
|
|
30
|
-
fileDataOffset = await buffer.getBigUint64(extraOffset + offsetInZip64Data);
|
|
31
|
-
}
|
|
32
|
-
return {
|
|
33
|
-
fileNameLength,
|
|
34
|
-
fileName,
|
|
35
|
-
extraFieldLength,
|
|
36
|
-
fileDataOffset,
|
|
37
|
-
compressedSize
|
|
38
|
-
};
|
|
39
|
-
};
|
|
40
|
-
//# sourceMappingURL=local-file-header.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"local-file-header.js","names":["offsets","COMPRESSED_SIZE_OFFSET","UNCOMPRESSED_SIZE_OFFSET","FILE_NAME_LENGTH_OFFSET","EXTRA_FIELD_LENGTH_OFFSET","FILE_NAME_OFFSET","signature","Buffer","from","parseZipLocalFileHeader","headerOffset","buffer","slice","compare","fileNameLength","getUint16","fileName","TextDecoder","decode","BigInt","split","join","extraFieldLength","fileDataOffset","compressedSize","getUint32","uncompressedSize","extraOffset","offsetInZip64Data","getBigUint64"],"sources":["../../../../../src/lib/parsers/parse-zip/local-file-header.ts"],"sourcesContent":["import {FileProvider} from './file-provider';\n\n/**\n * zip local file header info\n * according to https://en.wikipedia.org/wiki/ZIP_(file_format)\n */\nexport type ZipLocalFileHeader = {\n /** File name length */\n fileNameLength: number;\n /** File name */\n fileName: string;\n /** Extra field length */\n extraFieldLength: number;\n /** Offset of the file data */\n fileDataOffset: bigint;\n /** Compressed size */\n compressedSize: bigint;\n};\n\nconst offsets = {\n COMPRESSED_SIZE_OFFSET: 18n,\n UNCOMPRESSED_SIZE_OFFSET: 22n,\n FILE_NAME_LENGTH_OFFSET: 26n,\n EXTRA_FIELD_LENGTH_OFFSET: 28n,\n FILE_NAME_OFFSET: 30n\n};\n\nexport const signature = Buffer.from([0x50, 0x4b, 0x03, 0x04]);\n\n/**\n * Parses local file header of zip file\n * @param headerOffset - offset in the archive where header starts\n * @param buffer - buffer containing whole array\n * @returns Info from the header\n */\nexport const parseZipLocalFileHeader = async (\n headerOffset: bigint,\n buffer: FileProvider\n): Promise<ZipLocalFileHeader | null> => {\n if (Buffer.from(await buffer.slice(headerOffset, headerOffset + 4n)).compare(signature) !== 0) {\n return null;\n }\n\n const fileNameLength = await buffer.getUint16(headerOffset + offsets.FILE_NAME_LENGTH_OFFSET);\n\n const fileName = new TextDecoder()\n .decode(\n await buffer.slice(\n headerOffset + offsets.FILE_NAME_OFFSET,\n headerOffset + offsets.FILE_NAME_OFFSET + BigInt(fileNameLength)\n )\n )\n .split('\\\\')\n .join('/');\n const extraFieldLength = await buffer.getUint16(headerOffset + offsets.EXTRA_FIELD_LENGTH_OFFSET);\n\n let fileDataOffset =\n headerOffset + offsets.FILE_NAME_OFFSET + BigInt(fileNameLength + extraFieldLength);\n\n let compressedSize = BigInt(\n await buffer.getUint32(headerOffset + offsets.COMPRESSED_SIZE_OFFSET)\n ); // add zip 64 logic\n\n let uncompressedSize = BigInt(\n await buffer.getUint32(headerOffset + offsets.UNCOMPRESSED_SIZE_OFFSET)\n ); // add zip 64 logic\n\n const extraOffset = headerOffset + offsets.FILE_NAME_OFFSET + BigInt(fileNameLength);\n\n let offsetInZip64Data = 4n;\n // looking for info that might be also be in zip64 extra field\n if (uncompressedSize === BigInt(0xffffffff)) {\n uncompressedSize = await buffer.getBigUint64(extraOffset + offsetInZip64Data);\n offsetInZip64Data += 8n;\n }\n if (compressedSize === BigInt(0xffffffff)) {\n compressedSize = await buffer.getBigUint64(extraOffset + offsetInZip64Data);\n offsetInZip64Data += 8n;\n }\n if (fileDataOffset === BigInt(0xffffffff)) {\n fileDataOffset = await buffer.getBigUint64(extraOffset + offsetInZip64Data); // setting it to the one from zip64\n }\n\n return {\n fileNameLength,\n fileName,\n extraFieldLength,\n fileDataOffset,\n compressedSize\n };\n};\n"],"mappings":"AAmBA,MAAMA,OAAO,GAAG;EACdC,sBAAsB,EAAE,GAAG;EAC3BC,wBAAwB,EAAE,GAAG;EAC7BC,uBAAuB,EAAE,GAAG;EAC5BC,yBAAyB,EAAE,GAAG;EAC9BC,gBAAgB,EAAE;AACpB,CAAC;AAED,OAAO,MAAMC,SAAS,GAAGC,MAAM,CAACC,IAAI,CAAC,CAAC,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,CAAC,CAAC;AAQ9D,OAAO,MAAMC,uBAAuB,GAAG,MAAAA,CACrCC,YAAoB,EACpBC,MAAoB,KACmB;EACvC,IAAIJ,MAAM,CAACC,IAAI,CAAC,MAAMG,MAAM,CAACC,KAAK,CAACF,YAAY,EAAEA,YAAY,GAAG,EAAE,CAAC,CAAC,CAACG,OAAO,CAACP,SAAS,CAAC,KAAK,CAAC,EAAE;IAC7F,OAAO,IAAI;EACb;EAEA,MAAMQ,cAAc,GAAG,MAAMH,MAAM,CAACI,SAAS,CAACL,YAAY,GAAGV,OAAO,CAACG,uBAAuB,CAAC;EAE7F,MAAMa,QAAQ,GAAG,IAAIC,WAAW,CAAC,CAAC,CAC/BC,MAAM,CACL,MAAMP,MAAM,CAACC,KAAK,CAChBF,YAAY,GAAGV,OAAO,CAACK,gBAAgB,EACvCK,YAAY,GAAGV,OAAO,CAACK,gBAAgB,GAAGc,MAAM,CAACL,cAAc,CACjE,CACF,CAAC,CACAM,KAAK,CAAC,IAAI,CAAC,CACXC,IAAI,CAAC,GAAG,CAAC;EACZ,MAAMC,gBAAgB,GAAG,MAAMX,MAAM,CAACI,SAAS,CAACL,YAAY,GAAGV,OAAO,CAACI,yBAAyB,CAAC;EAEjG,IAAImB,cAAc,GAChBb,YAAY,GAAGV,OAAO,CAACK,gBAAgB,GAAGc,MAAM,CAACL,cAAc,GAAGQ,gBAAgB,CAAC;EAErF,IAAIE,cAAc,GAAGL,MAAM,CACzB,MAAMR,MAAM,CAACc,SAAS,CAACf,YAAY,GAAGV,OAAO,CAACC,sBAAsB,CACtE,CAAC;EAED,IAAIyB,gBAAgB,GAAGP,MAAM,CAC3B,MAAMR,MAAM,CAACc,SAAS,CAACf,YAAY,GAAGV,OAAO,CAACE,wBAAwB,CACxE,CAAC;EAED,MAAMyB,WAAW,GAAGjB,YAAY,GAAGV,OAAO,CAACK,gBAAgB,GAAGc,MAAM,CAACL,cAAc,CAAC;EAEpF,IAAIc,iBAAiB,GAAG,EAAE;EAE1B,IAAIF,gBAAgB,KAAKP,MAAM,CAAC,UAAU,CAAC,EAAE;IAC3CO,gBAAgB,GAAG,MAAMf,MAAM,CAACkB,YAAY,CAACF,WAAW,GAAGC,iBAAiB,CAAC;IAC7EA,iBAAiB,IAAI,EAAE;EACzB;EACA,IAAIJ,cAAc,KAAKL,MAAM,CAAC,UAAU,CAAC,EAAE;IACzCK,cAAc,GAAG,MAAMb,MAAM,CAACkB,YAAY,CAACF,WAAW,GAAGC,iBAAiB,CAAC;IAC3EA,iBAAiB,IAAI,EAAE;EACzB;EACA,IAAIL,cAAc,KAAKJ,MAAM,CAAC,UAAU,CAAC,EAAE;IACzCI,cAAc,GAAG,MAAMZ,MAAM,CAACkB,YAAY,CAACF,WAAW,GAAGC,iBAAiB,CAAC;EAC7E;EAEA,OAAO;IACLd,cAAc;IACdE,QAAQ;IACRM,gBAAgB;IAChBC,cAAc;IACdC;EACF,CAAC;AACH,CAAC"}
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
export const searchFromTheEnd = async (file, target) => {
|
|
2
|
-
const searchWindow = [await file.getUint8(file.length - 1n), await file.getUint8(file.length - 2n), await file.getUint8(file.length - 3n), undefined];
|
|
3
|
-
let targetOffset = 0n;
|
|
4
|
-
for (let i = file.length - 4n; i > -1; i--) {
|
|
5
|
-
searchWindow[3] = searchWindow[2];
|
|
6
|
-
searchWindow[2] = searchWindow[1];
|
|
7
|
-
searchWindow[1] = searchWindow[0];
|
|
8
|
-
searchWindow[0] = await file.getUint8(i);
|
|
9
|
-
if (searchWindow.every((val, index) => val === target[index])) {
|
|
10
|
-
targetOffset = i;
|
|
11
|
-
break;
|
|
12
|
-
}
|
|
13
|
-
}
|
|
14
|
-
return targetOffset;
|
|
15
|
-
};
|
|
16
|
-
//# sourceMappingURL=search-from-the-end.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"search-from-the-end.js","names":["searchFromTheEnd","file","target","searchWindow","getUint8","length","undefined","targetOffset","i","every","val","index"],"sources":["../../../../../src/lib/parsers/parse-zip/search-from-the-end.ts"],"sourcesContent":["import {FileProvider} from 'modules/i3s/src/lib/parsers/parse-zip/file-provider';\n\n/** Description of zip signature type */\nexport type ZipSignature = [number, number, number, number];\n\n/**\n * looking for the last occurrence of the provided\n * @param file\n * @param target\n * @returns\n */\nexport const searchFromTheEnd = async (\n file: FileProvider,\n target: ZipSignature\n): Promise<bigint> => {\n const searchWindow = [\n await file.getUint8(file.length - 1n),\n await file.getUint8(file.length - 2n),\n await file.getUint8(file.length - 3n),\n undefined\n ];\n\n let targetOffset = 0n;\n\n // looking for the last record in the central directory\n for (let i = file.length - 4n; i > -1; i--) {\n searchWindow[3] = searchWindow[2];\n searchWindow[2] = searchWindow[1];\n searchWindow[1] = searchWindow[0];\n searchWindow[0] = await file.getUint8(i);\n if (searchWindow.every((val, index) => val === target[index])) {\n targetOffset = i;\n break;\n }\n }\n\n return targetOffset;\n};\n"],"mappings":"AAWA,OAAO,MAAMA,gBAAgB,GAAG,MAAAA,CAC9BC,IAAkB,EAClBC,MAAoB,KACA;EACpB,MAAMC,YAAY,GAAG,CACnB,MAAMF,IAAI,CAACG,QAAQ,CAACH,IAAI,CAACI,MAAM,GAAG,EAAE,CAAC,EACrC,MAAMJ,IAAI,CAACG,QAAQ,CAACH,IAAI,CAACI,MAAM,GAAG,EAAE,CAAC,EACrC,MAAMJ,IAAI,CAACG,QAAQ,CAACH,IAAI,CAACI,MAAM,GAAG,EAAE,CAAC,EACrCC,SAAS,CACV;EAED,IAAIC,YAAY,GAAG,EAAE;EAGrB,KAAK,IAAIC,CAAC,GAAGP,IAAI,CAACI,MAAM,GAAG,EAAE,EAAEG,CAAC,GAAG,CAAC,CAAC,EAAEA,CAAC,EAAE,EAAE;IAC1CL,YAAY,CAAC,CAAC,CAAC,GAAGA,YAAY,CAAC,CAAC,CAAC;IACjCA,YAAY,CAAC,CAAC,CAAC,GAAGA,YAAY,CAAC,CAAC,CAAC;IACjCA,YAAY,CAAC,CAAC,CAAC,GAAGA,YAAY,CAAC,CAAC,CAAC;IACjCA,YAAY,CAAC,CAAC,CAAC,GAAG,MAAMF,IAAI,CAACG,QAAQ,CAACI,CAAC,CAAC;IACxC,IAAIL,YAAY,CAACM,KAAK,CAAC,CAACC,GAAG,EAAEC,KAAK,KAAKD,GAAG,KAAKR,MAAM,CAACS,KAAK,CAAC,CAAC,EAAE;MAC7DJ,YAAY,GAAGC,CAAC;MAChB;IACF;EACF;EAEA,OAAOD,YAAY;AACrB,CAAC"}
|
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
import { FileProvider } from './file-provider';
|
|
2
|
-
import { ZipSignature } from './search-from-the-end';
|
|
3
|
-
/**
|
|
4
|
-
* zip central directory file header info
|
|
5
|
-
* according to https://en.wikipedia.org/wiki/ZIP_(file_format)
|
|
6
|
-
*/
|
|
7
|
-
export type ZipCDFileHeader = {
|
|
8
|
-
/** Compressed size */
|
|
9
|
-
compressedSize: bigint;
|
|
10
|
-
/** Uncompressed size */
|
|
11
|
-
uncompressedSize: bigint;
|
|
12
|
-
/** Extra field size */
|
|
13
|
-
extraFieldLength: number;
|
|
14
|
-
/** File name length */
|
|
15
|
-
fileNameLength: number;
|
|
16
|
-
/** File name */
|
|
17
|
-
fileName: string;
|
|
18
|
-
/** Extra field offset */
|
|
19
|
-
extraOffset: bigint;
|
|
20
|
-
/** Relative offset of local file header */
|
|
21
|
-
localHeaderOffset: bigint;
|
|
22
|
-
};
|
|
23
|
-
export declare const signature: ZipSignature;
|
|
24
|
-
/**
|
|
25
|
-
* Parses central directory file header of zip file
|
|
26
|
-
* @param headerOffset - offset in the archive where header starts
|
|
27
|
-
* @param buffer - buffer containing whole array
|
|
28
|
-
* @returns Info from the header
|
|
29
|
-
*/
|
|
30
|
-
export declare const parseZipCDFileHeader: (headerOffset: bigint, buffer: FileProvider) => Promise<ZipCDFileHeader | null>;
|
|
31
|
-
//# sourceMappingURL=cd-file-header.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"cd-file-header.d.ts","sourceRoot":"","sources":["../../../../src/lib/parsers/parse-zip/cd-file-header.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,YAAY,EAAC,MAAM,iBAAiB,CAAC;AAC7C,OAAO,EAAC,YAAY,EAAC,MAAM,uBAAuB,CAAC;AAEnD;;;GAGG;AACH,MAAM,MAAM,eAAe,GAAG;IAC5B,sBAAsB;IACtB,cAAc,EAAE,MAAM,CAAC;IACvB,wBAAwB;IACxB,gBAAgB,EAAE,MAAM,CAAC;IACzB,uBAAuB;IACvB,gBAAgB,EAAE,MAAM,CAAC;IACzB,uBAAuB;IACvB,cAAc,EAAE,MAAM,CAAC;IACvB,gBAAgB;IAChB,QAAQ,EAAE,MAAM,CAAC;IACjB,yBAAyB;IACzB,WAAW,EAAE,MAAM,CAAC;IACpB,2CAA2C;IAC3C,iBAAiB,EAAE,MAAM,CAAC;CAC3B,CAAC;AAWF,eAAO,MAAM,SAAS,EAAE,YAAuC,CAAC;AAEhE;;;;;GAKG;AACH,eAAO,MAAM,oBAAoB,iBACjB,MAAM,UACZ,YAAY,KACnB,QAAQ,eAAe,GAAG,IAAI,CA6DhC,CAAC"}
|
|
@@ -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,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;
|