@loaders.gl/zip 4.0.0-alpha.23 → 4.0.0-alpha.24
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 +14 -14
- 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,12 +3618,6 @@
|
|
|
3618
3618
|
}
|
|
3619
3619
|
});
|
|
3620
3620
|
|
|
3621
|
-
// (disabled):fs
|
|
3622
|
-
var require_fs = __commonJS({
|
|
3623
|
-
"(disabled):fs"() {
|
|
3624
|
-
}
|
|
3625
|
-
});
|
|
3626
|
-
|
|
3627
3621
|
// ../loader-utils/src/lib/file-provider/file-provider.ts
|
|
3628
3622
|
var isFileProvider;
|
|
3629
3623
|
var init_file_provider = __esm({
|
|
@@ -3634,11 +3628,17 @@
|
|
|
3634
3628
|
}
|
|
3635
3629
|
});
|
|
3636
3630
|
|
|
3631
|
+
// (disabled):fs
|
|
3632
|
+
var init_fs = __esm({
|
|
3633
|
+
"(disabled):fs"() {
|
|
3634
|
+
}
|
|
3635
|
+
});
|
|
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();
|
|
3642
3642
|
FileHandle = class {
|
|
3643
3643
|
constructor(fileDescriptor, stats) {
|
|
3644
3644
|
this.read = (buffer, offset, length, position) => {
|
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.24" !== 'undefined' ? "4.0.0-alpha.24" : '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":"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"}
|
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;\n }\n}\n"],"mappings":"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"}
|
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,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;AAGD,eAAeA,aAAaA,CAACC,IAAS,EAAkC;EAAA,IAAhCH,OAAO,GAAAI,SAAA,CAAAC,MAAA,QAAAD,SAAA,QAAAE,SAAA,GAAAF,SAAA,MAAG,CAAC,CAAC;EAClD,MAAMG,QAAwB,GAAG,EAAE;EACnC,MAAMC,OAAoC,GAAG,CAAC,CAAC;EAE/C,IAAI;IACF,MAAMC,KAAK,GAAG,IAAIpB,KAAK,CAAC,CAAC;IAEzB,MAAMqB,GAAG,GAAG,MAAMD,KAAK,CAACE,SAAS,CAACR,IAAI,EAAEH,OAAO,CAAC;IAGhDU,GAAG,CAACE,OAAO,CAAC,CAACC,YAAY,EAAEC,QAAQ,KAAK;MACtC,MAAMC,WAAW,GAAGD,QAAQ,CAACpB,IAAI;MAEjC,MAAMsB,OAAO,GAAGC,YAAY,CAACR,KAAK,EAAEM,WAAW,EAAEf,OAAO,CAAC,CAACkB,IAAI,CAAEC,kBAAkB,IAAK;QACrFX,OAAO,CAACK,YAAY,CAAC,GAAGM,kBAAkB;MAC5C,CAAC,CAAC;MAGFZ,QAAQ,CAACa,IAAI,CAACJ,OAAO,CAAC;IACxB,CAAC,CAAC;IAEF,MAAMK,OAAO,CAACC,GAAG,CAACf,QAAQ,CAAC;IAC3B,OAAOC,OAAO;EAChB,CAAC,CAAC,OAAOe,KAAK,EAAE;IAEdvB,OAAO,CAACwB,GAAG,CAACD,KAAK,gCAAAE,MAAA,CAAgCF,KAAK,CAAE,CAAC;IACzD,MAAMA,KAAK;EACb;AACF;AAEA,eAAeN,YAAYA,CAACR,KAAU,EAAEM,WAAmB,EAAqB;EAAA,IAAnBf,OAAY,GAAAI,SAAA,CAAAC,MAAA,QAAAD,SAAA,QAAAE,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.24",
|
|
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.24",
|
|
34
|
+
"@loaders.gl/loader-utils": "4.0.0-alpha.24",
|
|
35
35
|
"jszip": "^3.1.5"
|
|
36
36
|
},
|
|
37
|
-
"gitHead": "
|
|
37
|
+
"gitHead": "97a8990595c132fb14e3445a8768d9f4cb98ff05"
|
|
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;
|
package/dist/index.js
DELETED
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
// loaders.gl, MIT license
|
|
3
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
-
exports.ZipFileSystem = exports.generateHashInfo = exports.findBin = exports.parseHashFile = exports.compareHashes = exports.searchFromTheEnd = exports.parseEoCDRecord = exports.localHeaderSignature = exports.parseZipLocalFileHeader = exports.cdSignature = exports.zipCDFileHeaderGenerator = exports.parseZipCDFileHeader = exports.TarBuilder = exports.ZipWriter = exports.ZipLoader = void 0;
|
|
5
|
-
var zip_loader_1 = require("./zip-loader");
|
|
6
|
-
Object.defineProperty(exports, "ZipLoader", { enumerable: true, get: function () { return zip_loader_1.ZipLoader; } });
|
|
7
|
-
var zip_writer_1 = require("./zip-writer");
|
|
8
|
-
Object.defineProperty(exports, "ZipWriter", { enumerable: true, get: function () { return zip_writer_1.ZipWriter; } });
|
|
9
|
-
var tar_builder_1 = require("./tar-builder");
|
|
10
|
-
Object.defineProperty(exports, "TarBuilder", { enumerable: true, get: function () { return tar_builder_1.TarBuilder; } });
|
|
11
|
-
var cd_file_header_1 = require("./parse-zip/cd-file-header");
|
|
12
|
-
Object.defineProperty(exports, "parseZipCDFileHeader", { enumerable: true, get: function () { return cd_file_header_1.parseZipCDFileHeader; } });
|
|
13
|
-
Object.defineProperty(exports, "zipCDFileHeaderGenerator", { enumerable: true, get: function () { return cd_file_header_1.zipCDFileHeaderGenerator; } });
|
|
14
|
-
Object.defineProperty(exports, "cdSignature", { enumerable: true, get: function () { return cd_file_header_1.signature; } });
|
|
15
|
-
var local_file_header_1 = require("./parse-zip/local-file-header");
|
|
16
|
-
Object.defineProperty(exports, "parseZipLocalFileHeader", { enumerable: true, get: function () { return local_file_header_1.parseZipLocalFileHeader; } });
|
|
17
|
-
Object.defineProperty(exports, "localHeaderSignature", { enumerable: true, get: function () { return local_file_header_1.signature; } });
|
|
18
|
-
var end_of_central_directory_1 = require("./parse-zip/end-of-central-directory");
|
|
19
|
-
Object.defineProperty(exports, "parseEoCDRecord", { enumerable: true, get: function () { return end_of_central_directory_1.parseEoCDRecord; } });
|
|
20
|
-
var search_from_the_end_1 = require("./parse-zip/search-from-the-end");
|
|
21
|
-
Object.defineProperty(exports, "searchFromTheEnd", { enumerable: true, get: function () { return search_from_the_end_1.searchFromTheEnd; } });
|
|
22
|
-
var hash_file_utility_1 = require("./hash-file-utility");
|
|
23
|
-
Object.defineProperty(exports, "compareHashes", { enumerable: true, get: function () { return hash_file_utility_1.compareHashes; } });
|
|
24
|
-
Object.defineProperty(exports, "parseHashFile", { enumerable: true, get: function () { return hash_file_utility_1.parseHashFile; } });
|
|
25
|
-
Object.defineProperty(exports, "findBin", { enumerable: true, get: function () { return hash_file_utility_1.findBin; } });
|
|
26
|
-
Object.defineProperty(exports, "generateHashInfo", { enumerable: true, get: function () { return hash_file_utility_1.generateHashInfo; } });
|
|
27
|
-
var zip_filesystem_1 = require("./filesystems/zip-filesystem");
|
|
28
|
-
Object.defineProperty(exports, "ZipFileSystem", { enumerable: true, get: function () { return zip_filesystem_1.ZipFileSystem; } });
|
package/dist/lib/tar/header.js
DELETED
|
@@ -1,99 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
-
}) : function(o, v) {
|
|
16
|
-
o["default"] = v;
|
|
17
|
-
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
-
if (mod && mod.__esModule) return mod;
|
|
20
|
-
var result = {};
|
|
21
|
-
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
-
__setModuleDefault(result, mod);
|
|
23
|
-
return result;
|
|
24
|
-
};
|
|
25
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
-
exports.format = void 0;
|
|
27
|
-
// This file is derived from the tar-js code base under MIT license
|
|
28
|
-
// See https://github.com/beatgammit/tar-js/blob/master/LICENSE
|
|
29
|
-
/*
|
|
30
|
-
* tar-js
|
|
31
|
-
* MIT (c) 2011 T. Jameson Little
|
|
32
|
-
*/
|
|
33
|
-
/* eslint-disable */
|
|
34
|
-
const utils = __importStar(require("./utils"));
|
|
35
|
-
/*
|
|
36
|
-
struct posix_header { // byte offset
|
|
37
|
-
char name[100]; // 0
|
|
38
|
-
char mode[8]; // 100
|
|
39
|
-
char uid[8]; // 108
|
|
40
|
-
char gid[8]; // 116
|
|
41
|
-
char size[12]; // 124
|
|
42
|
-
char mtime[12]; // 136
|
|
43
|
-
char chksum[8]; // 148
|
|
44
|
-
char typeflag; // 156
|
|
45
|
-
char linkname[100]; // 157
|
|
46
|
-
char magic[6]; // 257
|
|
47
|
-
char version[2]; // 263
|
|
48
|
-
char uname[32]; // 265
|
|
49
|
-
char gname[32]; // 297
|
|
50
|
-
char devmajor[8]; // 329
|
|
51
|
-
char devminor[8]; // 337
|
|
52
|
-
char prefix[155]; // 345
|
|
53
|
-
// 500
|
|
54
|
-
};
|
|
55
|
-
*/
|
|
56
|
-
const structure = {
|
|
57
|
-
fileName: 100,
|
|
58
|
-
fileMode: 8,
|
|
59
|
-
uid: 8,
|
|
60
|
-
gid: 8,
|
|
61
|
-
fileSize: 12,
|
|
62
|
-
mtime: 12,
|
|
63
|
-
checksum: 8,
|
|
64
|
-
type: 1,
|
|
65
|
-
linkName: 100,
|
|
66
|
-
ustar: 8,
|
|
67
|
-
owner: 32,
|
|
68
|
-
group: 32,
|
|
69
|
-
majorNumber: 8,
|
|
70
|
-
minorNumber: 8,
|
|
71
|
-
filenamePrefix: 155,
|
|
72
|
-
padding: 12
|
|
73
|
-
};
|
|
74
|
-
/**
|
|
75
|
-
* Getting the header
|
|
76
|
-
* @param data
|
|
77
|
-
* @param [cb]
|
|
78
|
-
* @returns {Uint8Array} | Array
|
|
79
|
-
*/
|
|
80
|
-
function format(data, cb) {
|
|
81
|
-
const buffer = utils.clean(512);
|
|
82
|
-
let offset = 0;
|
|
83
|
-
Object.entries(structure).forEach(([field, length]) => {
|
|
84
|
-
const str = data[field] || '';
|
|
85
|
-
let i;
|
|
86
|
-
let fieldLength;
|
|
87
|
-
for (i = 0, fieldLength = str.length; i < fieldLength; i += 1) {
|
|
88
|
-
buffer[offset] = str.charCodeAt(i);
|
|
89
|
-
offset += 1;
|
|
90
|
-
}
|
|
91
|
-
// space it out with nulls
|
|
92
|
-
offset += length - i;
|
|
93
|
-
});
|
|
94
|
-
if (typeof cb === 'function') {
|
|
95
|
-
return cb(buffer, offset);
|
|
96
|
-
}
|
|
97
|
-
return buffer;
|
|
98
|
-
}
|
|
99
|
-
exports.format = format;
|
package/dist/lib/tar/tar.js
DELETED
|
@@ -1,131 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
// This file is derived from the tar-js code base under MIT license
|
|
3
|
-
// See https://github.com/beatgammit/tar-js/blob/master/LICENSE
|
|
4
|
-
/*
|
|
5
|
-
* tar-js
|
|
6
|
-
* MIT (c) 2011 T. Jameson Little
|
|
7
|
-
*/
|
|
8
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
-
const utils_1 = require("./utils");
|
|
10
|
-
const header_1 = require("./header");
|
|
11
|
-
let blockSize;
|
|
12
|
-
let headerLength;
|
|
13
|
-
let inputLength;
|
|
14
|
-
const recordSize = 512;
|
|
15
|
-
class Tar {
|
|
16
|
-
/**
|
|
17
|
-
* @param [recordsPerBlock]
|
|
18
|
-
*/
|
|
19
|
-
constructor(recordsPerBlock) {
|
|
20
|
-
this.blocks = [];
|
|
21
|
-
this.written = 0;
|
|
22
|
-
blockSize = (recordsPerBlock || 20) * recordSize;
|
|
23
|
-
this.out = (0, utils_1.clean)(blockSize);
|
|
24
|
-
this.blocks = [];
|
|
25
|
-
this.length = 0;
|
|
26
|
-
this.save = this.save.bind(this);
|
|
27
|
-
this.clear = this.clear.bind(this);
|
|
28
|
-
this.append = this.append.bind(this);
|
|
29
|
-
}
|
|
30
|
-
/**
|
|
31
|
-
* Append a file to the tar archive
|
|
32
|
-
* @param filepath
|
|
33
|
-
* @param input
|
|
34
|
-
* @param [opts]
|
|
35
|
-
*/
|
|
36
|
-
// eslint-disable-next-line complexity
|
|
37
|
-
append(filepath, input, opts) {
|
|
38
|
-
let checksum;
|
|
39
|
-
if (typeof input === 'string') {
|
|
40
|
-
input = (0, utils_1.stringToUint8)(input);
|
|
41
|
-
}
|
|
42
|
-
else if (input.constructor && input.constructor !== Uint8Array.prototype.constructor) {
|
|
43
|
-
// @ts-ignore
|
|
44
|
-
const errorInputMatch = /function\s*([$A-Za-z_][0-9A-Za-z_]*)\s*\(/.exec(input.constructor.toString());
|
|
45
|
-
const errorInput = errorInputMatch && errorInputMatch[1];
|
|
46
|
-
const errorMessage = `Invalid input type. You gave me: ${errorInput}`;
|
|
47
|
-
throw errorMessage;
|
|
48
|
-
}
|
|
49
|
-
opts = opts || {};
|
|
50
|
-
const mode = opts.mode || parseInt('777', 8) & 0xfff;
|
|
51
|
-
const mtime = opts.mtime || Math.floor(Number(new Date()) / 1000);
|
|
52
|
-
const uid = opts.uid || 0;
|
|
53
|
-
const gid = opts.gid || 0;
|
|
54
|
-
const data = {
|
|
55
|
-
fileName: filepath,
|
|
56
|
-
fileMode: (0, utils_1.pad)(mode, 7),
|
|
57
|
-
uid: (0, utils_1.pad)(uid, 7),
|
|
58
|
-
gid: (0, utils_1.pad)(gid, 7),
|
|
59
|
-
fileSize: (0, utils_1.pad)(input.length, 11),
|
|
60
|
-
mtime: (0, utils_1.pad)(mtime, 11),
|
|
61
|
-
checksum: ' ',
|
|
62
|
-
// 0 = just a file
|
|
63
|
-
type: '0',
|
|
64
|
-
ustar: 'ustar ',
|
|
65
|
-
owner: opts.owner || '',
|
|
66
|
-
group: opts.group || ''
|
|
67
|
-
};
|
|
68
|
-
// calculate the checksum
|
|
69
|
-
checksum = 0;
|
|
70
|
-
Object.keys(data).forEach((key) => {
|
|
71
|
-
let i;
|
|
72
|
-
const value = data[key];
|
|
73
|
-
let length;
|
|
74
|
-
for (i = 0, length = value.length; i < length; i += 1) {
|
|
75
|
-
checksum += value.charCodeAt(i);
|
|
76
|
-
}
|
|
77
|
-
});
|
|
78
|
-
data.checksum = `${(0, utils_1.pad)(checksum, 6)}\u0000 `;
|
|
79
|
-
const headerArr = (0, header_1.format)(data);
|
|
80
|
-
headerLength = Math.ceil(headerArr.length / recordSize) * recordSize;
|
|
81
|
-
inputLength = Math.ceil(input.length / recordSize) * recordSize;
|
|
82
|
-
this.blocks.push({
|
|
83
|
-
header: headerArr,
|
|
84
|
-
input,
|
|
85
|
-
headerLength,
|
|
86
|
-
inputLength
|
|
87
|
-
});
|
|
88
|
-
}
|
|
89
|
-
/**
|
|
90
|
-
* Compiling data to a Blob object
|
|
91
|
-
* @returns {Blob}
|
|
92
|
-
*/
|
|
93
|
-
save() {
|
|
94
|
-
const buffers = [];
|
|
95
|
-
const chunks = new Array();
|
|
96
|
-
let length = 0;
|
|
97
|
-
const max = Math.pow(2, 20);
|
|
98
|
-
let chunk = new Array();
|
|
99
|
-
this.blocks.forEach((b = []) => {
|
|
100
|
-
if (length + b.headerLength + b.inputLength > max) {
|
|
101
|
-
chunks.push({ blocks: chunk, length });
|
|
102
|
-
chunk = [];
|
|
103
|
-
length = 0;
|
|
104
|
-
}
|
|
105
|
-
chunk.push(b);
|
|
106
|
-
length += b.headerLength + b.inputLength;
|
|
107
|
-
});
|
|
108
|
-
chunks.push({ blocks: chunk, length });
|
|
109
|
-
chunks.forEach((c = []) => {
|
|
110
|
-
const buffer = new Uint8Array(c.length);
|
|
111
|
-
let written = 0;
|
|
112
|
-
c.blocks.forEach((b = []) => {
|
|
113
|
-
buffer.set(b.header, written);
|
|
114
|
-
written += b.headerLength;
|
|
115
|
-
buffer.set(b.input, written);
|
|
116
|
-
written += b.inputLength;
|
|
117
|
-
});
|
|
118
|
-
buffers.push(buffer);
|
|
119
|
-
});
|
|
120
|
-
buffers.push(new Uint8Array(2 * recordSize));
|
|
121
|
-
return new Blob(buffers, { type: 'octet/stream' });
|
|
122
|
-
}
|
|
123
|
-
/**
|
|
124
|
-
* Clear the data by its blocksize
|
|
125
|
-
*/
|
|
126
|
-
clear() {
|
|
127
|
-
this.written = 0;
|
|
128
|
-
this.out = (0, utils_1.clean)(blockSize);
|
|
129
|
-
}
|
|
130
|
-
}
|
|
131
|
-
exports.default = Tar;
|
package/dist/lib/tar/types.js
DELETED
package/dist/lib/tar/utils.js
DELETED
|
@@ -1,54 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.stringToUint8 = exports.pad = exports.clean = void 0;
|
|
4
|
-
// This file is derived from the tar-js code base under MIT license
|
|
5
|
-
// See https://github.com/beatgammit/tar-js/blob/master/LICENSE
|
|
6
|
-
/*
|
|
7
|
-
* tar-js
|
|
8
|
-
* MIT (c) 2011 T. Jameson Little
|
|
9
|
-
*/
|
|
10
|
-
/**
|
|
11
|
-
* Returns the memory area specified by length
|
|
12
|
-
* @param length
|
|
13
|
-
* @returns {Uint8Array}
|
|
14
|
-
*/
|
|
15
|
-
function clean(length) {
|
|
16
|
-
let i;
|
|
17
|
-
const buffer = new Uint8Array(length);
|
|
18
|
-
for (i = 0; i < length; i += 1) {
|
|
19
|
-
buffer[i] = 0;
|
|
20
|
-
}
|
|
21
|
-
return buffer;
|
|
22
|
-
}
|
|
23
|
-
exports.clean = clean;
|
|
24
|
-
/**
|
|
25
|
-
* Converting data to a string
|
|
26
|
-
* @param num
|
|
27
|
-
* @param bytes
|
|
28
|
-
* @param base
|
|
29
|
-
* @returns string
|
|
30
|
-
*/
|
|
31
|
-
function pad(num, bytes, base) {
|
|
32
|
-
const numStr = num.toString(base || 8);
|
|
33
|
-
return '000000000000'.substr(numStr.length + 12 - bytes) + numStr;
|
|
34
|
-
}
|
|
35
|
-
exports.pad = pad;
|
|
36
|
-
/**
|
|
37
|
-
* Converting input to binary data
|
|
38
|
-
* @param input
|
|
39
|
-
* @param out
|
|
40
|
-
* @param offset
|
|
41
|
-
* @returns {Uint8Array}
|
|
42
|
-
*/
|
|
43
|
-
function stringToUint8(input, out, offset) {
|
|
44
|
-
let i;
|
|
45
|
-
let length;
|
|
46
|
-
out = out || clean(input.length);
|
|
47
|
-
offset = offset || 0;
|
|
48
|
-
for (i = 0, length = input.length; i < length; i += 1) {
|
|
49
|
-
out[offset] = input.charCodeAt(i);
|
|
50
|
-
offset += 1;
|
|
51
|
-
}
|
|
52
|
-
return out;
|
|
53
|
-
}
|
|
54
|
-
exports.stringToUint8 = stringToUint8;
|
|
@@ -1,68 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.zipCDFileHeaderGenerator = exports.parseZipCDFileHeader = exports.signature = void 0;
|
|
4
|
-
const end_of_central_directory_1 = require("./end-of-central-directory");
|
|
5
|
-
// offsets accroding to https://en.wikipedia.org/wiki/ZIP_(file_format)
|
|
6
|
-
const CD_COMPRESSED_SIZE_OFFSET = 20n;
|
|
7
|
-
const CD_UNCOMPRESSED_SIZE_OFFSET = 24n;
|
|
8
|
-
const CD_FILE_NAME_LENGTH_OFFSET = 28n;
|
|
9
|
-
const CD_EXTRA_FIELD_LENGTH_OFFSET = 30n;
|
|
10
|
-
const CD_LOCAL_HEADER_OFFSET_OFFSET = 42n;
|
|
11
|
-
const CD_FILE_NAME_OFFSET = 46n;
|
|
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 + CD_COMPRESSED_SIZE_OFFSET));
|
|
24
|
-
let uncompressedSize = BigInt(await buffer.getUint32(headerOffset + CD_UNCOMPRESSED_SIZE_OFFSET));
|
|
25
|
-
const extraFieldLength = await buffer.getUint16(headerOffset + CD_EXTRA_FIELD_LENGTH_OFFSET);
|
|
26
|
-
const fileNameLength = await buffer.getUint16(headerOffset + CD_FILE_NAME_LENGTH_OFFSET);
|
|
27
|
-
const fileName = new TextDecoder().decode(await buffer.slice(headerOffset + CD_FILE_NAME_OFFSET, headerOffset + CD_FILE_NAME_OFFSET + BigInt(fileNameLength)));
|
|
28
|
-
const extraOffset = headerOffset + CD_FILE_NAME_OFFSET + BigInt(fileNameLength);
|
|
29
|
-
const oldFormatOffset = await buffer.getUint32(headerOffset + 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;
|
|
56
|
-
/**
|
|
57
|
-
* Create iterator over files of zip archive
|
|
58
|
-
* @param fileProvider - file provider that provider random access to the file
|
|
59
|
-
*/
|
|
60
|
-
async function* zipCDFileHeaderGenerator(fileProvider) {
|
|
61
|
-
const { cdStartOffset } = await (0, end_of_central_directory_1.parseEoCDRecord)(fileProvider);
|
|
62
|
-
let cdHeader = await (0, exports.parseZipCDFileHeader)(cdStartOffset, fileProvider);
|
|
63
|
-
while (cdHeader) {
|
|
64
|
-
yield cdHeader;
|
|
65
|
-
cdHeader = await (0, exports.parseZipCDFileHeader)(cdHeader.extraOffset + BigInt(cdHeader.extraFieldLength), fileProvider);
|
|
66
|
-
}
|
|
67
|
-
}
|
|
68
|
-
exports.zipCDFileHeaderGenerator = zipCDFileHeaderGenerator;
|
|
@@ -1,40 +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
|
-
// offsets accroding to https://en.wikipedia.org/wiki/ZIP_(file_format)
|
|
9
|
-
const CD_RECORDS_NUMBER_OFFSET = 8n;
|
|
10
|
-
const CD_START_OFFSET_OFFSET = 16n;
|
|
11
|
-
const ZIP64_EOCD_START_OFFSET_OFFSET = 8n;
|
|
12
|
-
const ZIP64_CD_RECORDS_NUMBER_OFFSET = 24n;
|
|
13
|
-
const ZIP64_CD_START_OFFSET_OFFSET = 48n;
|
|
14
|
-
/**
|
|
15
|
-
* Parses end of central directory record of zip file
|
|
16
|
-
* @param fileProvider - FileProvider instance
|
|
17
|
-
* @returns Info from the header
|
|
18
|
-
*/
|
|
19
|
-
const parseEoCDRecord = async (fileProvider) => {
|
|
20
|
-
const zipEoCDOffset = await (0, search_from_the_end_1.searchFromTheEnd)(fileProvider, eoCDSignature);
|
|
21
|
-
let cdRecordsNumber = BigInt(await fileProvider.getUint16(zipEoCDOffset + CD_RECORDS_NUMBER_OFFSET));
|
|
22
|
-
let cdStartOffset = BigInt(await fileProvider.getUint32(zipEoCDOffset + CD_START_OFFSET_OFFSET));
|
|
23
|
-
if (cdStartOffset === BigInt(0xffffffff) || cdRecordsNumber === BigInt(0xffffffff)) {
|
|
24
|
-
const zip64EoCDLocatorOffset = zipEoCDOffset - 20n;
|
|
25
|
-
if (Buffer.from(await fileProvider.slice(zip64EoCDLocatorOffset, zip64EoCDLocatorOffset + 4n)).compare(zip64EoCDLocatorSignature) !== 0) {
|
|
26
|
-
throw new Error('zip64 EoCD locator not found');
|
|
27
|
-
}
|
|
28
|
-
const zip64EoCDOffset = await fileProvider.getBigUint64(zip64EoCDLocatorOffset + ZIP64_EOCD_START_OFFSET_OFFSET);
|
|
29
|
-
if (Buffer.from(await fileProvider.slice(zip64EoCDOffset, zip64EoCDOffset + 4n)).compare(zip64EoCDSignature) !== 0) {
|
|
30
|
-
throw new Error('zip64 EoCD not found');
|
|
31
|
-
}
|
|
32
|
-
cdRecordsNumber = await fileProvider.getBigUint64(zip64EoCDOffset + ZIP64_CD_RECORDS_NUMBER_OFFSET);
|
|
33
|
-
cdStartOffset = await fileProvider.getBigUint64(zip64EoCDOffset + ZIP64_CD_START_OFFSET_OFFSET);
|
|
34
|
-
}
|
|
35
|
-
return {
|
|
36
|
-
cdRecordsNumber,
|
|
37
|
-
cdStartOffset
|
|
38
|
-
};
|
|
39
|
-
};
|
|
40
|
-
exports.parseEoCDRecord = parseEoCDRecord;
|
|
@@ -1,55 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.parseZipLocalFileHeader = exports.signature = void 0;
|
|
4
|
-
// offsets accroding to https://en.wikipedia.org/wiki/ZIP_(file_format)
|
|
5
|
-
const COMPRESSION_METHOD_OFFSET = 8n;
|
|
6
|
-
const COMPRESSED_SIZE_OFFSET = 18n;
|
|
7
|
-
const UNCOMPRESSED_SIZE_OFFSET = 22n;
|
|
8
|
-
const FILE_NAME_LENGTH_OFFSET = 26n;
|
|
9
|
-
const EXTRA_FIELD_LENGTH_OFFSET = 28n;
|
|
10
|
-
const FILE_NAME_OFFSET = 30n;
|
|
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 + FILE_NAME_LENGTH_OFFSET);
|
|
23
|
-
const fileName = new TextDecoder()
|
|
24
|
-
.decode(await buffer.slice(headerOffset + FILE_NAME_OFFSET, headerOffset + FILE_NAME_OFFSET + BigInt(fileNameLength)))
|
|
25
|
-
.split('\\')
|
|
26
|
-
.join('/');
|
|
27
|
-
const extraFieldLength = await buffer.getUint16(headerOffset + EXTRA_FIELD_LENGTH_OFFSET);
|
|
28
|
-
let fileDataOffset = headerOffset + FILE_NAME_OFFSET + BigInt(fileNameLength + extraFieldLength);
|
|
29
|
-
const compressionMethod = await buffer.getUint16(headerOffset + COMPRESSION_METHOD_OFFSET);
|
|
30
|
-
let compressedSize = BigInt(await buffer.getUint32(headerOffset + COMPRESSED_SIZE_OFFSET)); // add zip 64 logic
|
|
31
|
-
let uncompressedSize = BigInt(await buffer.getUint32(headerOffset + UNCOMPRESSED_SIZE_OFFSET)); // add zip 64 logic
|
|
32
|
-
const extraOffset = headerOffset + FILE_NAME_OFFSET + BigInt(fileNameLength);
|
|
33
|
-
let offsetInZip64Data = 4n;
|
|
34
|
-
// looking for info that might be also be in zip64 extra field
|
|
35
|
-
if (uncompressedSize === BigInt(0xffffffff)) {
|
|
36
|
-
uncompressedSize = await buffer.getBigUint64(extraOffset + offsetInZip64Data);
|
|
37
|
-
offsetInZip64Data += 8n;
|
|
38
|
-
}
|
|
39
|
-
if (compressedSize === BigInt(0xffffffff)) {
|
|
40
|
-
compressedSize = await buffer.getBigUint64(extraOffset + offsetInZip64Data);
|
|
41
|
-
offsetInZip64Data += 8n;
|
|
42
|
-
}
|
|
43
|
-
if (fileDataOffset === BigInt(0xffffffff)) {
|
|
44
|
-
fileDataOffset = await buffer.getBigUint64(extraOffset + offsetInZip64Data); // setting it to the one from zip64
|
|
45
|
-
}
|
|
46
|
-
return {
|
|
47
|
-
fileNameLength,
|
|
48
|
-
fileName,
|
|
49
|
-
extraFieldLength,
|
|
50
|
-
fileDataOffset,
|
|
51
|
-
compressedSize,
|
|
52
|
-
compressionMethod
|
|
53
|
-
};
|
|
54
|
-
};
|
|
55
|
-
exports.parseZipLocalFileHeader = parseZipLocalFileHeader;
|
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.searchFromTheEnd = void 0;
|
|
4
|
-
/**
|
|
5
|
-
* looking for the last occurrence of the provided
|
|
6
|
-
* @param file
|
|
7
|
-
* @param target
|
|
8
|
-
* @returns
|
|
9
|
-
*/
|
|
10
|
-
const searchFromTheEnd = async (file, target) => {
|
|
11
|
-
const searchWindow = [
|
|
12
|
-
await file.getUint8(file.length - 1n),
|
|
13
|
-
await file.getUint8(file.length - 2n),
|
|
14
|
-
await file.getUint8(file.length - 3n),
|
|
15
|
-
undefined
|
|
16
|
-
];
|
|
17
|
-
let targetOffset = 0n;
|
|
18
|
-
// looking for the last record in the central directory
|
|
19
|
-
for (let i = file.length - 4n; i > -1; i--) {
|
|
20
|
-
searchWindow[3] = searchWindow[2];
|
|
21
|
-
searchWindow[2] = searchWindow[1];
|
|
22
|
-
searchWindow[1] = searchWindow[0];
|
|
23
|
-
searchWindow[0] = await file.getUint8(i);
|
|
24
|
-
if (searchWindow.every((val, index) => val === target[index])) {
|
|
25
|
-
targetOffset = i;
|
|
26
|
-
break;
|
|
27
|
-
}
|
|
28
|
-
}
|
|
29
|
-
return targetOffset;
|
|
30
|
-
};
|
|
31
|
-
exports.searchFromTheEnd = searchFromTheEnd;
|
package/dist/tar-builder.js
DELETED
|
@@ -1,39 +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.TarBuilder = void 0;
|
|
7
|
-
const tar_1 = __importDefault(require("./lib/tar/tar"));
|
|
8
|
-
const TAR_BUILDER_OPTIONS = {
|
|
9
|
-
recordsPerBlock: 20
|
|
10
|
-
};
|
|
11
|
-
/**
|
|
12
|
-
* Build a tar file by adding files
|
|
13
|
-
*/
|
|
14
|
-
class TarBuilder {
|
|
15
|
-
static get properties() {
|
|
16
|
-
return {
|
|
17
|
-
id: 'tar',
|
|
18
|
-
name: 'TAR',
|
|
19
|
-
extensions: ['tar'],
|
|
20
|
-
mimeTypes: ['application/x-tar'],
|
|
21
|
-
builder: TarBuilder,
|
|
22
|
-
options: TAR_BUILDER_OPTIONS
|
|
23
|
-
};
|
|
24
|
-
}
|
|
25
|
-
constructor(options) {
|
|
26
|
-
this.count = 0;
|
|
27
|
-
this.options = { ...TAR_BUILDER_OPTIONS, ...options };
|
|
28
|
-
this.tape = new tar_1.default(this.options.recordsPerBlock);
|
|
29
|
-
}
|
|
30
|
-
/** Adds a file to the archive. */
|
|
31
|
-
addFile(filename, buffer) {
|
|
32
|
-
this.tape.append(filename, new Uint8Array(buffer));
|
|
33
|
-
this.count++;
|
|
34
|
-
}
|
|
35
|
-
async build() {
|
|
36
|
-
return new Response(this.tape.save()).arrayBuffer();
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
exports.TarBuilder = TarBuilder;
|
package/dist/zip-loader.js
DELETED
|
@@ -1,60 +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.ZipLoader = void 0;
|
|
7
|
-
const jszip_1 = __importDefault(require("jszip"));
|
|
8
|
-
// __VERSION__ is injected by babel-plugin-version-inline
|
|
9
|
-
// @ts-ignore TS2304: Cannot find name '__VERSION__'.
|
|
10
|
-
const VERSION = typeof __VERSION__ !== 'undefined' ? __VERSION__ : 'latest';
|
|
11
|
-
exports.ZipLoader = {
|
|
12
|
-
id: 'zip',
|
|
13
|
-
module: 'zip',
|
|
14
|
-
name: 'Zip Archive',
|
|
15
|
-
version: VERSION,
|
|
16
|
-
extensions: ['zip'],
|
|
17
|
-
mimeTypes: ['application/zip'],
|
|
18
|
-
category: 'archive',
|
|
19
|
-
tests: ['PK'],
|
|
20
|
-
options: {},
|
|
21
|
-
parse: parseZipAsync
|
|
22
|
-
};
|
|
23
|
-
// TODO - Could return a map of promises, perhaps as an option...
|
|
24
|
-
async function parseZipAsync(data, options = {}) {
|
|
25
|
-
const promises = [];
|
|
26
|
-
const fileMap = {};
|
|
27
|
-
try {
|
|
28
|
-
const jsZip = new jszip_1.default();
|
|
29
|
-
const zip = await jsZip.loadAsync(data, options);
|
|
30
|
-
// start to load each file in this zip
|
|
31
|
-
zip.forEach((relativePath, zipEntry) => {
|
|
32
|
-
const subFilename = zipEntry.name;
|
|
33
|
-
const promise = loadZipEntry(jsZip, subFilename, options).then((arrayBufferOrError) => {
|
|
34
|
-
fileMap[relativePath] = arrayBufferOrError;
|
|
35
|
-
});
|
|
36
|
-
// Ensure Promise.all doesn't ignore rejected promises.
|
|
37
|
-
promises.push(promise);
|
|
38
|
-
});
|
|
39
|
-
await Promise.all(promises);
|
|
40
|
-
return fileMap;
|
|
41
|
-
}
|
|
42
|
-
catch (error) {
|
|
43
|
-
// @ts-ignore
|
|
44
|
-
options.log.error(`Unable to read zip archive: ${error}`);
|
|
45
|
-
throw error;
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
async function loadZipEntry(jsZip, subFilename, options = {}) {
|
|
49
|
-
// jszip supports both arraybuffer and text, the main loaders.gl types
|
|
50
|
-
// https://stuk.github.io/jszip/documentation/api_zipobject/async.html
|
|
51
|
-
try {
|
|
52
|
-
const arrayBuffer = await jsZip.file(subFilename).async(options.dataType || 'arraybuffer');
|
|
53
|
-
return arrayBuffer;
|
|
54
|
-
}
|
|
55
|
-
catch (error) {
|
|
56
|
-
options.log.error(`Unable to read ${subFilename} from zip archive: ${error}`);
|
|
57
|
-
// Store error in place of data in map
|
|
58
|
-
return error;
|
|
59
|
-
}
|
|
60
|
-
}
|
package/dist/zip-writer.js
DELETED
|
@@ -1,37 +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.ZipWriter = void 0;
|
|
7
|
-
const jszip_1 = __importDefault(require("jszip"));
|
|
8
|
-
/**
|
|
9
|
-
* Zip exporter
|
|
10
|
-
*/
|
|
11
|
-
exports.ZipWriter = {
|
|
12
|
-
name: 'Zip Archive',
|
|
13
|
-
extensions: ['zip'],
|
|
14
|
-
category: 'archive',
|
|
15
|
-
mimeTypes: ['application/zip'],
|
|
16
|
-
// @ts-ignore
|
|
17
|
-
encode: encodeZipAsync
|
|
18
|
-
};
|
|
19
|
-
async function encodeZipAsync(fileMap, options = {}) {
|
|
20
|
-
const jsZip = new jszip_1.default();
|
|
21
|
-
// add files to the zip
|
|
22
|
-
for (const subFileName in fileMap) {
|
|
23
|
-
const subFileData = fileMap[subFileName];
|
|
24
|
-
// jszip supports both arraybuffer and string data (the main loaders.gl types)
|
|
25
|
-
// https://stuk.github.io/jszip/documentation/api_zipobject/async.html
|
|
26
|
-
jsZip.file(subFileName, subFileData, options);
|
|
27
|
-
}
|
|
28
|
-
// always generate the full zip as an arraybuffer
|
|
29
|
-
options = Object.assign({}, options, {
|
|
30
|
-
type: 'arraybuffer'
|
|
31
|
-
});
|
|
32
|
-
const { onUpdate = () => { } } = options;
|
|
33
|
-
return jsZip.generateAsync(options, onUpdate).catch((error) => {
|
|
34
|
-
options.log.error(`Unable to write zip archive: ${error}`);
|
|
35
|
-
throw error;
|
|
36
|
-
});
|
|
37
|
-
}
|