@loaders.gl/zip 4.0.0-alpha.5 → 4.0.0-alpha.6

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 (63) hide show
  1. package/dist/bundle.js +2 -2
  2. package/dist/dist.min.js +2662 -3064
  3. package/dist/es5/bundle.js +6 -0
  4. package/dist/es5/bundle.js.map +1 -0
  5. package/dist/es5/index.js +28 -0
  6. package/dist/es5/index.js.map +1 -0
  7. package/dist/es5/lib/tar/header.js +52 -0
  8. package/dist/es5/lib/tar/header.js.map +1 -0
  9. package/dist/es5/lib/tar/tar.js +137 -0
  10. package/dist/es5/lib/tar/tar.js.map +1 -0
  11. package/dist/es5/lib/tar/types.js +2 -0
  12. package/dist/es5/lib/tar/types.js.map +1 -0
  13. package/dist/es5/lib/tar/utils.js +32 -0
  14. package/dist/es5/lib/tar/utils.js.map +1 -0
  15. package/dist/es5/tar-builder.js +69 -0
  16. package/dist/es5/tar-builder.js.map +1 -0
  17. package/dist/es5/zip-loader.js +105 -0
  18. package/dist/es5/zip-loader.js.map +1 -0
  19. package/dist/es5/zip-writer.js +57 -0
  20. package/dist/es5/zip-writer.js.map +1 -0
  21. package/dist/esm/bundle.js +4 -0
  22. package/dist/esm/bundle.js.map +1 -0
  23. package/dist/esm/index.js +4 -0
  24. package/dist/esm/index.js.map +1 -0
  25. package/dist/esm/lib/tar/header.js +39 -0
  26. package/dist/esm/lib/tar/header.js.map +1 -0
  27. package/dist/esm/lib/tar/tar.js +118 -0
  28. package/dist/esm/lib/tar/tar.js.map +1 -0
  29. package/dist/esm/lib/tar/types.js +2 -0
  30. package/dist/esm/lib/tar/types.js.map +1 -0
  31. package/dist/esm/lib/tar/utils.js +24 -0
  32. package/dist/esm/lib/tar/utils.js.map +1 -0
  33. package/dist/esm/tar-builder.js +35 -0
  34. package/dist/esm/tar-builder.js.map +1 -0
  35. package/dist/esm/zip-loader.js +47 -0
  36. package/dist/esm/zip-loader.js.map +1 -0
  37. package/dist/esm/zip-writer.js +27 -0
  38. package/dist/esm/zip-writer.js.map +1 -0
  39. package/dist/index.js +12 -4
  40. package/dist/lib/tar/header.js +95 -38
  41. package/dist/lib/tar/tar.js +123 -121
  42. package/dist/lib/tar/types.d.ts +6 -6
  43. package/dist/lib/tar/types.d.ts.map +1 -1
  44. package/dist/lib/tar/types.js +2 -2
  45. package/dist/lib/tar/utils.js +51 -25
  46. package/dist/tar-builder.d.ts +1 -1
  47. package/dist/tar-builder.d.ts.map +1 -1
  48. package/dist/tar-builder.js +35 -38
  49. package/dist/zip-loader.d.ts +3 -15
  50. package/dist/zip-loader.d.ts.map +1 -1
  51. package/dist/zip-loader.js +56 -44
  52. package/dist/zip-writer.js +34 -26
  53. package/package.json +4 -4
  54. package/src/zip-loader.ts +4 -4
  55. package/dist/bundle.js.map +0 -1
  56. package/dist/index.js.map +0 -1
  57. package/dist/lib/tar/header.js.map +0 -1
  58. package/dist/lib/tar/tar.js.map +0 -1
  59. package/dist/lib/tar/types.js.map +0 -1
  60. package/dist/lib/tar/utils.js.map +0 -1
  61. package/dist/tar-builder.js.map +0 -1
  62. package/dist/zip-loader.js.map +0 -1
  63. package/dist/zip-writer.js.map +0 -1
@@ -1,129 +1,131 @@
1
- import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
2
- import { clean, pad, stringToUint8 } from './utils';
3
- import { format } from './header';
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");
4
11
  let blockSize;
5
12
  let headerLength;
6
13
  let inputLength;
7
14
  const recordSize = 512;
8
-
9
15
  class Tar {
10
- constructor(recordsPerBlock) {
11
- _defineProperty(this, "written", void 0);
12
-
13
- _defineProperty(this, "out", void 0);
14
-
15
- _defineProperty(this, "blocks", []);
16
-
17
- _defineProperty(this, "length", void 0);
18
-
19
- this.written = 0;
20
- blockSize = (recordsPerBlock || 20) * recordSize;
21
- this.out = clean(blockSize);
22
- this.blocks = [];
23
- this.length = 0;
24
- this.save = this.save.bind(this);
25
- this.clear = this.clear.bind(this);
26
- this.append = this.append.bind(this);
27
- }
28
-
29
- append(filepath, input, opts) {
30
- let checksum;
31
-
32
- if (typeof input === 'string') {
33
- input = stringToUint8(input);
34
- } else if (input.constructor && input.constructor !== Uint8Array.prototype.constructor) {
35
- const errorInputMatch = /function\s*([$A-Za-z_][0-9A-Za-z_]*)\s*\(/.exec(input.constructor.toString());
36
- const errorInput = errorInputMatch && errorInputMatch[1];
37
- const errorMessage = "Invalid input type. You gave me: ".concat(errorInput);
38
- throw errorMessage;
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);
39
29
  }
40
-
41
- opts = opts || {};
42
- const mode = opts.mode || parseInt('777', 8) & 0xfff;
43
- const mtime = opts.mtime || Math.floor(Number(new Date()) / 1000);
44
- const uid = opts.uid || 0;
45
- const gid = opts.gid || 0;
46
- const data = {
47
- fileName: filepath,
48
- fileMode: pad(mode, 7),
49
- uid: pad(uid, 7),
50
- gid: pad(gid, 7),
51
- fileSize: pad(input.length, 11),
52
- mtime: pad(mtime, 11),
53
- checksum: ' ',
54
- type: '0',
55
- ustar: 'ustar ',
56
- owner: opts.owner || '',
57
- group: opts.group || ''
58
- };
59
- checksum = 0;
60
- Object.keys(data).forEach(key => {
61
- let i;
62
- const value = data[key];
63
- let length;
64
-
65
- for (i = 0, length = value.length; i < length; i += 1) {
66
- checksum += value.charCodeAt(i);
67
- }
68
- });
69
- data.checksum = "".concat(pad(checksum, 6), "\0 ");
70
- const headerArr = format(data);
71
- headerLength = Math.ceil(headerArr.length / recordSize) * recordSize;
72
- inputLength = Math.ceil(input.length / recordSize) * recordSize;
73
- this.blocks.push({
74
- header: headerArr,
75
- input,
76
- headerLength,
77
- inputLength
78
- });
79
- }
80
-
81
- save() {
82
- const buffers = [];
83
- const chunks = new Array();
84
- let length = 0;
85
- const max = Math.pow(2, 20);
86
- let chunk = new Array();
87
- this.blocks.forEach((b = []) => {
88
- if (length + b.headerLength + b.inputLength > max) {
89
- chunks.push({
90
- blocks: chunk,
91
- length
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
+ }
92
77
  });
93
- chunk = [];
94
- length = 0;
95
- }
96
-
97
- chunk.push(b);
98
- length += b.headerLength + b.inputLength;
99
- });
100
- chunks.push({
101
- blocks: chunk,
102
- length
103
- });
104
- chunks.forEach((c = []) => {
105
- const buffer = new Uint8Array(c.length);
106
- let written = 0;
107
- c.blocks.forEach((b = []) => {
108
- buffer.set(b.header, written);
109
- written += b.headerLength;
110
- buffer.set(b.input, written);
111
- written += b.inputLength;
112
- });
113
- buffers.push(buffer);
114
- });
115
- buffers.push(new Uint8Array(2 * recordSize));
116
- return new Blob(buffers, {
117
- type: 'octet/stream'
118
- });
119
- }
120
-
121
- clear() {
122
- this.written = 0;
123
- this.out = clean(blockSize);
124
- }
125
-
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
+ }
126
130
  }
127
-
128
- export default Tar;
129
- //# sourceMappingURL=tar.js.map
131
+ exports.default = Tar;
@@ -1,19 +1,19 @@
1
1
  /**
2
2
  * Structure of data
3
3
  */
4
- export declare type TarStructure = {
4
+ export type TarStructure = {
5
5
  [index: string]: number;
6
6
  };
7
7
  /**
8
8
  * Image of input data
9
9
  */
10
- export declare type TarData = {
10
+ export type TarData = {
11
11
  [index: string]: string | any;
12
12
  };
13
13
  /**
14
14
  * Describes inner content of the blocks in the Tar's constructor
15
15
  */
16
- export declare type TarBlocks = {
16
+ export type TarBlocks = {
17
17
  [index: string]: any;
18
18
  header?: Uint8Array;
19
19
  input?: string | Uint8Array;
@@ -23,7 +23,7 @@ export declare type TarBlocks = {
23
23
  /**
24
24
  * Describes additional options for Tar class
25
25
  */
26
- export declare type TarOptions = {
26
+ export type TarOptions = {
27
27
  mode?: number;
28
28
  mtime?: number;
29
29
  uid?: number;
@@ -34,13 +34,13 @@ export declare type TarOptions = {
34
34
  /**
35
35
  * Array of numbers for TarChunks
36
36
  */
37
- export declare type TarChunk = {
37
+ export type TarChunk = {
38
38
  [index: number]: any;
39
39
  };
40
40
  /**
41
41
  * Sections of binary data inside the Tar class
42
42
  */
43
- export declare type TarChunks = {
43
+ export type TarChunks = {
44
44
  [index: number]: TarChunk;
45
45
  length?: number;
46
46
  blocks?: any;
@@ -1 +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"}
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/lib/tar/types.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,MAAM,MAAM,YAAY,GAAG;IACzB,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAAC;CACzB,CAAC;AACF;;GAEG;AACH,MAAM,MAAM,OAAO,GAAG;IACpB,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,GAAG,GAAG,CAAC;CAC/B,CAAC;AACF;;GAEG;AACH,MAAM,MAAM,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,MAAM,MAAM,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,MAAM,MAAM,QAAQ,GAAG;IACrB,CAAC,KAAK,EAAE,MAAM,GAAG,GAAG,CAAC;CACtB,CAAC;AACF;;GAEG;AACH,MAAM,MAAM,SAAS,GAAG;IACtB,CAAC,KAAK,EAAE,MAAM,GAAG,QAAQ,CAAC;IAC1B,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,MAAM,CAAC,EAAE,GAAG,CAAC;CACd,CAAC"}
@@ -1,2 +1,2 @@
1
- export {};
2
- //# sourceMappingURL=types.js.map
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -1,28 +1,54 @@
1
- export function clean(length) {
2
- let i;
3
- const buffer = new Uint8Array(length);
4
-
5
- for (i = 0; i < length; i += 1) {
6
- buffer[i] = 0;
7
- }
8
-
9
- return buffer;
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;
10
22
  }
11
- export function pad(num, bytes, base) {
12
- const numStr = num.toString(base || 8);
13
- return '000000000000'.substr(numStr.length + 12 - bytes) + numStr;
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;
14
34
  }
15
- export function stringToUint8(input, out, offset) {
16
- let i;
17
- let length;
18
- out = out || clean(input.length);
19
- offset = offset || 0;
20
-
21
- for (i = 0, length = input.length; i < length; i += 1) {
22
- out[offset] = input.charCodeAt(i);
23
- offset += 1;
24
- }
25
-
26
- return out;
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;
27
53
  }
28
- //# sourceMappingURL=utils.js.map
54
+ exports.stringToUint8 = stringToUint8;
@@ -1,5 +1,5 @@
1
1
  import Tar from './lib/tar/tar';
2
- declare type TarBuilderOptions = {
2
+ type TarBuilderOptions = {
3
3
  recordsPerBlock?: number;
4
4
  };
5
5
  /**
@@ -1 +1 @@
1
- {"version":3,"file":"tar-builder.d.ts","sourceRoot":"","sources":["../src/tar-builder.ts"],"names":[],"mappings":"AAAA,OAAO,GAAG,MAAM,eAAe,CAAC;AAMhC,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"}
1
+ {"version":3,"file":"tar-builder.d.ts","sourceRoot":"","sources":["../src/tar-builder.ts"],"names":[],"mappings":"AAAA,OAAO,GAAG,MAAM,eAAe,CAAC;AAMhC,KAAK,iBAAiB,GAAG;IACvB,eAAe,CAAC,EAAE,MAAM,CAAC;CAC1B,CAAC;AAEF;;GAEG;AACH,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"}
@@ -1,41 +1,38 @@
1
- import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
2
- import Tar from './lib/tar/tar';
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"));
3
7
  const TAR_BUILDER_OPTIONS = {
4
- recordsPerBlock: 20
8
+ recordsPerBlock: 20
5
9
  };
6
- export default class TARBuilder {
7
- static get properties() {
8
- return {
9
- id: 'tar',
10
- name: 'TAR',
11
- extensions: ['tar'],
12
- mimeTypes: ['application/x-tar'],
13
- builder: TARBuilder,
14
- options: TAR_BUILDER_OPTIONS
15
- };
16
- }
17
-
18
- constructor(options) {
19
- _defineProperty(this, "options", void 0);
20
-
21
- _defineProperty(this, "tape", void 0);
22
-
23
- _defineProperty(this, "count", 0);
24
-
25
- this.options = { ...TAR_BUILDER_OPTIONS,
26
- ...options
27
- };
28
- this.tape = new Tar(this.options.recordsPerBlock);
29
- }
30
-
31
- addFile(filename, buffer) {
32
- this.tape.append(filename, new Uint8Array(buffer));
33
- this.count++;
34
- }
35
-
36
- async build() {
37
- return new Response(this.tape.save()).arrayBuffer();
38
- }
39
-
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
+ }
40
37
  }
41
- //# sourceMappingURL=tar-builder.js.map
38
+ exports.default = TARBuilder;
@@ -1,18 +1,6 @@
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>;
1
+ import type { LoaderWithParser, LoaderOptions } from '@loaders.gl/loader-utils';
2
+ type FileMap = Record<string, ArrayBuffer>;
3
+ export declare const ZipLoader: LoaderWithParser<FileMap, never, LoaderOptions>;
16
4
  export declare const _typecheckZipLoader: LoaderWithParser;
17
5
  export {};
18
6
  //# sourceMappingURL=zip-loader.d.ts.map
@@ -1 +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"}
1
+ {"version":3,"file":"zip-loader.d.ts","sourceRoot":"","sources":["../src/zip-loader.ts"],"names":[],"mappings":"AACA,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;AA8CF,eAAO,MAAM,mBAAmB,EAAE,gBAA4B,CAAC"}
@@ -1,49 +1,61 @@
1
- import JSZip from 'jszip';
2
- const VERSION = typeof "4.0.0-alpha.5" !== 'undefined' ? "4.0.0-alpha.5" : 'latest';
3
- export const ZipLoader = {
4
- id: 'zip',
5
- module: 'zip',
6
- name: 'Zip Archive',
7
- version: VERSION,
8
- extensions: ['zip'],
9
- mimeTypes: ['application/zip'],
10
- category: 'archive',
11
- tests: ['PK'],
12
- options: {},
13
- parse: parseZipAsync
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
14
4
  };
15
-
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...
16
24
  async function parseZipAsync(data, options = {}) {
17
- const promises = [];
18
- const fileMap = {};
19
-
20
- try {
21
- const jsZip = new JSZip();
22
- const zip = await jsZip.loadAsync(data, options);
23
- zip.forEach((relativePath, zipEntry) => {
24
- const subFilename = zipEntry.name;
25
- const promise = loadZipEntry(jsZip, subFilename, options).then(arrayBufferOrError => {
26
- fileMap[relativePath] = arrayBufferOrError;
27
- });
28
- promises.push(promise);
29
- });
30
- await Promise.all(promises);
31
- return fileMap;
32
- } catch (error) {
33
- options.log.error("Unable to read zip archive: ".concat(error));
34
- throw error;
35
- }
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
+ }
36
47
  }
37
-
38
48
  async function loadZipEntry(jsZip, subFilename, options = {}) {
39
- try {
40
- const arrayBuffer = await jsZip.file(subFilename).async(options.dataType || 'arraybuffer');
41
- return arrayBuffer;
42
- } catch (error) {
43
- options.log.error("Unable to read ".concat(subFilename, " from zip archive: ").concat(error));
44
- return error;
45
- }
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
+ }
46
60
  }
47
-
48
- export const _typecheckZipLoader = ZipLoader;
49
- //# sourceMappingURL=zip-loader.js.map
61
+ exports._typecheckZipLoader = exports.ZipLoader;