@loaders.gl/zip 4.0.0-alpha.23 → 4.0.0-alpha.25
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 +15 -19
- package/dist/es5/zip-loader.js +1 -1
- 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/zip-loader.js +1 -1
- 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/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 +4 -4
- package/src/zip-loader.ts +2 -1
- package/src/zip-writer.ts +23 -10
- package/dist/bundle.js +0 -5
- package/dist/filesystems/zip-filesystem.js +0 -128
- package/dist/hash-file-utility.js +0 -88
- package/dist/index.js +0 -28
- 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/parse-zip/cd-file-header.js +0 -68
- package/dist/parse-zip/end-of-central-directory.js +0 -40
- package/dist/parse-zip/local-file-header.js +0 -55
- package/dist/parse-zip/search-from-the-end.js +0 -31
- package/dist/tar-builder.js +0 -39
- package/dist/zip-loader.js +0 -60
- package/dist/zip-writer.js +0 -37
package/dist/dist.min.js
CHANGED
|
@@ -2787,17 +2787,17 @@
|
|
|
2787
2787
|
const jsZip = new import_jszip2.default();
|
|
2788
2788
|
for (const subFileName in fileMap) {
|
|
2789
2789
|
const subFileData = fileMap[subFileName];
|
|
2790
|
-
jsZip.file(subFileName, subFileData, options);
|
|
2790
|
+
jsZip.file(subFileName, subFileData, options?.jszip || {});
|
|
2791
2791
|
}
|
|
2792
|
-
|
|
2793
|
-
type: "arraybuffer"
|
|
2794
|
-
});
|
|
2792
|
+
const jszipOptions = { ...options?.jszip, type: "arraybuffer" };
|
|
2795
2793
|
const { onUpdate = () => {
|
|
2796
2794
|
} } = options;
|
|
2797
|
-
|
|
2795
|
+
try {
|
|
2796
|
+
return await jsZip.generateAsync(jszipOptions, onUpdate);
|
|
2797
|
+
} catch (error) {
|
|
2798
2798
|
options.log.error(`Unable to write zip archive: ${error}`);
|
|
2799
2799
|
throw error;
|
|
2800
|
-
}
|
|
2800
|
+
}
|
|
2801
2801
|
}
|
|
2802
2802
|
var import_jszip2, ZipWriter;
|
|
2803
2803
|
var init_zip_writer = __esm({
|
|
@@ -3618,9 +3618,9 @@
|
|
|
3618
3618
|
}
|
|
3619
3619
|
});
|
|
3620
3620
|
|
|
3621
|
-
//
|
|
3622
|
-
var
|
|
3623
|
-
"
|
|
3621
|
+
// ../loader-utils/src/lib/node/fs.browser.ts
|
|
3622
|
+
var init_fs_browser = __esm({
|
|
3623
|
+
"../loader-utils/src/lib/node/fs.browser.ts"() {
|
|
3624
3624
|
}
|
|
3625
3625
|
});
|
|
3626
3626
|
|
|
@@ -3635,15 +3635,15 @@
|
|
|
3635
3635
|
});
|
|
3636
3636
|
|
|
3637
3637
|
// ../loader-utils/src/lib/file-provider/file-handle.ts
|
|
3638
|
-
var
|
|
3638
|
+
var FileHandle;
|
|
3639
3639
|
var init_file_handle = __esm({
|
|
3640
3640
|
"../loader-utils/src/lib/file-provider/file-handle.ts"() {
|
|
3641
|
-
|
|
3641
|
+
init_fs_browser();
|
|
3642
3642
|
FileHandle = class {
|
|
3643
3643
|
constructor(fileDescriptor, stats) {
|
|
3644
3644
|
this.read = (buffer, offset, length, position) => {
|
|
3645
3645
|
return new Promise((s) => {
|
|
3646
|
-
(0
|
|
3646
|
+
(void 0)(this.fileDescriptor, buffer, offset, length, position, (_err, bytesRead, buffer2) => s({ bytesRead, buffer: buffer2 }));
|
|
3647
3647
|
});
|
|
3648
3648
|
};
|
|
3649
3649
|
this.fileDescriptor = fileDescriptor;
|
|
@@ -3652,18 +3652,14 @@
|
|
|
3652
3652
|
static async open(path) {
|
|
3653
3653
|
const [fd, stats] = await Promise.all([
|
|
3654
3654
|
new Promise((resolve, reject) => {
|
|
3655
|
-
(0
|
|
3655
|
+
(void 0)(path, void 0, void 0, (_err, fd2) => _err ? reject(_err) : resolve(fd2));
|
|
3656
3656
|
}),
|
|
3657
|
-
|
|
3658
|
-
(0, import_fs.stat)(path, { bigint: true }, (_err, stats2) => _err ? reject(_err) : resolve(stats2));
|
|
3659
|
-
})
|
|
3657
|
+
(void 0)(path, { bigint: true })
|
|
3660
3658
|
]);
|
|
3661
3659
|
return new FileHandle(fd, stats);
|
|
3662
3660
|
}
|
|
3663
3661
|
async close() {
|
|
3664
|
-
return
|
|
3665
|
-
(0, import_fs.close)(this.fileDescriptor, (_err) => resolve());
|
|
3666
|
-
});
|
|
3662
|
+
return (void 0)(this.fileDescriptor);
|
|
3667
3663
|
}
|
|
3668
3664
|
get stat() {
|
|
3669
3665
|
return this.stats;
|
package/dist/es5/zip-loader.js
CHANGED
|
@@ -8,7 +8,7 @@ exports.ZipLoader = void 0;
|
|
|
8
8
|
var _regenerator = _interopRequireDefault(require("@babel/runtime/regenerator"));
|
|
9
9
|
var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator"));
|
|
10
10
|
var _jszip = _interopRequireDefault(require("jszip"));
|
|
11
|
-
var VERSION = typeof "4.0.0-alpha.
|
|
11
|
+
var VERSION = typeof "4.0.0-alpha.25" !== 'undefined' ? "4.0.0-alpha.25" : 'latest';
|
|
12
12
|
var ZipLoader = {
|
|
13
13
|
id: 'zip',
|
|
14
14
|
module: 'zip',
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"zip-loader.js","names":["_jszip","_interopRequireDefault","require","VERSION","ZipLoader","id","module","name","version","extensions","mimeTypes","category","tests","options","parse","parseZipAsync","exports","_x","_parseZipAsync","apply","arguments","_asyncToGenerator2","default","_regenerator","mark","_callee","data","promises","fileMap","jsZip","zip","_args","wrap","_callee$","_context","prev","next","length","undefined","JSZip","loadAsync","sent","forEach","relativePath","zipEntry","subFilename","promise","loadZipEntry","then","arrayBufferOrError","push","Promise","all","abrupt","t0","log","error","concat","stop","_x2","_x3","_loadZipEntry","_callee2","arrayBuffer","_args2","_callee2$","_context2","file","async","dataType"],"sources":["../../src/zip-loader.ts"],"sourcesContent":["//
|
|
1
|
+
{"version":3,"file":"zip-loader.js","names":["_jszip","_interopRequireDefault","require","VERSION","ZipLoader","id","module","name","version","extensions","mimeTypes","category","tests","options","parse","parseZipAsync","exports","_x","_parseZipAsync","apply","arguments","_asyncToGenerator2","default","_regenerator","mark","_callee","data","promises","fileMap","jsZip","zip","_args","wrap","_callee$","_context","prev","next","length","undefined","JSZip","loadAsync","sent","forEach","relativePath","zipEntry","subFilename","promise","loadZipEntry","then","arrayBufferOrError","push","Promise","all","abrupt","t0","log","error","concat","stop","_x2","_x3","_loadZipEntry","_callee2","arrayBuffer","_args2","_callee2$","_context2","file","async","dataType"],"sources":["../../src/zip-loader.ts"],"sourcesContent":["// loaders.gl, MIT license\n\nimport type {LoaderWithParser, LoaderOptions} from '@loaders.gl/loader-utils';\nimport JSZip from 'jszip';\n\n// __VERSION__ is injected by babel-plugin-version-inline\n// @ts-ignore TS2304: Cannot find name '__VERSION__'.\nconst VERSION = typeof __VERSION__ !== 'undefined' ? __VERSION__ : 'latest';\n\ntype FileMap = Record<string, ArrayBuffer>;\n\nexport const ZipLoader: LoaderWithParser<FileMap, never, LoaderOptions> = {\n id: 'zip',\n module: 'zip',\n name: 'Zip Archive',\n version: VERSION,\n extensions: ['zip'],\n mimeTypes: ['application/zip'],\n category: 'archive',\n tests: ['PK'],\n options: {},\n parse: parseZipAsync\n};\n\n// TODO - Could return a map of promises, perhaps as an option...\nasync function parseZipAsync(data: any, options = {}): Promise<FileMap> {\n const promises: Promise<any>[] = [];\n const fileMap: Record<string, ArrayBuffer> = {};\n\n try {\n const jsZip = new JSZip();\n\n const zip = await jsZip.loadAsync(data, options);\n\n // start to load each file in this zip\n zip.forEach((relativePath, zipEntry) => {\n const subFilename = zipEntry.name;\n\n const promise = loadZipEntry(jsZip, subFilename, options).then((arrayBufferOrError) => {\n fileMap[relativePath] = arrayBufferOrError;\n });\n\n // Ensure Promise.all doesn't ignore rejected promises.\n promises.push(promise);\n });\n\n await Promise.all(promises);\n return fileMap;\n } catch (error) {\n // @ts-ignore\n options.log.error(`Unable to read zip archive: ${error}`);\n throw error;\n }\n}\n\nasync function loadZipEntry(jsZip: any, subFilename: string, options: any = {}) {\n // jszip supports both arraybuffer and text, the main loaders.gl types\n // https://stuk.github.io/jszip/documentation/api_zipobject/async.html\n try {\n const arrayBuffer = await jsZip.file(subFilename).async(options.dataType || 'arraybuffer');\n return arrayBuffer;\n } catch (error) {\n options.log.error(`Unable to read ${subFilename} from zip archive: ${error}`);\n // Store error in place of data in map\n return error;\n }\n}\n"],"mappings":";;;;;;;;;AAGA,IAAAA,MAAA,GAAAC,sBAAA,CAAAC,OAAA;AAIA,IAAMC,OAAO,GAAG,uBAAkB,KAAK,WAAW,sBAAiB,QAAQ;AAIpE,IAAMC,SAA0D,GAAG;EACxEC,EAAE,EAAE,KAAK;EACTC,MAAM,EAAE,KAAK;EACbC,IAAI,EAAE,aAAa;EACnBC,OAAO,EAAEL,OAAO;EAChBM,UAAU,EAAE,CAAC,KAAK,CAAC;EACnBC,SAAS,EAAE,CAAC,iBAAiB,CAAC;EAC9BC,QAAQ,EAAE,SAAS;EACnBC,KAAK,EAAE,CAAC,IAAI,CAAC;EACbC,OAAO,EAAE,CAAC,CAAC;EACXC,KAAK,EAAEC;AACT,CAAC;AAACC,OAAA,CAAAZ,SAAA,GAAAA,SAAA;AAAA,SAGaW,aAAaA,CAAAE,EAAA;EAAA,OAAAC,cAAA,CAAAC,KAAA,OAAAC,SAAA;AAAA;AAAA,SAAAF,eAAA;EAAAA,cAAA,OAAAG,kBAAA,CAAAC,OAAA,EAAAC,YAAA,CAAAD,OAA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,CAAAS,SAAA,CAAAZ,EAAA,CAA6B,CAAC;UAAC,OAAAY,SAAA,CAAAb,MAAA,WAAAa,SAAA,CAAAZ,EAAA;QAAA;QAAA;UAAA,OAAAY,SAAA,CAAAR,IAAA;MAAA;IAAA,GAAAI,QAAA;EAAA,CAIjF;EAAA,OAAAD,aAAA,CAAA1C,KAAA,OAAAC,SAAA;AAAA"}
|
package/dist/es5/zip-writer.js
CHANGED
|
@@ -6,8 +6,11 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
6
6
|
});
|
|
7
7
|
exports.ZipWriter = void 0;
|
|
8
8
|
var _regenerator = _interopRequireDefault(require("@babel/runtime/regenerator"));
|
|
9
|
+
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
9
10
|
var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator"));
|
|
10
11
|
var _jszip = _interopRequireDefault(require("jszip"));
|
|
12
|
+
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
|
13
|
+
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { (0, _defineProperty2.default)(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
|
|
11
14
|
var ZipWriter = {
|
|
12
15
|
name: 'Zip Archive',
|
|
13
16
|
extensions: ['zip'],
|
|
@@ -25,7 +28,7 @@ function _encodeZipAsync() {
|
|
|
25
28
|
jsZip,
|
|
26
29
|
subFileName,
|
|
27
30
|
subFileData,
|
|
28
|
-
|
|
31
|
+
jszipOptions,
|
|
29
32
|
_options$onUpdate,
|
|
30
33
|
onUpdate,
|
|
31
34
|
_args = arguments;
|
|
@@ -36,21 +39,27 @@ function _encodeZipAsync() {
|
|
|
36
39
|
jsZip = new _jszip.default();
|
|
37
40
|
for (subFileName in fileMap) {
|
|
38
41
|
subFileData = fileMap[subFileName];
|
|
39
|
-
jsZip.file(subFileName, subFileData, options);
|
|
42
|
+
jsZip.file(subFileName, subFileData, (options === null || options === void 0 ? void 0 : options.jszip) || {});
|
|
40
43
|
}
|
|
41
|
-
|
|
44
|
+
jszipOptions = _objectSpread(_objectSpread({}, options === null || options === void 0 ? void 0 : options.jszip), {}, {
|
|
42
45
|
type: 'arraybuffer'
|
|
43
46
|
});
|
|
44
|
-
_options
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
47
|
+
_options$onUpdate = options.onUpdate, onUpdate = _options$onUpdate === void 0 ? function () {} : _options$onUpdate;
|
|
48
|
+
_context.prev = 5;
|
|
49
|
+
_context.next = 8;
|
|
50
|
+
return jsZip.generateAsync(jszipOptions, onUpdate);
|
|
51
|
+
case 8:
|
|
52
|
+
return _context.abrupt("return", _context.sent);
|
|
53
|
+
case 11:
|
|
54
|
+
_context.prev = 11;
|
|
55
|
+
_context.t0 = _context["catch"](5);
|
|
56
|
+
options.log.error("Unable to write zip archive: ".concat(_context.t0));
|
|
57
|
+
throw _context.t0;
|
|
58
|
+
case 15:
|
|
50
59
|
case "end":
|
|
51
60
|
return _context.stop();
|
|
52
61
|
}
|
|
53
|
-
}, _callee);
|
|
62
|
+
}, _callee, null, [[5, 11]]);
|
|
54
63
|
}));
|
|
55
64
|
return _encodeZipAsync.apply(this, arguments);
|
|
56
65
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"zip-writer.js","names":["_jszip","_interopRequireDefault","require","
|
|
1
|
+
{"version":3,"file":"zip-writer.js","names":["_jszip","_interopRequireDefault","require","ownKeys","object","enumerableOnly","keys","Object","getOwnPropertySymbols","symbols","filter","sym","getOwnPropertyDescriptor","enumerable","push","apply","_objectSpread","target","i","arguments","length","source","forEach","key","_defineProperty2","default","getOwnPropertyDescriptors","defineProperties","defineProperty","ZipWriter","name","extensions","category","mimeTypes","encode","encodeZipAsync","exports","_x","_encodeZipAsync","_asyncToGenerator2","_regenerator","mark","_callee","fileMap","options","jsZip","subFileName","subFileData","jszipOptions","_options$onUpdate","onUpdate","_args","wrap","_callee$","_context","prev","next","undefined","JSZip","file","jszip","type","generateAsync","abrupt","sent","t0","log","error","concat","stop"],"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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AE,IAAA;UAAA,OAGXX,KAAK,CAACiB,aAAa,CAACd,YAAY,EAAEE,QAAQ,CAAC;QAAA;UAAA,OAAAI,QAAA,CAAAS,MAAA,WAAAT,QAAA,CAAAU,IAAA;QAAA;UAAAV,QAAA,CAAAC,IAAA;UAAAD,QAAA,CAAAW,EAAA,GAAAX,QAAA;UAExDV,OAAO,CAACsB,GAAG,CAACC,KAAK,iCAAAC,MAAA,CAAAd,QAAA,CAAAW,EAAA,CAAwC,CAAC;UAAC,MAAAX,QAAA,CAAAW,EAAA;QAAA;QAAA;UAAA,OAAAX,QAAA,CAAAe,IAAA;MAAA;IAAA,GAAA3B,OAAA;EAAA,CAG9D;EAAA,OAAAJ,eAAA,CAAAvB,KAAA,OAAAI,SAAA;AAAA"}
|
package/dist/esm/zip-loader.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"zip-loader.js","names":["JSZip","VERSION","ZipLoader","id","module","name","version","extensions","mimeTypes","category","tests","options","parse","parseZipAsync","data","arguments","length","undefined","promises","fileMap","jsZip","zip","loadAsync","forEach","relativePath","zipEntry","subFilename","promise","loadZipEntry","then","arrayBufferOrError","push","Promise","all","error","log","concat","arrayBuffer","file","async","dataType"],"sources":["../../src/zip-loader.ts"],"sourcesContent":["//
|
|
1
|
+
{"version":3,"file":"zip-loader.js","names":["JSZip","VERSION","ZipLoader","id","module","name","version","extensions","mimeTypes","category","tests","options","parse","parseZipAsync","data","arguments","length","undefined","promises","fileMap","jsZip","zip","loadAsync","forEach","relativePath","zipEntry","subFilename","promise","loadZipEntry","then","arrayBufferOrError","push","Promise","all","error","log","concat","arrayBuffer","file","async","dataType"],"sources":["../../src/zip-loader.ts"],"sourcesContent":["// loaders.gl, MIT license\n\nimport type {LoaderWithParser, LoaderOptions} from '@loaders.gl/loader-utils';\nimport JSZip from 'jszip';\n\n// __VERSION__ is injected by babel-plugin-version-inline\n// @ts-ignore TS2304: Cannot find name '__VERSION__'.\nconst VERSION = typeof __VERSION__ !== 'undefined' ? __VERSION__ : 'latest';\n\ntype FileMap = Record<string, ArrayBuffer>;\n\nexport const ZipLoader: LoaderWithParser<FileMap, never, LoaderOptions> = {\n id: 'zip',\n module: 'zip',\n name: 'Zip Archive',\n version: VERSION,\n extensions: ['zip'],\n mimeTypes: ['application/zip'],\n category: 'archive',\n tests: ['PK'],\n options: {},\n parse: parseZipAsync\n};\n\n// TODO - Could return a map of promises, perhaps as an option...\nasync function parseZipAsync(data: any, options = {}): Promise<FileMap> {\n const promises: Promise<any>[] = [];\n const fileMap: Record<string, ArrayBuffer> = {};\n\n try {\n const jsZip = new JSZip();\n\n const zip = await jsZip.loadAsync(data, options);\n\n // start to load each file in this zip\n zip.forEach((relativePath, zipEntry) => {\n const subFilename = zipEntry.name;\n\n const promise = loadZipEntry(jsZip, subFilename, options).then((arrayBufferOrError) => {\n fileMap[relativePath] = arrayBufferOrError;\n });\n\n // Ensure Promise.all doesn't ignore rejected promises.\n promises.push(promise);\n });\n\n await Promise.all(promises);\n return fileMap;\n } catch (error) {\n // @ts-ignore\n options.log.error(`Unable to read zip archive: ${error}`);\n throw error;\n }\n}\n\nasync function loadZipEntry(jsZip: any, subFilename: string, options: any = {}) {\n // jszip supports both arraybuffer and text, the main loaders.gl types\n // https://stuk.github.io/jszip/documentation/api_zipobject/async.html\n try {\n const arrayBuffer = await jsZip.file(subFilename).async(options.dataType || 'arraybuffer');\n return arrayBuffer;\n } catch (error) {\n options.log.error(`Unable to read ${subFilename} from zip archive: ${error}`);\n // Store error in place of data in map\n return error;\n }\n}\n"],"mappings":"AAGA,OAAOA,KAAK,MAAM,OAAO;AAIzB,MAAMC,OAAO,GAAG,uBAAkB,KAAK,WAAW,sBAAiB,QAAQ;AAI3E,OAAO,MAAMC,SAA0D,GAAG;EACxEC,EAAE,EAAE,KAAK;EACTC,MAAM,EAAE,KAAK;EACbC,IAAI,EAAE,aAAa;EACnBC,OAAO,EAAEL,OAAO;EAChBM,UAAU,EAAE,CAAC,KAAK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SAAA,GAAAF,SAAA,MAAG,CAAC,CAAC;EAG5E,IAAI;IACF,MAAMsB,WAAW,GAAG,MAAMjB,KAAK,CAACkB,IAAI,CAACZ,WAAW,CAAC,CAACa,KAAK,CAAC5B,OAAO,CAAC6B,QAAQ,IAAI,aAAa,CAAC;IAC1F,OAAOH,WAAW;EACpB,CAAC,CAAC,OAAOH,KAAK,EAAE;IACdvB,OAAO,CAACwB,GAAG,CAACD,KAAK,mBAAAE,MAAA,CAAmBV,WAAW,yBAAAU,MAAA,CAAsBF,KAAK,CAAE,CAAC;IAE7E,OAAOA,KAAK;EACd;AACF"}
|
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"}
|
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-alpha.
|
|
3
|
+
"version": "4.0.0-alpha.25",
|
|
4
4
|
"description": "Zip Archive Loader",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"publishConfig": {
|
|
@@ -30,9 +30,9 @@
|
|
|
30
30
|
"build-bundle": "esbuild src/bundle.ts --bundle --outfile=dist/dist.min.js"
|
|
31
31
|
},
|
|
32
32
|
"dependencies": {
|
|
33
|
-
"@loaders.gl/compression": "4.0.0-alpha.
|
|
34
|
-
"@loaders.gl/loader-utils": "4.0.0-alpha.
|
|
33
|
+
"@loaders.gl/compression": "4.0.0-alpha.25",
|
|
34
|
+
"@loaders.gl/loader-utils": "4.0.0-alpha.25",
|
|
35
35
|
"jszip": "^3.1.5"
|
|
36
36
|
},
|
|
37
|
-
"gitHead": "
|
|
37
|
+
"gitHead": "40135f391b869388dbbcd615bbe51178d0c370be"
|
|
38
38
|
}
|
package/src/zip-loader.ts
CHANGED
package/src/zip-writer.ts
CHANGED
|
@@ -1,10 +1,20 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
// loaders.gl, MIT license
|
|
2
|
+
|
|
3
|
+
import type {Writer, WriterOptions} from '@loaders.gl/loader-utils';
|
|
4
|
+
import JSZip, {JSZipGeneratorOptions} from 'jszip';
|
|
5
|
+
|
|
6
|
+
export type ZipWriterOptions = WriterOptions & {
|
|
7
|
+
zip?: {
|
|
8
|
+
onUpdate?: (metadata: {percent: number}) => void;
|
|
9
|
+
};
|
|
10
|
+
/** Passthrough options to jszip */
|
|
11
|
+
jszip?: JSZipGeneratorOptions;
|
|
12
|
+
};
|
|
3
13
|
|
|
4
14
|
/**
|
|
5
15
|
* Zip exporter
|
|
6
16
|
*/
|
|
7
|
-
export const ZipWriter: Writer = {
|
|
17
|
+
export const ZipWriter: Writer<FileReaderEventMap, never, ZipWriterOptions> = {
|
|
8
18
|
name: 'Zip Archive',
|
|
9
19
|
extensions: ['zip'],
|
|
10
20
|
category: 'archive',
|
|
@@ -13,7 +23,10 @@ export const ZipWriter: Writer = {
|
|
|
13
23
|
encode: encodeZipAsync
|
|
14
24
|
};
|
|
15
25
|
|
|
16
|
-
async function encodeZipAsync(
|
|
26
|
+
async function encodeZipAsync(
|
|
27
|
+
fileMap: Record<string, ArrayBuffer>,
|
|
28
|
+
options: ZipWriterOptions = {}
|
|
29
|
+
) {
|
|
17
30
|
const jsZip = new JSZip();
|
|
18
31
|
// add files to the zip
|
|
19
32
|
for (const subFileName in fileMap) {
|
|
@@ -21,17 +34,17 @@ async function encodeZipAsync(fileMap: any, options: any = {}) {
|
|
|
21
34
|
|
|
22
35
|
// jszip supports both arraybuffer and string data (the main loaders.gl types)
|
|
23
36
|
// https://stuk.github.io/jszip/documentation/api_zipobject/async.html
|
|
24
|
-
jsZip.file(subFileName, subFileData, options);
|
|
37
|
+
jsZip.file(subFileName, subFileData, options?.jszip || {});
|
|
25
38
|
}
|
|
26
39
|
|
|
27
40
|
// always generate the full zip as an arraybuffer
|
|
28
|
-
|
|
29
|
-
type: 'arraybuffer'
|
|
30
|
-
});
|
|
41
|
+
const jszipOptions: JSZipGeneratorOptions = {...options?.jszip, type: 'arraybuffer'};
|
|
31
42
|
const {onUpdate = () => {}} = options;
|
|
32
43
|
|
|
33
|
-
|
|
44
|
+
try {
|
|
45
|
+
return await jsZip.generateAsync(jszipOptions, onUpdate);
|
|
46
|
+
} catch (error) {
|
|
34
47
|
options.log.error(`Unable to write zip archive: ${error}`);
|
|
35
48
|
throw error;
|
|
36
|
-
}
|
|
49
|
+
}
|
|
37
50
|
}
|
package/dist/bundle.js
DELETED
|
@@ -1,128 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.ZipFileSystem = void 0;
|
|
4
|
-
const loader_utils_1 = require("@loaders.gl/loader-utils");
|
|
5
|
-
const loader_utils_2 = require("@loaders.gl/loader-utils");
|
|
6
|
-
const loader_utils_3 = require("@loaders.gl/loader-utils");
|
|
7
|
-
const cd_file_header_1 = require("../parse-zip/cd-file-header");
|
|
8
|
-
const local_file_header_1 = require("../parse-zip/local-file-header");
|
|
9
|
-
const compression_1 = require("@loaders.gl/compression");
|
|
10
|
-
/** Handling different compression types in zip */
|
|
11
|
-
const COMPRESSION_METHODS = {
|
|
12
|
-
/** No compression */
|
|
13
|
-
0: async (compressedFile) => compressedFile,
|
|
14
|
-
/** Deflation */
|
|
15
|
-
8: async (compressedFile) => {
|
|
16
|
-
const compression = new compression_1.DeflateCompression({ raw: true });
|
|
17
|
-
const decompressedData = await compression.decompress(compressedFile);
|
|
18
|
-
return decompressedData;
|
|
19
|
-
}
|
|
20
|
-
};
|
|
21
|
-
/**
|
|
22
|
-
* FileSystem adapter for a ZIP file
|
|
23
|
-
* Holds FileProvider object that provides random access to archived files
|
|
24
|
-
*/
|
|
25
|
-
class ZipFileSystem {
|
|
26
|
-
/**
|
|
27
|
-
* Constructor
|
|
28
|
-
* @param file - instance of FileProvider or file path string
|
|
29
|
-
*/
|
|
30
|
-
constructor(file) {
|
|
31
|
-
/** FileProvider instance promise */
|
|
32
|
-
this.fileProvider = Promise.resolve(null);
|
|
33
|
-
// Try to open file in NodeJS
|
|
34
|
-
if (typeof file === 'string') {
|
|
35
|
-
this.fileName = file;
|
|
36
|
-
if (!loader_utils_1.isBrowser) {
|
|
37
|
-
this.fileProvider = loader_utils_3.FileHandleFile.from(file);
|
|
38
|
-
}
|
|
39
|
-
else {
|
|
40
|
-
throw new Error('Cannot open file for random access in a WEB browser');
|
|
41
|
-
}
|
|
42
|
-
}
|
|
43
|
-
else if ((0, loader_utils_2.isFileProvider)(file)) {
|
|
44
|
-
this.fileProvider = Promise.resolve(file);
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
/** Clean up resources */
|
|
48
|
-
async destroy() {
|
|
49
|
-
const fileProvider = await this.fileProvider;
|
|
50
|
-
if (fileProvider) {
|
|
51
|
-
await fileProvider.destroy();
|
|
52
|
-
}
|
|
53
|
-
}
|
|
54
|
-
/**
|
|
55
|
-
* Get file names list from zip archive
|
|
56
|
-
* @returns array of file names
|
|
57
|
-
*/
|
|
58
|
-
async readdir() {
|
|
59
|
-
const fileProvider = await this.fileProvider;
|
|
60
|
-
if (!fileProvider) {
|
|
61
|
-
throw new Error('No data detected in the zip archive');
|
|
62
|
-
}
|
|
63
|
-
const fileNames = [];
|
|
64
|
-
const zipCDIterator = (0, cd_file_header_1.zipCDFileHeaderGenerator)(fileProvider);
|
|
65
|
-
for await (const cdHeader of zipCDIterator) {
|
|
66
|
-
fileNames.push(cdHeader.fileName);
|
|
67
|
-
}
|
|
68
|
-
return fileNames;
|
|
69
|
-
}
|
|
70
|
-
/**
|
|
71
|
-
* Get file metadata
|
|
72
|
-
* @param filename - name of a file
|
|
73
|
-
* @returns central directory data
|
|
74
|
-
*/
|
|
75
|
-
async stat(filename) {
|
|
76
|
-
const cdFileHeader = await this.getCDFileHeader(filename);
|
|
77
|
-
return { ...cdFileHeader, size: Number(cdFileHeader.uncompressedSize) };
|
|
78
|
-
}
|
|
79
|
-
/**
|
|
80
|
-
* Implementation of fetch against this file system
|
|
81
|
-
* @param filename - name of a file
|
|
82
|
-
* @returns - Response with file data
|
|
83
|
-
*/
|
|
84
|
-
async fetch(filename) {
|
|
85
|
-
const fileProvider = await this.fileProvider;
|
|
86
|
-
if (!fileProvider) {
|
|
87
|
-
throw new Error('No data detected in the zip archive');
|
|
88
|
-
}
|
|
89
|
-
const cdFileHeader = await this.getCDFileHeader(filename);
|
|
90
|
-
const localFileHeader = await (0, local_file_header_1.parseZipLocalFileHeader)(cdFileHeader.localHeaderOffset, fileProvider);
|
|
91
|
-
if (!localFileHeader) {
|
|
92
|
-
throw new Error('Local file header has not been found in the zip archive`');
|
|
93
|
-
}
|
|
94
|
-
const compressionHandler = COMPRESSION_METHODS[localFileHeader.compressionMethod.toString()];
|
|
95
|
-
if (!compressionHandler) {
|
|
96
|
-
throw Error('Only Deflation compression is supported');
|
|
97
|
-
}
|
|
98
|
-
const compressedFile = await fileProvider.slice(localFileHeader.fileDataOffset, localFileHeader.fileDataOffset + localFileHeader.compressedSize);
|
|
99
|
-
const uncompressedFile = await compressionHandler(compressedFile);
|
|
100
|
-
const response = new Response(uncompressedFile);
|
|
101
|
-
Object.defineProperty(response, 'url', { value: `${this.fileName || ''}/${filename}` });
|
|
102
|
-
return response;
|
|
103
|
-
}
|
|
104
|
-
/**
|
|
105
|
-
* Get central directory file header
|
|
106
|
-
* @param filename - name of a file
|
|
107
|
-
* @returns central directory file header
|
|
108
|
-
*/
|
|
109
|
-
async getCDFileHeader(filename) {
|
|
110
|
-
const fileProvider = await this.fileProvider;
|
|
111
|
-
if (!fileProvider) {
|
|
112
|
-
throw new Error('No data detected in the zip archive');
|
|
113
|
-
}
|
|
114
|
-
const zipCDIterator = (0, cd_file_header_1.zipCDFileHeaderGenerator)(fileProvider);
|
|
115
|
-
let result = null;
|
|
116
|
-
for await (const cdHeader of zipCDIterator) {
|
|
117
|
-
if (cdHeader.fileName === filename) {
|
|
118
|
-
result = cdHeader;
|
|
119
|
-
break;
|
|
120
|
-
}
|
|
121
|
-
}
|
|
122
|
-
if (!result) {
|
|
123
|
-
throw new Error('File has not been found in the zip archive');
|
|
124
|
-
}
|
|
125
|
-
return result;
|
|
126
|
-
}
|
|
127
|
-
}
|
|
128
|
-
exports.ZipFileSystem = ZipFileSystem;
|
|
@@ -1,88 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.generateHashInfo = exports.findBin = exports.parseHashFile = exports.compareHashes = void 0;
|
|
7
|
-
const md5_1 = __importDefault(require("md5"));
|
|
8
|
-
const cd_file_header_1 = require("./parse-zip/cd-file-header");
|
|
9
|
-
/**
|
|
10
|
-
* Comparing md5 hashes according to https://github.com/Esri/i3s-spec/blob/master/docs/2.0/slpk_hashtable.pcsl.md step 5
|
|
11
|
-
* @param hash1 hash to compare
|
|
12
|
-
* @param hash2 hash to compare
|
|
13
|
-
* @returns -1 if hash1 < hash2, 0 of hash1 === hash2, 1 if hash1 > hash2
|
|
14
|
-
*/
|
|
15
|
-
const compareHashes = (hash1, hash2) => {
|
|
16
|
-
const h1 = new BigUint64Array(hash1.buffer, hash1.byteOffset, 2);
|
|
17
|
-
const h2 = new BigUint64Array(hash2.buffer, hash2.byteOffset, 2);
|
|
18
|
-
const diff = h1[0] === h2[0] ? h1[1] - h2[1] : h1[0] - h2[0];
|
|
19
|
-
if (diff < 0n) {
|
|
20
|
-
return -1;
|
|
21
|
-
}
|
|
22
|
-
else if (diff === 0n) {
|
|
23
|
-
return 0;
|
|
24
|
-
}
|
|
25
|
-
return 1;
|
|
26
|
-
};
|
|
27
|
-
exports.compareHashes = compareHashes;
|
|
28
|
-
/**
|
|
29
|
-
* Reads hash file from buffer and returns it in ready-to-use form
|
|
30
|
-
* @param hashFile - bufer containing hash file
|
|
31
|
-
* @returns Array containing file info
|
|
32
|
-
*/
|
|
33
|
-
const parseHashFile = (hashFile) => {
|
|
34
|
-
const hashFileBuffer = Buffer.from(hashFile);
|
|
35
|
-
const hashArray = [];
|
|
36
|
-
for (let i = 0; i < hashFileBuffer.buffer.byteLength; i = i + 24) {
|
|
37
|
-
const offsetBuffer = new DataView(hashFileBuffer.buffer.slice(hashFileBuffer.byteOffset + i + 16, hashFileBuffer.byteOffset + i + 24));
|
|
38
|
-
const offset = offsetBuffer.getBigUint64(offsetBuffer.byteOffset, true);
|
|
39
|
-
hashArray.push({
|
|
40
|
-
hash: Buffer.from(hashFileBuffer.subarray(hashFileBuffer.byteOffset + i, hashFileBuffer.byteOffset + i + 16)),
|
|
41
|
-
offset
|
|
42
|
-
});
|
|
43
|
-
}
|
|
44
|
-
return hashArray;
|
|
45
|
-
};
|
|
46
|
-
exports.parseHashFile = parseHashFile;
|
|
47
|
-
/**
|
|
48
|
-
* Binary search in the hash info
|
|
49
|
-
* @param hashToSearch hash that we need to find
|
|
50
|
-
* @returns required hash element or undefined if not found
|
|
51
|
-
*/
|
|
52
|
-
const findBin = (hashToSearch, hashArray) => {
|
|
53
|
-
let lowerBorder = 0;
|
|
54
|
-
let upperBorder = hashArray.length;
|
|
55
|
-
while (upperBorder - lowerBorder > 1) {
|
|
56
|
-
const middle = lowerBorder + Math.floor((upperBorder - lowerBorder) / 2);
|
|
57
|
-
const value = (0, exports.compareHashes)(hashArray[middle].hash, hashToSearch);
|
|
58
|
-
if (value === 0) {
|
|
59
|
-
return hashArray[middle];
|
|
60
|
-
}
|
|
61
|
-
else if (value < 0) {
|
|
62
|
-
lowerBorder = middle;
|
|
63
|
-
}
|
|
64
|
-
else {
|
|
65
|
-
upperBorder = middle;
|
|
66
|
-
}
|
|
67
|
-
}
|
|
68
|
-
return undefined;
|
|
69
|
-
};
|
|
70
|
-
exports.findBin = findBin;
|
|
71
|
-
/**
|
|
72
|
-
* generates hash info from central directory
|
|
73
|
-
* @param fileProvider - provider of the archive
|
|
74
|
-
* @returns ready to use hash info
|
|
75
|
-
*/
|
|
76
|
-
const generateHashInfo = async (fileProvider) => {
|
|
77
|
-
const zipCDIterator = (0, cd_file_header_1.zipCDFileHeaderGenerator)(fileProvider);
|
|
78
|
-
const hashInfo = [];
|
|
79
|
-
for await (const cdHeader of zipCDIterator) {
|
|
80
|
-
hashInfo.push({
|
|
81
|
-
hash: Buffer.from((0, md5_1.default)(cdHeader.fileName.split('\\').join('/').toLocaleLowerCase()), 'hex'),
|
|
82
|
-
offset: cdHeader.localHeaderOffset
|
|
83
|
-
});
|
|
84
|
-
}
|
|
85
|
-
hashInfo.sort((a, b) => (0, exports.compareHashes)(a.hash, b.hash));
|
|
86
|
-
return hashInfo;
|
|
87
|
-
};
|
|
88
|
-
exports.generateHashInfo = generateHashInfo;
|