@loaders.gl/zip 3.4.11 → 3.4.13
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/es5/zip-loader.js +1 -1
- package/dist/esm/zip-loader.js +1 -1
- package/package.json +2 -2
- package/dist/bundle.js +0 -5
- package/dist/index.js +0 -12
- package/dist/lib/tar/header.js +0 -99
- package/dist/lib/tar/tar.js +0 -131
- package/dist/lib/tar/types.js +0 -2
- package/dist/lib/tar/utils.js +0 -54
- package/dist/tar-builder.js +0 -38
- package/dist/zip-loader.js +0 -61
- package/dist/zip-writer.js +0 -37
package/dist/es5/zip-loader.js
CHANGED
|
@@ -8,7 +8,7 @@ exports._typecheckZipLoader = 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 "3.4.
|
|
11
|
+
var VERSION = typeof "3.4.13" !== 'undefined' ? "3.4.13" : 'latest';
|
|
12
12
|
var ZipLoader = {
|
|
13
13
|
id: 'zip',
|
|
14
14
|
module: 'zip',
|
package/dist/esm/zip-loader.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@loaders.gl/zip",
|
|
3
|
-
"version": "3.4.
|
|
3
|
+
"version": "3.4.13",
|
|
4
4
|
"description": "Zip Archive Loader",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"publishConfig": {
|
|
@@ -32,5 +32,5 @@
|
|
|
32
32
|
"dependencies": {
|
|
33
33
|
"jszip": "^3.1.5"
|
|
34
34
|
},
|
|
35
|
-
"gitHead": "
|
|
35
|
+
"gitHead": "be8849c02972ce541e01720d29b976f830d6af92"
|
|
36
36
|
}
|
package/dist/bundle.js
DELETED
package/dist/index.js
DELETED
|
@@ -1,12 +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 = exports.ZipWriter = exports.ZipLoader = void 0;
|
|
7
|
-
var zip_loader_1 = require("./zip-loader");
|
|
8
|
-
Object.defineProperty(exports, "ZipLoader", { enumerable: true, get: function () { return zip_loader_1.ZipLoader; } });
|
|
9
|
-
var zip_writer_1 = require("./zip-writer");
|
|
10
|
-
Object.defineProperty(exports, "ZipWriter", { enumerable: true, get: function () { return zip_writer_1.ZipWriter; } });
|
|
11
|
-
var tar_builder_1 = require("./tar-builder");
|
|
12
|
-
Object.defineProperty(exports, "TarBuilder", { enumerable: true, get: function () { return __importDefault(tar_builder_1).default; } });
|
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;
|
package/dist/tar-builder.js
DELETED
|
@@ -1,38 +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
|
-
const tar_1 = __importDefault(require("./lib/tar/tar"));
|
|
7
|
-
const TAR_BUILDER_OPTIONS = {
|
|
8
|
-
recordsPerBlock: 20
|
|
9
|
-
};
|
|
10
|
-
/**
|
|
11
|
-
* Build a tar file by adding files
|
|
12
|
-
*/
|
|
13
|
-
class TARBuilder {
|
|
14
|
-
static get properties() {
|
|
15
|
-
return {
|
|
16
|
-
id: 'tar',
|
|
17
|
-
name: 'TAR',
|
|
18
|
-
extensions: ['tar'],
|
|
19
|
-
mimeTypes: ['application/x-tar'],
|
|
20
|
-
builder: TARBuilder,
|
|
21
|
-
options: TAR_BUILDER_OPTIONS
|
|
22
|
-
};
|
|
23
|
-
}
|
|
24
|
-
constructor(options) {
|
|
25
|
-
this.count = 0;
|
|
26
|
-
this.options = { ...TAR_BUILDER_OPTIONS, ...options };
|
|
27
|
-
this.tape = new tar_1.default(this.options.recordsPerBlock);
|
|
28
|
-
}
|
|
29
|
-
/** Adds a file to the archive. */
|
|
30
|
-
addFile(filename, buffer) {
|
|
31
|
-
this.tape.append(filename, new Uint8Array(buffer));
|
|
32
|
-
this.count++;
|
|
33
|
-
}
|
|
34
|
-
async build() {
|
|
35
|
-
return new Response(this.tape.save()).arrayBuffer();
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
-
exports.default = TARBuilder;
|
package/dist/zip-loader.js
DELETED
|
@@ -1,61 +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._typecheckZipLoader = 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
|
-
}
|
|
61
|
-
exports._typecheckZipLoader = exports.ZipLoader;
|
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
|
-
}
|