@loaders.gl/zip 3.1.0-alpha.4 → 3.1.0-beta.3

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.
Files changed (55) hide show
  1. package/dist/bundle.d.ts +2 -0
  2. package/dist/bundle.d.ts.map +1 -0
  3. package/dist/bundle.js +3467 -0
  4. package/dist/es5/bundle.js +1 -1
  5. package/dist/es5/bundle.js.map +1 -1
  6. package/dist/es5/index.js +3 -3
  7. package/dist/es5/lib/tar/header.js +9 -19
  8. package/dist/es5/lib/tar/header.js.map +1 -1
  9. package/dist/es5/lib/tar/tar.js +100 -114
  10. package/dist/es5/lib/tar/tar.js.map +1 -1
  11. package/dist/es5/lib/tar/utils.js +5 -5
  12. package/dist/es5/lib/tar/utils.js.map +1 -1
  13. package/dist/es5/tar-builder.js +25 -60
  14. package/dist/es5/tar-builder.js.map +1 -1
  15. package/dist/es5/zip-loader.js +31 -96
  16. package/dist/es5/zip-loader.js.map +1 -1
  17. package/dist/es5/zip-writer.js +19 -49
  18. package/dist/es5/zip-writer.js.map +1 -1
  19. package/dist/esm/lib/tar/header.js.map +1 -1
  20. package/dist/esm/lib/tar/tar.js +2 -2
  21. package/dist/esm/lib/tar/tar.js.map +1 -1
  22. package/dist/esm/zip-loader.js +3 -3
  23. package/dist/esm/zip-loader.js.map +1 -1
  24. package/dist/esm/zip-writer.js +1 -1
  25. package/dist/esm/zip-writer.js.map +1 -1
  26. package/dist/index.d.ts +4 -0
  27. package/dist/index.d.ts.map +1 -0
  28. package/dist/index.js +12 -0
  29. package/dist/lib/tar/header.d.ts +9 -0
  30. package/dist/lib/tar/header.d.ts.map +1 -0
  31. package/dist/lib/tar/header.js +95 -0
  32. package/dist/lib/tar/tar.d.ts +29 -0
  33. package/dist/lib/tar/tar.d.ts.map +1 -0
  34. package/dist/lib/tar/tar.js +131 -0
  35. package/dist/lib/tar/types.d.ts +48 -0
  36. package/dist/lib/tar/types.d.ts.map +1 -0
  37. package/dist/lib/tar/types.js +2 -0
  38. package/dist/lib/tar/utils.d.ts +23 -0
  39. package/dist/lib/tar/utils.d.ts.map +1 -0
  40. package/dist/lib/tar/utils.js +54 -0
  41. package/dist/tar-builder.d.ts +28 -0
  42. package/dist/tar-builder.d.ts.map +1 -0
  43. package/dist/tar-builder.js +38 -0
  44. package/dist/zip-loader.d.ts +18 -0
  45. package/dist/zip-loader.d.ts.map +1 -0
  46. package/dist/zip-loader.js +61 -0
  47. package/dist/zip-writer.d.ts +6 -0
  48. package/dist/zip-writer.d.ts.map +1 -0
  49. package/dist/zip-writer.js +37 -0
  50. package/package.json +7 -5
  51. package/src/lib/tar/header.ts +1 -1
  52. package/src/lib/tar/tar.ts +1 -1
  53. package/src/zip-loader.ts +4 -2
  54. package/dist/dist.min.js +0 -2
  55. package/dist/dist.min.js.map +0 -1
@@ -0,0 +1,131 @@
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;
@@ -0,0 +1,48 @@
1
+ /**
2
+ * Structure of data
3
+ */
4
+ export declare type TarStructure = {
5
+ [index: string]: number;
6
+ };
7
+ /**
8
+ * Image of input data
9
+ */
10
+ export declare type TarData = {
11
+ [index: string]: string | any;
12
+ };
13
+ /**
14
+ * Describes inner content of the blocks in the Tar's constructor
15
+ */
16
+ export declare type TarBlocks = {
17
+ [index: string]: any;
18
+ header?: Uint8Array;
19
+ input?: string | Uint8Array;
20
+ headerLength?: number;
21
+ inputLength?: number;
22
+ };
23
+ /**
24
+ * Describes additional options for Tar class
25
+ */
26
+ export declare type TarOptions = {
27
+ mode?: number;
28
+ mtime?: number;
29
+ uid?: number;
30
+ gid?: number;
31
+ owner?: any;
32
+ group?: any;
33
+ };
34
+ /**
35
+ * Array of numbers for TarChunks
36
+ */
37
+ export declare type TarChunk = {
38
+ [index: number]: any;
39
+ };
40
+ /**
41
+ * Sections of binary data inside the Tar class
42
+ */
43
+ export declare type TarChunks = {
44
+ [index: number]: TarChunk;
45
+ length?: number;
46
+ blocks?: any;
47
+ };
48
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/lib/tar/types.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,oBAAY,YAAY,GAAG;IACzB,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAAC;CACzB,CAAC;AACF;;GAEG;AACH,oBAAY,OAAO,GAAG;IACpB,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,GAAG,GAAG,CAAC;CAC/B,CAAC;AACF;;GAEG;AACH,oBAAY,SAAS,GAAG;IACtB,CAAC,KAAK,EAAE,MAAM,GAAG,GAAG,CAAC;IACrB,MAAM,CAAC,EAAE,UAAU,CAAC;IACpB,KAAK,CAAC,EAAE,MAAM,GAAG,UAAU,CAAC;IAC5B,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,WAAW,CAAC,EAAE,MAAM,CAAC;CACtB,CAAC;AACF;;GAEG;AACH,oBAAY,UAAU,GAAG;IACvB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,KAAK,CAAC,EAAE,GAAG,CAAC;IACZ,KAAK,CAAC,EAAE,GAAG,CAAC;CACb,CAAC;AACF;;GAEG;AACH,oBAAY,QAAQ,GAAG;IACrB,CAAC,KAAK,EAAE,MAAM,GAAG,GAAG,CAAC;CACtB,CAAC;AACF;;GAEG;AACH,oBAAY,SAAS,GAAG;IACtB,CAAC,KAAK,EAAE,MAAM,GAAG,QAAQ,CAAC;IAC1B,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,MAAM,CAAC,EAAE,GAAG,CAAC;CACd,CAAC"}
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,23 @@
1
+ /**
2
+ * Returns the memory area specified by length
3
+ * @param length
4
+ * @returns {Uint8Array}
5
+ */
6
+ export declare function clean(length: number): Uint8Array;
7
+ /**
8
+ * Converting data to a string
9
+ * @param num
10
+ * @param bytes
11
+ * @param base
12
+ * @returns string
13
+ */
14
+ export declare function pad(num: number, bytes: number, base?: number): string;
15
+ /**
16
+ * Converting input to binary data
17
+ * @param input
18
+ * @param out
19
+ * @param offset
20
+ * @returns {Uint8Array}
21
+ */
22
+ export declare function stringToUint8(input: string, out?: Uint8Array, offset?: number): Uint8Array;
23
+ //# sourceMappingURL=utils.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../../src/lib/tar/utils.ts"],"names":[],"mappings":"AAMA;;;;GAIG;AACH,wBAAgB,KAAK,CAAC,MAAM,EAAE,MAAM,GAAG,UAAU,CAOhD;AACD;;;;;;GAMG;AACH,wBAAgB,GAAG,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,MAAM,GAAG,MAAM,CAGrE;AACD;;;;;;GAMG;AACH,wBAAgB,aAAa,CAAC,KAAK,EAAE,MAAM,EAAE,GAAG,CAAC,EAAE,UAAU,EAAE,MAAM,CAAC,EAAE,MAAM,GAAG,UAAU,CAa1F"}
@@ -0,0 +1,54 @@
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;
@@ -0,0 +1,28 @@
1
+ import Tar from './lib/tar/tar';
2
+ declare type TarBuilderOptions = {
3
+ recordsPerBlock?: number;
4
+ };
5
+ /**
6
+ * Build a tar file by adding files
7
+ */
8
+ export default class TARBuilder {
9
+ static get properties(): {
10
+ id: string;
11
+ name: string;
12
+ extensions: string[];
13
+ mimeTypes: string[];
14
+ builder: typeof TARBuilder;
15
+ options: {
16
+ recordsPerBlock: number;
17
+ };
18
+ };
19
+ options: TarBuilderOptions;
20
+ tape: Tar;
21
+ count: number;
22
+ constructor(options?: Partial<TarBuilderOptions>);
23
+ /** Adds a file to the archive. */
24
+ addFile(filename: string, buffer: ArrayBuffer): void;
25
+ build(): Promise<ArrayBuffer>;
26
+ }
27
+ export {};
28
+ //# sourceMappingURL=tar-builder.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"tar-builder.d.ts","sourceRoot":"","sources":["../src/tar-builder.ts"],"names":[],"mappings":"AAAA,OAAO,GAAG,MAAM,eAAe,CAAC;AAMhC,aAAK,iBAAiB,GAAG;IACvB,eAAe,CAAC,EAAE,MAAM,CAAC;CAC1B,CAAC;AAEF;;GAEG;AACH,MAAM,CAAC,OAAO,OAAO,UAAU;IAC7B,MAAM,KAAK,UAAU;;;;;;;;;MASpB;IAED,OAAO,EAAE,iBAAiB,CAAC;IAC3B,IAAI,EAAE,GAAG,CAAC;IACV,KAAK,EAAE,MAAM,CAAK;gBAEN,OAAO,CAAC,EAAE,OAAO,CAAC,iBAAiB,CAAC;IAIhD,kCAAkC;IAClC,OAAO,CAAC,QAAQ,EAAE,MAAM,EAAE,MAAM,EAAE,WAAW;IAKvC,KAAK,IAAI,OAAO,CAAC,WAAW,CAAC;CAGpC"}
@@ -0,0 +1,38 @@
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
+ constructor(options) {
15
+ this.count = 0;
16
+ this.options = { ...TAR_BUILDER_OPTIONS, ...options };
17
+ this.tape = new tar_1.default(this.options.recordsPerBlock);
18
+ }
19
+ static get properties() {
20
+ return {
21
+ id: 'tar',
22
+ name: 'TAR',
23
+ extensions: ['tar'],
24
+ mimeTypes: ['application/x-tar'],
25
+ builder: TARBuilder,
26
+ options: TAR_BUILDER_OPTIONS
27
+ };
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;
@@ -0,0 +1,18 @@
1
+ import type { LoaderWithParser } from '@loaders.gl/loader-utils';
2
+ export declare const ZipLoader: {
3
+ id: string;
4
+ module: string;
5
+ name: string;
6
+ version: any;
7
+ extensions: string[];
8
+ mimeTypes: string[];
9
+ category: string;
10
+ tests: string[];
11
+ options: {};
12
+ parse: typeof parseZipAsync;
13
+ };
14
+ declare type FileMap = Record<string, ArrayBuffer>;
15
+ declare function parseZipAsync(data: any, options?: {}): Promise<FileMap>;
16
+ export declare const _typecheckZipLoader: LoaderWithParser;
17
+ export {};
18
+ //# sourceMappingURL=zip-loader.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"zip-loader.d.ts","sourceRoot":"","sources":["../src/zip-loader.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAC,gBAAgB,EAAC,MAAM,0BAA0B,CAAC;AAO/D,eAAO,MAAM,SAAS;;;;;;;;;;;CAWrB,CAAC;AAEF,aAAK,OAAO,GAAG,MAAM,CAAC,MAAM,EAAE,WAAW,CAAC,CAAC;AAG3C,iBAAe,aAAa,CAAC,IAAI,EAAE,GAAG,EAAE,OAAO,KAAK,GAAG,OAAO,CAAC,OAAO,CAAC,CA4BtE;AAeD,eAAO,MAAM,mBAAmB,EAAE,gBAA4B,CAAC"}
@@ -0,0 +1,61 @@
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;
@@ -0,0 +1,6 @@
1
+ import type { Writer } from '@loaders.gl/loader-utils';
2
+ /**
3
+ * Zip exporter
4
+ */
5
+ export declare const ZipWriter: Writer;
6
+ //# sourceMappingURL=zip-writer.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"zip-writer.d.ts","sourceRoot":"","sources":["../src/zip-writer.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAC,MAAM,EAAC,MAAM,0BAA0B,CAAC;AAGrD;;GAEG;AACH,eAAO,MAAM,SAAS,EAAE,MAOvB,CAAC"}
@@ -0,0 +1,37 @@
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
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@loaders.gl/zip",
3
- "version": "3.1.0-alpha.4",
3
+ "version": "3.1.0-beta.3",
4
4
  "description": "Zip Archive Loader",
5
5
  "license": "MIT",
6
6
  "publishConfig": {
@@ -16,7 +16,7 @@
16
16
  "archive",
17
17
  "ZIP"
18
18
  ],
19
- "types": "src/index.ts",
19
+ "types": "dist/index.d.ts",
20
20
  "main": "dist/es5/index.js",
21
21
  "module": "dist/esm/index.js",
22
22
  "sideEffects": false,
@@ -27,11 +27,13 @@
27
27
  ],
28
28
  "scripts": {
29
29
  "pre-build": "npm run build-bundle",
30
- "build-bundle": "webpack --display=minimal --config ../../scripts/webpack/bundle.js"
30
+ "build-bundle": "esbuild src/bundle.ts --bundle --outfile=dist/bundle.js"
31
31
  },
32
32
  "dependencies": {
33
- "@loaders.gl/core": "3.1.0-alpha.4",
34
33
  "jszip": "^3.1.5"
35
34
  },
36
- "gitHead": "e309784af37ef9f3640c7733c7851124c72e1fa3"
35
+ "peerDependencies": {
36
+ "@loaders.gl/core": "3.1.0-beta.1"
37
+ },
38
+ "gitHead": "3537c382b3ea4e092b24b6f94c3edee72076039c"
37
39
  }
@@ -4,7 +4,7 @@
4
4
  * tar-js
5
5
  * MIT (c) 2011 T. Jameson Little
6
6
  */
7
-
7
+ /* eslint-disable */
8
8
  import * as utils from './utils';
9
9
  import type {TarStructure, TarData} from './types';
10
10
  /*
@@ -65,7 +65,7 @@ class Tar {
65
65
  const uid = opts.uid || 0;
66
66
  const gid = opts.gid || 0;
67
67
 
68
- const data = {
68
+ const data: Record<string, string> = {
69
69
  fileName: filepath,
70
70
  fileMode: pad(mode, 7),
71
71
  uid: pad(uid, 7),
package/src/zip-loader.ts CHANGED
@@ -19,10 +19,12 @@ export const ZipLoader = {
19
19
  parse: parseZipAsync
20
20
  };
21
21
 
22
+ type FileMap = Record<string, ArrayBuffer>;
23
+
22
24
  // TODO - Could return a map of promises, perhaps as an option...
23
- async function parseZipAsync(data: any, options = {}) {
25
+ async function parseZipAsync(data: any, options = {}): Promise<FileMap> {
24
26
  const promises: Promise<any>[] = [];
25
- const fileMap = {};
27
+ const fileMap: Record<string, ArrayBuffer> = {};
26
28
 
27
29
  try {
28
30
  const jsZip = new JSZip();