@loaders.gl/zip 4.0.0-alpha.9 → 4.0.0-beta.2
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 +5143 -36
- package/dist/es5/filesystems/zip-filesystem.js +372 -0
- package/dist/es5/filesystems/zip-filesystem.js.map +1 -0
- package/dist/es5/hash-file-utility.js +130 -0
- package/dist/es5/hash-file-utility.js.map +1 -0
- package/dist/es5/index.js +80 -3
- package/dist/es5/index.js.map +1 -1
- package/dist/es5/parse-zip/cd-file-header.js +163 -0
- package/dist/es5/parse-zip/cd-file-header.js.map +1 -0
- package/dist/es5/parse-zip/end-of-central-directory.js +98 -0
- package/dist/es5/parse-zip/end-of-central-directory.js.map +1 -0
- package/dist/es5/parse-zip/local-file-header.js +117 -0
- package/dist/es5/parse-zip/local-file-header.js.map +1 -0
- package/dist/es5/parse-zip/search-from-the-end.js +69 -0
- package/dist/es5/parse-zip/search-from-the-end.js.map +1 -0
- package/dist/es5/tar-builder.js +8 -8
- package/dist/es5/tar-builder.js.map +1 -1
- package/dist/es5/zip-loader.js +2 -4
- package/dist/es5/zip-loader.js.map +1 -1
- package/dist/es5/zip-writer.js +19 -10
- package/dist/es5/zip-writer.js.map +1 -1
- package/dist/esm/filesystems/zip-filesystem.js +99 -0
- package/dist/esm/filesystems/zip-filesystem.js.map +1 -0
- package/dist/esm/hash-file-utility.js +55 -0
- package/dist/esm/hash-file-utility.js.map +1 -0
- package/dist/esm/index.js +7 -1
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/parse-zip/cd-file-header.js +54 -0
- package/dist/esm/parse-zip/cd-file-header.js.map +1 -0
- package/dist/esm/parse-zip/end-of-central-directory.js +31 -0
- package/dist/esm/parse-zip/end-of-central-directory.js.map +1 -0
- package/dist/esm/parse-zip/local-file-header.js +41 -0
- package/dist/esm/parse-zip/local-file-header.js.map +1 -0
- package/dist/esm/parse-zip/search-from-the-end.js +16 -0
- package/dist/esm/parse-zip/search-from-the-end.js.map +1 -0
- package/dist/esm/tar-builder.js +2 -2
- package/dist/esm/tar-builder.js.map +1 -1
- package/dist/esm/zip-loader.js +1 -2
- package/dist/esm/zip-loader.js.map +1 -1
- package/dist/esm/zip-writer.js +8 -5
- package/dist/esm/zip-writer.js.map +1 -1
- package/dist/filesystems/zip-filesystem.d.ts +45 -0
- package/dist/filesystems/zip-filesystem.d.ts.map +1 -0
- package/dist/hash-file-utility.d.ts +35 -0
- package/dist/hash-file-utility.d.ts.map +1 -0
- package/dist/index.d.ts +8 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/parse-zip/cd-file-header.d.ts +36 -0
- package/dist/parse-zip/cd-file-header.d.ts.map +1 -0
- package/dist/parse-zip/end-of-central-directory.d.ts +18 -0
- package/dist/parse-zip/end-of-central-directory.d.ts.map +1 -0
- package/dist/parse-zip/local-file-header.d.ts +28 -0
- package/dist/parse-zip/local-file-header.d.ts.map +1 -0
- package/dist/parse-zip/search-from-the-end.d.ts +11 -0
- package/dist/parse-zip/search-from-the-end.d.ts.map +1 -0
- package/dist/tar-builder.d.ts +2 -2
- package/dist/tar-builder.d.ts.map +1 -1
- package/dist/zip-loader.d.ts +0 -1
- package/dist/zip-loader.d.ts.map +1 -1
- package/dist/zip-writer.d.ts +12 -2
- package/dist/zip-writer.d.ts.map +1 -1
- package/package.json +6 -3
- package/src/filesystems/zip-filesystem.ts +142 -0
- package/src/hash-file-utility.ts +101 -0
- package/src/index.ts +20 -1
- package/src/parse-zip/cd-file-header.ts +114 -0
- package/src/parse-zip/end-of-central-directory.ts +71 -0
- package/src/parse-zip/local-file-header.ts +95 -0
- package/src/parse-zip/search-from-the-end.ts +38 -0
- package/src/tar-builder.ts +2 -2
- package/src/zip-loader.ts +2 -3
- package/src/zip-writer.ts +23 -10
- package/dist/bundle.js +0 -5
- package/dist/index.js +0 -12
- package/dist/lib/tar/header.js +0 -99
- package/dist/lib/tar/tar.js +0 -131
- package/dist/lib/tar/types.js +0 -2
- package/dist/lib/tar/utils.js +0 -54
- package/dist/tar-builder.js +0 -38
- package/dist/zip-loader.js +0 -61
- package/dist/zip-writer.js +0 -37
package/dist/esm/zip-writer.js
CHANGED
|
@@ -11,17 +11,20 @@ async function encodeZipAsync(fileMap) {
|
|
|
11
11
|
const jsZip = new JSZip();
|
|
12
12
|
for (const subFileName in fileMap) {
|
|
13
13
|
const subFileData = fileMap[subFileName];
|
|
14
|
-
jsZip.file(subFileName, subFileData, options);
|
|
14
|
+
jsZip.file(subFileName, subFileData, (options === null || options === void 0 ? void 0 : options.jszip) || {});
|
|
15
15
|
}
|
|
16
|
-
|
|
16
|
+
const jszipOptions = {
|
|
17
|
+
...(options === null || options === void 0 ? void 0 : options.jszip),
|
|
17
18
|
type: 'arraybuffer'
|
|
18
|
-
}
|
|
19
|
+
};
|
|
19
20
|
const {
|
|
20
21
|
onUpdate = () => {}
|
|
21
22
|
} = options;
|
|
22
|
-
|
|
23
|
+
try {
|
|
24
|
+
return await jsZip.generateAsync(jszipOptions, onUpdate);
|
|
25
|
+
} catch (error) {
|
|
23
26
|
options.log.error("Unable to write zip archive: ".concat(error));
|
|
24
27
|
throw error;
|
|
25
|
-
}
|
|
28
|
+
}
|
|
26
29
|
}
|
|
27
30
|
//# sourceMappingURL=zip-writer.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"zip-writer.js","names":["JSZip","ZipWriter","name","extensions","category","mimeTypes","encode","encodeZipAsync","fileMap","options","arguments","length","undefined","jsZip","subFileName","subFileData","file","
|
|
1
|
+
{"version":3,"file":"zip-writer.js","names":["JSZip","ZipWriter","name","extensions","category","mimeTypes","encode","encodeZipAsync","fileMap","options","arguments","length","undefined","jsZip","subFileName","subFileData","file","jszip","jszipOptions","type","onUpdate","generateAsync","error","log","concat"],"sources":["../../src/zip-writer.ts"],"sourcesContent":["// loaders.gl, MIT license\n\nimport type {Writer, WriterOptions} from '@loaders.gl/loader-utils';\nimport JSZip, {JSZipGeneratorOptions} from 'jszip';\n\nexport type ZipWriterOptions = WriterOptions & {\n zip?: {\n onUpdate?: (metadata: {percent: number}) => void;\n };\n /** Passthrough options to jszip */\n jszip?: JSZipGeneratorOptions;\n};\n\n/**\n * Zip exporter\n */\nexport const ZipWriter: Writer<FileReaderEventMap, never, ZipWriterOptions> = {\n name: 'Zip Archive',\n extensions: ['zip'],\n category: 'archive',\n mimeTypes: ['application/zip'],\n // @ts-ignore\n encode: encodeZipAsync\n};\n\nasync function encodeZipAsync(\n fileMap: Record<string, ArrayBuffer>,\n options: ZipWriterOptions = {}\n) {\n const jsZip = new JSZip();\n // add files to the zip\n for (const subFileName in fileMap) {\n const subFileData = fileMap[subFileName];\n\n // jszip supports both arraybuffer and string data (the main loaders.gl types)\n // https://stuk.github.io/jszip/documentation/api_zipobject/async.html\n jsZip.file(subFileName, subFileData, options?.jszip || {});\n }\n\n // always generate the full zip as an arraybuffer\n const jszipOptions: JSZipGeneratorOptions = {...options?.jszip, type: 'arraybuffer'};\n const {onUpdate = () => {}} = options;\n\n try {\n return await jsZip.generateAsync(jszipOptions, onUpdate);\n } catch (error) {\n options.log.error(`Unable to write zip archive: ${error}`);\n throw error;\n }\n}\n"],"mappings":"AAGA,OAAOA,KAAK,MAA+B,OAAO;AAalD,OAAO,MAAMC,SAA8D,GAAG;EAC5EC,IAAI,EAAE,aAAa;EACnBC,UAAU,EAAE,CAAC,KAAK,CAAC;EACnBC,QAAQ,EAAE,SAAS;EACnBC,SAAS,EAAE,CAAC,iBAAiB,CAAC;EAE9BC,MAAM,EAAEC;AACV,CAAC;AAED,eAAeA,cAAcA,CAC3BC,OAAoC,EAEpC;EAAA,IADAC,OAAyB,GAAAC,SAAA,CAAAC,MAAA,QAAAD,SAAA,QAAAE,SAAA,GAAAF,SAAA,MAAG,CAAC,CAAC;EAE9B,MAAMG,KAAK,GAAG,IAAIb,KAAK,CAAC,CAAC;EAEzB,KAAK,MAAMc,WAAW,IAAIN,OAAO,EAAE;IACjC,MAAMO,WAAW,GAAGP,OAAO,CAACM,WAAW,CAAC;IAIxCD,KAAK,CAACG,IAAI,CAACF,WAAW,EAAEC,WAAW,EAAE,CAAAN,OAAO,aAAPA,OAAO,uBAAPA,OAAO,CAAEQ,KAAK,KAAI,CAAC,CAAC,CAAC;EAC5D;EAGA,MAAMC,YAAmC,GAAG;IAAC,IAAGT,OAAO,aAAPA,OAAO,uBAAPA,OAAO,CAAEQ,KAAK;IAAEE,IAAI,EAAE;EAAa,CAAC;EACpF,MAAM;IAACC,QAAQ,GAAGA,CAAA,KAAM,CAAC;EAAC,CAAC,GAAGX,OAAO;EAErC,IAAI;IACF,OAAO,MAAMI,KAAK,CAACQ,aAAa,CAACH,YAAY,EAAEE,QAAQ,CAAC;EAC1D,CAAC,CAAC,OAAOE,KAAK,EAAE;IACdb,OAAO,CAACc,GAAG,CAACD,KAAK,iCAAAE,MAAA,CAAiCF,KAAK,CAAE,CAAC;IAC1D,MAAMA,KAAK;EACb;AACF"}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { FileSystem } from '@loaders.gl/loader-utils';
|
|
2
|
+
import { FileProvider } from '@loaders.gl/loader-utils';
|
|
3
|
+
import { ZipCDFileHeader } from '../parse-zip/cd-file-header';
|
|
4
|
+
/**
|
|
5
|
+
* FileSystem adapter for a ZIP file
|
|
6
|
+
* Holds FileProvider object that provides random access to archived files
|
|
7
|
+
*/
|
|
8
|
+
export declare class ZipFileSystem implements FileSystem {
|
|
9
|
+
/** FileProvider instance promise */
|
|
10
|
+
protected fileProvider: Promise<FileProvider | null>;
|
|
11
|
+
fileName?: string;
|
|
12
|
+
/**
|
|
13
|
+
* Constructor
|
|
14
|
+
* @param file - instance of FileProvider or file path string
|
|
15
|
+
*/
|
|
16
|
+
constructor(file: FileProvider | string);
|
|
17
|
+
/** Clean up resources */
|
|
18
|
+
destroy(): Promise<void>;
|
|
19
|
+
/**
|
|
20
|
+
* Get file names list from zip archive
|
|
21
|
+
* @returns array of file names
|
|
22
|
+
*/
|
|
23
|
+
readdir(): Promise<string[]>;
|
|
24
|
+
/**
|
|
25
|
+
* Get file metadata
|
|
26
|
+
* @param filename - name of a file
|
|
27
|
+
* @returns central directory data
|
|
28
|
+
*/
|
|
29
|
+
stat(filename: string): Promise<ZipCDFileHeader & {
|
|
30
|
+
size: number;
|
|
31
|
+
}>;
|
|
32
|
+
/**
|
|
33
|
+
* Implementation of fetch against this file system
|
|
34
|
+
* @param filename - name of a file
|
|
35
|
+
* @returns - Response with file data
|
|
36
|
+
*/
|
|
37
|
+
fetch(filename: string): Promise<Response>;
|
|
38
|
+
/**
|
|
39
|
+
* Get central directory file header
|
|
40
|
+
* @param filename - name of a file
|
|
41
|
+
* @returns central directory file header
|
|
42
|
+
*/
|
|
43
|
+
private getCDFileHeader;
|
|
44
|
+
}
|
|
45
|
+
//# sourceMappingURL=zip-filesystem.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"zip-filesystem.d.ts","sourceRoot":"","sources":["../../src/filesystems/zip-filesystem.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,UAAU,EAAY,MAAM,0BAA0B,CAAC;AAC/D,OAAO,EAAC,YAAY,EAAiB,MAAM,0BAA0B,CAAC;AAEtE,OAAO,EAAC,eAAe,EAA2B,MAAM,6BAA6B,CAAC;AAiBtF;;;GAGG;AACH,qBAAa,aAAc,YAAW,UAAU;IAC9C,oCAAoC;IACpC,SAAS,CAAC,YAAY,EAAE,OAAO,CAAC,YAAY,GAAG,IAAI,CAAC,CAAyB;IACtE,QAAQ,CAAC,EAAE,MAAM,CAAC;IAEzB;;;OAGG;gBACS,IAAI,EAAE,YAAY,GAAG,MAAM;IAcvC,yBAAyB;IACnB,OAAO;IAOb;;;OAGG;IACG,OAAO,IAAI,OAAO,CAAC,MAAM,EAAE,CAAC;IAalC;;;;OAIG;IACG,IAAI,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,eAAe,GAAG;QAAC,IAAI,EAAE,MAAM,CAAA;KAAC,CAAC;IAKvE;;;;OAIG;IACG,KAAK,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,QAAQ,CAAC;IA+BhD;;;;OAIG;YACW,eAAe;CAkB9B"}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
import { FileProvider } from '@loaders.gl/loader-utils';
|
|
3
|
+
/** Element of hash array */
|
|
4
|
+
export type HashElement = {
|
|
5
|
+
/** File name hash */
|
|
6
|
+
hash: Buffer;
|
|
7
|
+
/** File offset in the archive */
|
|
8
|
+
offset: bigint;
|
|
9
|
+
};
|
|
10
|
+
/**
|
|
11
|
+
* Comparing md5 hashes according to https://github.com/Esri/i3s-spec/blob/master/docs/2.0/slpk_hashtable.pcsl.md step 5
|
|
12
|
+
* @param hash1 hash to compare
|
|
13
|
+
* @param hash2 hash to compare
|
|
14
|
+
* @returns -1 if hash1 < hash2, 0 of hash1 === hash2, 1 if hash1 > hash2
|
|
15
|
+
*/
|
|
16
|
+
export declare const compareHashes: (hash1: Buffer, hash2: Buffer) => number;
|
|
17
|
+
/**
|
|
18
|
+
* Reads hash file from buffer and returns it in ready-to-use form
|
|
19
|
+
* @param hashFile - bufer containing hash file
|
|
20
|
+
* @returns Array containing file info
|
|
21
|
+
*/
|
|
22
|
+
export declare const parseHashFile: (hashFile: ArrayBuffer) => HashElement[];
|
|
23
|
+
/**
|
|
24
|
+
* Binary search in the hash info
|
|
25
|
+
* @param hashToSearch hash that we need to find
|
|
26
|
+
* @returns required hash element or undefined if not found
|
|
27
|
+
*/
|
|
28
|
+
export declare const findBin: (hashToSearch: Buffer, hashArray: HashElement[]) => HashElement | undefined;
|
|
29
|
+
/**
|
|
30
|
+
* generates hash info from central directory
|
|
31
|
+
* @param fileProvider - provider of the archive
|
|
32
|
+
* @returns ready to use hash info
|
|
33
|
+
*/
|
|
34
|
+
export declare const generateHashInfo: (fileProvider: FileProvider) => Promise<HashElement[]>;
|
|
35
|
+
//# sourceMappingURL=hash-file-utility.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"hash-file-utility.d.ts","sourceRoot":"","sources":["../src/hash-file-utility.ts"],"names":[],"mappings":";AACA,OAAO,EAAC,YAAY,EAAC,MAAM,0BAA0B,CAAC;AAGtD,4BAA4B;AAC5B,MAAM,MAAM,WAAW,GAAG;IACxB,qBAAqB;IACrB,IAAI,EAAE,MAAM,CAAC;IACb,iCAAiC;IACjC,MAAM,EAAE,MAAM,CAAC;CAChB,CAAC;AAEF;;;;;GAKG;AACH,eAAO,MAAM,aAAa,UAAW,MAAM,SAAS,MAAM,KAAG,MAY5D,CAAC;AAEF;;;;GAIG;AACH,eAAO,MAAM,aAAa,aAAc,WAAW,KAAG,WAAW,EAmBhE,CAAC;AAEF;;;;GAIG;AACH,eAAO,MAAM,OAAO,iBACJ,MAAM,aACT,WAAW,EAAE,KACvB,WAAW,GAAG,SAgBhB,CAAC;AAEF;;;;GAIG;AACH,eAAO,MAAM,gBAAgB,iBAAwB,YAAY,KAAG,QAAQ,WAAW,EAAE,CAWxF,CAAC"}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,11 @@
|
|
|
1
1
|
export { ZipLoader } from './zip-loader';
|
|
2
2
|
export { ZipWriter } from './zip-writer';
|
|
3
|
-
export {
|
|
3
|
+
export { TarBuilder } from './tar-builder';
|
|
4
|
+
export { parseZipCDFileHeader, zipCDFileHeaderGenerator, signature as cdSignature } from './parse-zip/cd-file-header';
|
|
5
|
+
export { parseZipLocalFileHeader, signature as localHeaderSignature } from './parse-zip/local-file-header';
|
|
6
|
+
export { parseEoCDRecord } from './parse-zip/end-of-central-directory';
|
|
7
|
+
export { searchFromTheEnd } from './parse-zip/search-from-the-end';
|
|
8
|
+
export type { HashElement } from './hash-file-utility';
|
|
9
|
+
export { compareHashes, parseHashFile, findBin, generateHashInfo } from './hash-file-utility';
|
|
10
|
+
export { ZipFileSystem } from './filesystems/zip-filesystem';
|
|
4
11
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAEA,OAAO,EAAC,SAAS,EAAC,MAAM,cAAc,CAAC;AACvC,OAAO,EAAC,SAAS,EAAC,MAAM,cAAc,CAAC;AACvC,OAAO,EAAC,UAAU,EAAC,MAAM,eAAe,CAAC;AAEzC,OAAO,EACL,oBAAoB,EACpB,wBAAwB,EACxB,SAAS,IAAI,WAAW,EACzB,MAAM,4BAA4B,CAAC;AACpC,OAAO,EACL,uBAAuB,EACvB,SAAS,IAAI,oBAAoB,EAClC,MAAM,+BAA+B,CAAC;AACvC,OAAO,EAAC,eAAe,EAAC,MAAM,sCAAsC,CAAC;AACrE,OAAO,EAAC,gBAAgB,EAAC,MAAM,iCAAiC,CAAC;AAEjE,YAAY,EAAC,WAAW,EAAC,MAAM,qBAAqB,CAAC;AACrD,OAAO,EAAC,aAAa,EAAE,aAAa,EAAE,OAAO,EAAE,gBAAgB,EAAC,MAAM,qBAAqB,CAAC;AAE5F,OAAO,EAAC,aAAa,EAAC,MAAM,8BAA8B,CAAC"}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { FileProvider } from '@loaders.gl/loader-utils';
|
|
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
|
+
/**
|
|
32
|
+
* Create iterator over files of zip archive
|
|
33
|
+
* @param fileProvider - file provider that provider random access to the file
|
|
34
|
+
*/
|
|
35
|
+
export declare function zipCDFileHeaderGenerator(fileProvider: FileProvider): AsyncGenerator<ZipCDFileHeader, void, unknown>;
|
|
36
|
+
//# sourceMappingURL=cd-file-header.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cd-file-header.d.ts","sourceRoot":"","sources":["../../src/parse-zip/cd-file-header.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,YAAY,EAAC,MAAM,0BAA0B,CAAC;AAEtD,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;AAUF,eAAO,MAAM,SAAS,EAAE,YAAuC,CAAC;AAEhE;;;;;GAKG;AACH,eAAO,MAAM,oBAAoB,iBACjB,MAAM,UACZ,YAAY,KACnB,QAAQ,eAAe,GAAG,IAAI,CAqDhC,CAAC;AAEF;;;GAGG;AACH,wBAAuB,wBAAwB,CAAC,YAAY,EAAE,YAAY,kDAUzE"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { FileProvider } from '@loaders.gl/loader-utils';
|
|
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
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"end-of-central-directory.d.ts","sourceRoot":"","sources":["../../src/parse-zip/end-of-central-directory.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,YAAY,EAAC,MAAM,0BAA0B,CAAC;AAGtD;;;GAGG;AACH,MAAM,MAAM,aAAa,GAAG;IAC1B,2CAA2C;IAC3C,aAAa,EAAE,MAAM,CAAC;IACtB,2CAA2C;IAC3C,eAAe,EAAE,MAAM,CAAC;CACzB,CAAC;AAaF;;;;GAIG;AACH,eAAO,MAAM,eAAe,iBAAwB,YAAY,KAAG,QAAQ,aAAa,CAwCvF,CAAC"}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { FileProvider } from '@loaders.gl/loader-utils';
|
|
2
|
+
/**
|
|
3
|
+
* zip local file header info
|
|
4
|
+
* according to https://en.wikipedia.org/wiki/ZIP_(file_format)
|
|
5
|
+
*/
|
|
6
|
+
export type ZipLocalFileHeader = {
|
|
7
|
+
/** File name length */
|
|
8
|
+
fileNameLength: number;
|
|
9
|
+
/** File name */
|
|
10
|
+
fileName: string;
|
|
11
|
+
/** Extra field length */
|
|
12
|
+
extraFieldLength: number;
|
|
13
|
+
/** Offset of the file data */
|
|
14
|
+
fileDataOffset: bigint;
|
|
15
|
+
/** Compressed size */
|
|
16
|
+
compressedSize: bigint;
|
|
17
|
+
/** Compression method */
|
|
18
|
+
compressionMethod: number;
|
|
19
|
+
};
|
|
20
|
+
export declare const signature: number[];
|
|
21
|
+
/**
|
|
22
|
+
* Parses local file header of zip file
|
|
23
|
+
* @param headerOffset - offset in the archive where header starts
|
|
24
|
+
* @param buffer - buffer containing whole array
|
|
25
|
+
* @returns Info from the header
|
|
26
|
+
*/
|
|
27
|
+
export declare const parseZipLocalFileHeader: (headerOffset: bigint, buffer: FileProvider) => Promise<ZipLocalFileHeader | null>;
|
|
28
|
+
//# sourceMappingURL=local-file-header.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"local-file-header.d.ts","sourceRoot":"","sources":["../../src/parse-zip/local-file-header.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,YAAY,EAAC,MAAM,0BAA0B,CAAC;AAEtD;;;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;IACvB,yBAAyB;IACzB,iBAAiB,EAAE,MAAM,CAAC;CAC3B,CAAC;AAUF,eAAO,MAAM,SAAS,UAA2B,CAAC;AAElD;;;;;GAKG;AACH,eAAO,MAAM,uBAAuB,iBACpB,MAAM,UACZ,YAAY,KACnB,QAAQ,kBAAkB,GAAG,IAAI,CAsDnC,CAAC"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { FileProvider } from '@loaders.gl/loader-utils';
|
|
2
|
+
/** Description of zip signature type */
|
|
3
|
+
export type ZipSignature = [number, number, number, number];
|
|
4
|
+
/**
|
|
5
|
+
* looking for the last occurrence of the provided
|
|
6
|
+
* @param file
|
|
7
|
+
* @param target
|
|
8
|
+
* @returns
|
|
9
|
+
*/
|
|
10
|
+
export declare const searchFromTheEnd: (file: FileProvider, target: ZipSignature) => Promise<bigint>;
|
|
11
|
+
//# sourceMappingURL=search-from-the-end.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"search-from-the-end.d.ts","sourceRoot":"","sources":["../../src/parse-zip/search-from-the-end.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,YAAY,EAAC,MAAM,0BAA0B,CAAC;AAEtD,wCAAwC;AACxC,MAAM,MAAM,YAAY,GAAG,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,CAAC,CAAC;AAE5D;;;;;GAKG;AACH,eAAO,MAAM,gBAAgB,SACrB,YAAY,2BAEjB,QAAQ,MAAM,CAuBhB,CAAC"}
|
package/dist/tar-builder.d.ts
CHANGED
|
@@ -5,13 +5,13 @@ type TarBuilderOptions = {
|
|
|
5
5
|
/**
|
|
6
6
|
* Build a tar file by adding files
|
|
7
7
|
*/
|
|
8
|
-
export
|
|
8
|
+
export declare class TarBuilder {
|
|
9
9
|
static get properties(): {
|
|
10
10
|
id: string;
|
|
11
11
|
name: string;
|
|
12
12
|
extensions: string[];
|
|
13
13
|
mimeTypes: string[];
|
|
14
|
-
builder: typeof
|
|
14
|
+
builder: typeof TarBuilder;
|
|
15
15
|
options: {
|
|
16
16
|
recordsPerBlock: number;
|
|
17
17
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"tar-builder.d.ts","sourceRoot":"","sources":["../src/tar-builder.ts"],"names":[],"mappings":"AAAA,OAAO,GAAG,MAAM,eAAe,CAAC;AAMhC,KAAK,iBAAiB,GAAG;IACvB,eAAe,CAAC,EAAE,MAAM,CAAC;CAC1B,CAAC;AAEF;;GAEG;AACH,
|
|
1
|
+
{"version":3,"file":"tar-builder.d.ts","sourceRoot":"","sources":["../src/tar-builder.ts"],"names":[],"mappings":"AAAA,OAAO,GAAG,MAAM,eAAe,CAAC;AAMhC,KAAK,iBAAiB,GAAG;IACvB,eAAe,CAAC,EAAE,MAAM,CAAC;CAC1B,CAAC;AAEF;;GAEG;AACH,qBAAa,UAAU;IACrB,MAAM,KAAK,UAAU;;;;;;;;;MASpB;IAED,OAAO,EAAE,iBAAiB,CAAC;IAC3B,IAAI,EAAE,GAAG,CAAC;IACV,KAAK,EAAE,MAAM,CAAK;gBAEN,OAAO,CAAC,EAAE,OAAO,CAAC,iBAAiB,CAAC;IAIhD,kCAAkC;IAClC,OAAO,CAAC,QAAQ,EAAE,MAAM,EAAE,MAAM,EAAE,WAAW;IAKvC,KAAK,IAAI,OAAO,CAAC,WAAW,CAAC;CAGpC"}
|
package/dist/zip-loader.d.ts
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import type { LoaderWithParser, LoaderOptions } from '@loaders.gl/loader-utils';
|
|
2
2
|
type FileMap = Record<string, ArrayBuffer>;
|
|
3
3
|
export declare const ZipLoader: LoaderWithParser<FileMap, never, LoaderOptions>;
|
|
4
|
-
export declare const _typecheckZipLoader: LoaderWithParser;
|
|
5
4
|
export {};
|
|
6
5
|
//# sourceMappingURL=zip-loader.d.ts.map
|
package/dist/zip-loader.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"zip-loader.d.ts","sourceRoot":"","sources":["../src/zip-loader.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"zip-loader.d.ts","sourceRoot":"","sources":["../src/zip-loader.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAC,gBAAgB,EAAE,aAAa,EAAC,MAAM,0BAA0B,CAAC;AAO9E,KAAK,OAAO,GAAG,MAAM,CAAC,MAAM,EAAE,WAAW,CAAC,CAAC;AAE3C,eAAO,MAAM,SAAS,EAAE,gBAAgB,CAAC,OAAO,EAAE,KAAK,EAAE,aAAa,CAWrE,CAAC"}
|
package/dist/zip-writer.d.ts
CHANGED
|
@@ -1,6 +1,16 @@
|
|
|
1
|
-
import type { Writer } from '@loaders.gl/loader-utils';
|
|
1
|
+
import type { Writer, WriterOptions } from '@loaders.gl/loader-utils';
|
|
2
|
+
import { JSZipGeneratorOptions } from 'jszip';
|
|
3
|
+
export type ZipWriterOptions = WriterOptions & {
|
|
4
|
+
zip?: {
|
|
5
|
+
onUpdate?: (metadata: {
|
|
6
|
+
percent: number;
|
|
7
|
+
}) => void;
|
|
8
|
+
};
|
|
9
|
+
/** Passthrough options to jszip */
|
|
10
|
+
jszip?: JSZipGeneratorOptions;
|
|
11
|
+
};
|
|
2
12
|
/**
|
|
3
13
|
* Zip exporter
|
|
4
14
|
*/
|
|
5
|
-
export declare const ZipWriter: Writer
|
|
15
|
+
export declare const ZipWriter: Writer<FileReaderEventMap, never, ZipWriterOptions>;
|
|
6
16
|
//# sourceMappingURL=zip-writer.d.ts.map
|
package/dist/zip-writer.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"zip-writer.d.ts","sourceRoot":"","sources":["../src/zip-writer.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"zip-writer.d.ts","sourceRoot":"","sources":["../src/zip-writer.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAC,MAAM,EAAE,aAAa,EAAC,MAAM,0BAA0B,CAAC;AACpE,OAAc,EAAC,qBAAqB,EAAC,MAAM,OAAO,CAAC;AAEnD,MAAM,MAAM,gBAAgB,GAAG,aAAa,GAAG;IAC7C,GAAG,CAAC,EAAE;QACJ,QAAQ,CAAC,EAAE,CAAC,QAAQ,EAAE;YAAC,OAAO,EAAE,MAAM,CAAA;SAAC,KAAK,IAAI,CAAC;KAClD,CAAC;IACF,mCAAmC;IACnC,KAAK,CAAC,EAAE,qBAAqB,CAAC;CAC/B,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,SAAS,EAAE,MAAM,CAAC,kBAAkB,EAAE,KAAK,EAAE,gBAAgB,CAOzE,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@loaders.gl/zip",
|
|
3
|
-
"version": "4.0.0-
|
|
3
|
+
"version": "4.0.0-beta.2",
|
|
4
4
|
"description": "Zip Archive Loader",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"publishConfig": {
|
|
@@ -30,7 +30,10 @@
|
|
|
30
30
|
"build-bundle": "esbuild src/bundle.ts --bundle --outfile=dist/dist.min.js"
|
|
31
31
|
},
|
|
32
32
|
"dependencies": {
|
|
33
|
-
"
|
|
33
|
+
"@loaders.gl/compression": "4.0.0-beta.2",
|
|
34
|
+
"@loaders.gl/loader-utils": "4.0.0-beta.2",
|
|
35
|
+
"jszip": "^3.1.5",
|
|
36
|
+
"md5": "^2.3.0"
|
|
34
37
|
},
|
|
35
|
-
"gitHead": "
|
|
38
|
+
"gitHead": "79c2033f755e88e11bc30a04428e3666b177b8fc"
|
|
36
39
|
}
|
|
@@ -0,0 +1,142 @@
|
|
|
1
|
+
import {FileSystem, isBrowser} from '@loaders.gl/loader-utils';
|
|
2
|
+
import {FileProvider, isFileProvider} from '@loaders.gl/loader-utils';
|
|
3
|
+
import {FileHandleFile} from '@loaders.gl/loader-utils';
|
|
4
|
+
import {ZipCDFileHeader, zipCDFileHeaderGenerator} from '../parse-zip/cd-file-header';
|
|
5
|
+
import {parseZipLocalFileHeader} from '../parse-zip/local-file-header';
|
|
6
|
+
import {DeflateCompression} from '@loaders.gl/compression';
|
|
7
|
+
|
|
8
|
+
type CompressionHandler = (compressedFile: ArrayBuffer) => Promise<ArrayBuffer>;
|
|
9
|
+
/** Handling different compression types in zip */
|
|
10
|
+
const COMPRESSION_METHODS: {[key: number]: CompressionHandler} = {
|
|
11
|
+
/** No compression */
|
|
12
|
+
0: async (compressedFile) => compressedFile,
|
|
13
|
+
/** Deflation */
|
|
14
|
+
8: async (compressedFile) => {
|
|
15
|
+
const compression = new DeflateCompression({raw: true});
|
|
16
|
+
const decompressedData = await compression.decompress(compressedFile);
|
|
17
|
+
return decompressedData;
|
|
18
|
+
}
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* FileSystem adapter for a ZIP file
|
|
23
|
+
* Holds FileProvider object that provides random access to archived files
|
|
24
|
+
*/
|
|
25
|
+
export class ZipFileSystem implements FileSystem {
|
|
26
|
+
/** FileProvider instance promise */
|
|
27
|
+
protected fileProvider: Promise<FileProvider | null> = Promise.resolve(null);
|
|
28
|
+
public fileName?: string;
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* Constructor
|
|
32
|
+
* @param file - instance of FileProvider or file path string
|
|
33
|
+
*/
|
|
34
|
+
constructor(file: FileProvider | string) {
|
|
35
|
+
// Try to open file in NodeJS
|
|
36
|
+
if (typeof file === 'string') {
|
|
37
|
+
this.fileName = file;
|
|
38
|
+
if (!isBrowser) {
|
|
39
|
+
this.fileProvider = FileHandleFile.from(file);
|
|
40
|
+
} else {
|
|
41
|
+
throw new Error('Cannot open file for random access in a WEB browser');
|
|
42
|
+
}
|
|
43
|
+
} else if (isFileProvider(file)) {
|
|
44
|
+
this.fileProvider = Promise.resolve(file);
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
/** Clean up resources */
|
|
49
|
+
async destroy() {
|
|
50
|
+
const fileProvider = await this.fileProvider;
|
|
51
|
+
if (fileProvider) {
|
|
52
|
+
await fileProvider.destroy();
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* Get file names list from zip archive
|
|
58
|
+
* @returns array of file names
|
|
59
|
+
*/
|
|
60
|
+
async readdir(): Promise<string[]> {
|
|
61
|
+
const fileProvider = await this.fileProvider;
|
|
62
|
+
if (!fileProvider) {
|
|
63
|
+
throw new Error('No data detected in the zip archive');
|
|
64
|
+
}
|
|
65
|
+
const fileNames: string[] = [];
|
|
66
|
+
const zipCDIterator = zipCDFileHeaderGenerator(fileProvider);
|
|
67
|
+
for await (const cdHeader of zipCDIterator) {
|
|
68
|
+
fileNames.push(cdHeader.fileName);
|
|
69
|
+
}
|
|
70
|
+
return fileNames;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
/**
|
|
74
|
+
* Get file metadata
|
|
75
|
+
* @param filename - name of a file
|
|
76
|
+
* @returns central directory data
|
|
77
|
+
*/
|
|
78
|
+
async stat(filename: string): Promise<ZipCDFileHeader & {size: number}> {
|
|
79
|
+
const cdFileHeader = await this.getCDFileHeader(filename);
|
|
80
|
+
return {...cdFileHeader, size: Number(cdFileHeader.uncompressedSize)};
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
/**
|
|
84
|
+
* Implementation of fetch against this file system
|
|
85
|
+
* @param filename - name of a file
|
|
86
|
+
* @returns - Response with file data
|
|
87
|
+
*/
|
|
88
|
+
async fetch(filename: string): Promise<Response> {
|
|
89
|
+
const fileProvider = await this.fileProvider;
|
|
90
|
+
if (!fileProvider) {
|
|
91
|
+
throw new Error('No data detected in the zip archive');
|
|
92
|
+
}
|
|
93
|
+
const cdFileHeader = await this.getCDFileHeader(filename);
|
|
94
|
+
const localFileHeader = await parseZipLocalFileHeader(
|
|
95
|
+
cdFileHeader.localHeaderOffset,
|
|
96
|
+
fileProvider
|
|
97
|
+
);
|
|
98
|
+
if (!localFileHeader) {
|
|
99
|
+
throw new Error('Local file header has not been found in the zip archive`');
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
const compressionHandler = COMPRESSION_METHODS[localFileHeader.compressionMethod.toString()];
|
|
103
|
+
if (!compressionHandler) {
|
|
104
|
+
throw Error('Only Deflation compression is supported');
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
const compressedFile = await fileProvider.slice(
|
|
108
|
+
localFileHeader.fileDataOffset,
|
|
109
|
+
localFileHeader.fileDataOffset + localFileHeader.compressedSize
|
|
110
|
+
);
|
|
111
|
+
|
|
112
|
+
const uncompressedFile = await compressionHandler(compressedFile);
|
|
113
|
+
|
|
114
|
+
const response = new Response(uncompressedFile);
|
|
115
|
+
Object.defineProperty(response, 'url', {value: `${this.fileName || ''}/${filename}`});
|
|
116
|
+
return response;
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
/**
|
|
120
|
+
* Get central directory file header
|
|
121
|
+
* @param filename - name of a file
|
|
122
|
+
* @returns central directory file header
|
|
123
|
+
*/
|
|
124
|
+
private async getCDFileHeader(filename: string): Promise<ZipCDFileHeader> {
|
|
125
|
+
const fileProvider = await this.fileProvider;
|
|
126
|
+
if (!fileProvider) {
|
|
127
|
+
throw new Error('No data detected in the zip archive');
|
|
128
|
+
}
|
|
129
|
+
const zipCDIterator = zipCDFileHeaderGenerator(fileProvider);
|
|
130
|
+
let result: ZipCDFileHeader | null = null;
|
|
131
|
+
for await (const cdHeader of zipCDIterator) {
|
|
132
|
+
if (cdHeader.fileName === filename) {
|
|
133
|
+
result = cdHeader;
|
|
134
|
+
break;
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
if (!result) {
|
|
138
|
+
throw new Error('File has not been found in the zip archive');
|
|
139
|
+
}
|
|
140
|
+
return result;
|
|
141
|
+
}
|
|
142
|
+
}
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
import md5 from 'md5';
|
|
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
|
+
};
|
|
12
|
+
|
|
13
|
+
/**
|
|
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
|
|
18
|
+
*/
|
|
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);
|
|
22
|
+
|
|
23
|
+
const diff = h1[0] === h2[0] ? h1[1] - h2[1] : h1[0] - h2[0];
|
|
24
|
+
|
|
25
|
+
if (diff < 0n) {
|
|
26
|
+
return -1;
|
|
27
|
+
} else if (diff === 0n) {
|
|
28
|
+
return 0;
|
|
29
|
+
}
|
|
30
|
+
return 1;
|
|
31
|
+
};
|
|
32
|
+
|
|
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
|
+
};
|
|
58
|
+
|
|
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
|
+
};
|
|
84
|
+
|
|
85
|
+
/**
|
|
86
|
+
* generates hash info from central directory
|
|
87
|
+
* @param fileProvider - provider of the archive
|
|
88
|
+
* @returns ready to use hash info
|
|
89
|
+
*/
|
|
90
|
+
export const generateHashInfo = async (fileProvider: FileProvider): Promise<HashElement[]> => {
|
|
91
|
+
const zipCDIterator = zipCDFileHeaderGenerator(fileProvider);
|
|
92
|
+
const hashInfo: HashElement[] = [];
|
|
93
|
+
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
|
+
});
|
|
98
|
+
}
|
|
99
|
+
hashInfo.sort((a, b) => compareHashes(a.hash, b.hash));
|
|
100
|
+
return hashInfo;
|
|
101
|
+
};
|
package/src/index.ts
CHANGED
|
@@ -1,3 +1,22 @@
|
|
|
1
|
+
// loaders.gl, MIT license
|
|
2
|
+
|
|
1
3
|
export {ZipLoader} from './zip-loader';
|
|
2
4
|
export {ZipWriter} from './zip-writer';
|
|
3
|
-
export {
|
|
5
|
+
export {TarBuilder} from './tar-builder';
|
|
6
|
+
|
|
7
|
+
export {
|
|
8
|
+
parseZipCDFileHeader,
|
|
9
|
+
zipCDFileHeaderGenerator,
|
|
10
|
+
signature as cdSignature
|
|
11
|
+
} from './parse-zip/cd-file-header';
|
|
12
|
+
export {
|
|
13
|
+
parseZipLocalFileHeader,
|
|
14
|
+
signature as localHeaderSignature
|
|
15
|
+
} from './parse-zip/local-file-header';
|
|
16
|
+
export {parseEoCDRecord} from './parse-zip/end-of-central-directory';
|
|
17
|
+
export {searchFromTheEnd} from './parse-zip/search-from-the-end';
|
|
18
|
+
|
|
19
|
+
export type {HashElement} from './hash-file-utility';
|
|
20
|
+
export {compareHashes, parseHashFile, findBin, generateHashInfo} from './hash-file-utility';
|
|
21
|
+
|
|
22
|
+
export {ZipFileSystem} from './filesystems/zip-filesystem';
|