@loaders.gl/zip 4.2.0-alpha.4 → 4.2.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 (56) hide show
  1. package/dist/dist.dev.js +919 -523
  2. package/dist/dist.min.js +25 -0
  3. package/dist/filesystems/IndexedArchive.js +26 -12
  4. package/dist/filesystems/zip-filesystem.d.ts +2 -2
  5. package/dist/filesystems/zip-filesystem.d.ts.map +1 -1
  6. package/dist/filesystems/zip-filesystem.js +125 -88
  7. package/dist/hash-file-utility.d.ts +1 -1
  8. package/dist/hash-file-utility.d.ts.map +1 -1
  9. package/dist/hash-file-utility.js +85 -42
  10. package/dist/index.cjs +64 -128
  11. package/dist/index.cjs.map +7 -0
  12. package/dist/index.d.ts +12 -12
  13. package/dist/index.d.ts.map +1 -1
  14. package/dist/index.js +4 -1
  15. package/dist/lib/tar/header.d.ts +1 -1
  16. package/dist/lib/tar/header.d.ts.map +1 -1
  17. package/dist/lib/tar/header.js +69 -33
  18. package/dist/lib/tar/tar.d.ts +1 -1
  19. package/dist/lib/tar/tar.d.ts.map +1 -1
  20. package/dist/lib/tar/tar.js +124 -106
  21. package/dist/lib/tar/types.js +3 -1
  22. package/dist/lib/tar/utils.js +45 -18
  23. package/dist/parse-zip/cd-file-header.d.ts +1 -1
  24. package/dist/parse-zip/cd-file-header.d.ts.map +1 -1
  25. package/dist/parse-zip/cd-file-header.js +239 -177
  26. package/dist/parse-zip/end-of-central-directory.js +247 -158
  27. package/dist/parse-zip/local-file-header.d.ts +1 -1
  28. package/dist/parse-zip/local-file-header.d.ts.map +1 -1
  29. package/dist/parse-zip/local-file-header.js +143 -102
  30. package/dist/parse-zip/search-from-the-end.js +27 -13
  31. package/dist/parse-zip/zip-composition.js +142 -92
  32. package/dist/parse-zip/zip64-info-generation.js +64 -41
  33. package/dist/tar-builder.d.ts +1 -1
  34. package/dist/tar-builder.d.ts.map +1 -1
  35. package/dist/tar-builder.js +32 -29
  36. package/dist/zip-loader.js +52 -41
  37. package/dist/zip-writer.js +40 -40
  38. package/package.json +11 -7
  39. package/src/filesystems/zip-filesystem.ts +4 -0
  40. package/dist/filesystems/IndexedArchive.js.map +0 -1
  41. package/dist/filesystems/zip-filesystem.js.map +0 -1
  42. package/dist/hash-file-utility.js.map +0 -1
  43. package/dist/index.js.map +0 -1
  44. package/dist/lib/tar/header.js.map +0 -1
  45. package/dist/lib/tar/tar.js.map +0 -1
  46. package/dist/lib/tar/types.js.map +0 -1
  47. package/dist/lib/tar/utils.js.map +0 -1
  48. package/dist/parse-zip/cd-file-header.js.map +0 -1
  49. package/dist/parse-zip/end-of-central-directory.js.map +0 -1
  50. package/dist/parse-zip/local-file-header.js.map +0 -1
  51. package/dist/parse-zip/search-from-the-end.js.map +0 -1
  52. package/dist/parse-zip/zip-composition.js.map +0 -1
  53. package/dist/parse-zip/zip64-info-generation.js.map +0 -1
  54. package/dist/tar-builder.js.map +0 -1
  55. package/dist/zip-loader.js.map +0 -1
  56. package/dist/zip-writer.js.map +0 -1
@@ -1,3 +1,12 @@
1
+ // loaders.gl
2
+ // SPDX-License-Identifier: MIT
3
+ // Copyright (c) vis.gl contributors
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
+ */
1
10
  import { clean, pad, stringToUint8 } from "./utils.js";
2
11
  import { format } from "./header.js";
3
12
  let blockSize;
@@ -5,113 +14,122 @@ let headerLength;
5
14
  let inputLength;
6
15
  const recordSize = 512;
7
16
  class Tar {
8
- constructor(recordsPerBlock) {
9
- this.written = void 0;
10
- this.out = void 0;
11
- this.blocks = [];
12
- this.length = void 0;
13
- this.written = 0;
14
- blockSize = (recordsPerBlock || 20) * recordSize;
15
- this.out = clean(blockSize);
16
- this.blocks = [];
17
- this.length = 0;
18
- this.save = this.save.bind(this);
19
- this.clear = this.clear.bind(this);
20
- this.append = this.append.bind(this);
21
- }
22
- append(filepath, input, opts) {
23
- let checksum;
24
- if (typeof input === 'string') {
25
- input = stringToUint8(input);
26
- } else if (input.constructor && input.constructor !== Uint8Array.prototype.constructor) {
27
- const errorInputMatch = /function\s*([$A-Za-z_][0-9A-Za-z_]*)\s*\(/.exec(input.constructor.toString());
28
- const errorInput = errorInputMatch && errorInputMatch[1];
29
- const errorMessage = `Invalid input type. You gave me: ${errorInput}`;
30
- throw errorMessage;
17
+ written;
18
+ out;
19
+ blocks = [];
20
+ length;
21
+ /**
22
+ * @param [recordsPerBlock]
23
+ */
24
+ constructor(recordsPerBlock) {
25
+ this.written = 0;
26
+ blockSize = (recordsPerBlock || 20) * recordSize;
27
+ this.out = clean(blockSize);
28
+ this.blocks = [];
29
+ this.length = 0;
30
+ this.save = this.save.bind(this);
31
+ this.clear = this.clear.bind(this);
32
+ this.append = this.append.bind(this);
31
33
  }
32
- opts = opts || {};
33
- const mode = opts.mode || parseInt('777', 8) & 0xfff;
34
- const mtime = opts.mtime || Math.floor(Number(new Date()) / 1000);
35
- const uid = opts.uid || 0;
36
- const gid = opts.gid || 0;
37
- const data = {
38
- fileName: filepath,
39
- fileMode: pad(mode, 7),
40
- uid: pad(uid, 7),
41
- gid: pad(gid, 7),
42
- fileSize: pad(input.length, 11),
43
- mtime: pad(mtime, 11),
44
- checksum: ' ',
45
- type: '0',
46
- ustar: 'ustar ',
47
- owner: opts.owner || '',
48
- group: opts.group || ''
49
- };
50
- checksum = 0;
51
- Object.keys(data).forEach(key => {
52
- let i;
53
- const value = data[key];
54
- let length;
55
- for (i = 0, length = value.length; i < length; i += 1) {
56
- checksum += value.charCodeAt(i);
57
- }
58
- });
59
- data.checksum = `${pad(checksum, 6)}\u0000 `;
60
- const headerArr = format(data);
61
- headerLength = Math.ceil(headerArr.length / recordSize) * recordSize;
62
- inputLength = Math.ceil(input.length / recordSize) * recordSize;
63
- this.blocks.push({
64
- header: headerArr,
65
- input,
66
- headerLength,
67
- inputLength
68
- });
69
- }
70
- save() {
71
- const buffers = [];
72
- const chunks = new Array();
73
- let length = 0;
74
- const max = Math.pow(2, 20);
75
- let chunk = new Array();
76
- this.blocks.forEach(function () {
77
- let b = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
78
- if (length + b.headerLength + b.inputLength > max) {
79
- chunks.push({
80
- blocks: chunk,
81
- length
34
+ /**
35
+ * Append a file to the tar archive
36
+ * @param filepath
37
+ * @param input
38
+ * @param [opts]
39
+ */
40
+ // eslint-disable-next-line complexity
41
+ append(filepath, input, opts) {
42
+ let checksum;
43
+ if (typeof input === 'string') {
44
+ input = stringToUint8(input);
45
+ }
46
+ else if (input.constructor && input.constructor !== Uint8Array.prototype.constructor) {
47
+ // @ts-ignore
48
+ const errorInputMatch = /function\s*([$A-Za-z_][0-9A-Za-z_]*)\s*\(/.exec(input.constructor.toString());
49
+ const errorInput = errorInputMatch && errorInputMatch[1];
50
+ const errorMessage = `Invalid input type. You gave me: ${errorInput}`;
51
+ throw errorMessage;
52
+ }
53
+ opts = opts || {};
54
+ const mode = opts.mode || parseInt('777', 8) & 0xfff;
55
+ const mtime = opts.mtime || Math.floor(Number(new Date()) / 1000);
56
+ const uid = opts.uid || 0;
57
+ const gid = opts.gid || 0;
58
+ const data = {
59
+ fileName: filepath,
60
+ fileMode: pad(mode, 7),
61
+ uid: pad(uid, 7),
62
+ gid: pad(gid, 7),
63
+ fileSize: pad(input.length, 11),
64
+ mtime: pad(mtime, 11),
65
+ checksum: ' ',
66
+ // 0 = just a file
67
+ type: '0',
68
+ ustar: 'ustar ',
69
+ owner: opts.owner || '',
70
+ group: opts.group || ''
71
+ };
72
+ // calculate the checksum
73
+ checksum = 0;
74
+ Object.keys(data).forEach((key) => {
75
+ let i;
76
+ const value = data[key];
77
+ let length;
78
+ for (i = 0, length = value.length; i < length; i += 1) {
79
+ checksum += value.charCodeAt(i);
80
+ }
82
81
  });
83
- chunk = [];
84
- length = 0;
85
- }
86
- chunk.push(b);
87
- length += b.headerLength + b.inputLength;
88
- });
89
- chunks.push({
90
- blocks: chunk,
91
- length
92
- });
93
- chunks.forEach(function () {
94
- let c = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
95
- const buffer = new Uint8Array(c.length);
96
- let written = 0;
97
- c.blocks.forEach(function () {
98
- let b = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
99
- buffer.set(b.header, written);
100
- written += b.headerLength;
101
- buffer.set(b.input, written);
102
- written += b.inputLength;
103
- });
104
- buffers.push(buffer);
105
- });
106
- buffers.push(new Uint8Array(2 * recordSize));
107
- return new Blob(buffers, {
108
- type: 'octet/stream'
109
- });
110
- }
111
- clear() {
112
- this.written = 0;
113
- this.out = clean(blockSize);
114
- }
82
+ data.checksum = `${pad(checksum, 6)}\u0000 `;
83
+ const headerArr = format(data);
84
+ headerLength = Math.ceil(headerArr.length / recordSize) * recordSize;
85
+ inputLength = Math.ceil(input.length / recordSize) * recordSize;
86
+ this.blocks.push({
87
+ header: headerArr,
88
+ input,
89
+ headerLength,
90
+ inputLength
91
+ });
92
+ }
93
+ /**
94
+ * Compiling data to a Blob object
95
+ * @returns {Blob}
96
+ */
97
+ save() {
98
+ const buffers = [];
99
+ const chunks = new Array();
100
+ let length = 0;
101
+ const max = Math.pow(2, 20);
102
+ let chunk = new Array();
103
+ this.blocks.forEach((b = []) => {
104
+ if (length + b.headerLength + b.inputLength > max) {
105
+ chunks.push({ blocks: chunk, length });
106
+ chunk = [];
107
+ length = 0;
108
+ }
109
+ chunk.push(b);
110
+ length += b.headerLength + b.inputLength;
111
+ });
112
+ chunks.push({ blocks: chunk, length });
113
+ chunks.forEach((c = []) => {
114
+ const buffer = new Uint8Array(c.length);
115
+ let written = 0;
116
+ c.blocks.forEach((b = []) => {
117
+ buffer.set(b.header, written);
118
+ written += b.headerLength;
119
+ buffer.set(b.input, written);
120
+ written += b.inputLength;
121
+ });
122
+ buffers.push(buffer);
123
+ });
124
+ buffers.push(new Uint8Array(2 * recordSize));
125
+ return new Blob(buffers, { type: 'octet/stream' });
126
+ }
127
+ /**
128
+ * Clear the data by its blocksize
129
+ */
130
+ clear() {
131
+ this.written = 0;
132
+ this.out = clean(blockSize);
133
+ }
115
134
  }
116
135
  export default Tar;
117
- //# sourceMappingURL=tar.js.map
@@ -1,2 +1,4 @@
1
+ // loaders.gl
2
+ // SPDX-License-Identifier: MIT
3
+ // Copyright (c) vis.gl contributors
1
4
  export {};
2
- //# sourceMappingURL=types.js.map
@@ -1,24 +1,51 @@
1
+ // loaders.gl
2
+ // SPDX-License-Identifier: MIT
3
+ // Copyright (c) vis.gl contributors
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
+ */
1
15
  export function clean(length) {
2
- let i;
3
- const buffer = new Uint8Array(length);
4
- for (i = 0; i < length; i += 1) {
5
- buffer[i] = 0;
6
- }
7
- return buffer;
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;
8
22
  }
23
+ /**
24
+ * Converting data to a string
25
+ * @param num
26
+ * @param bytes
27
+ * @param base
28
+ * @returns string
29
+ */
9
30
  export function pad(num, bytes, base) {
10
- const numStr = num.toString(base || 8);
11
- return '000000000000'.substr(numStr.length + 12 - bytes) + numStr;
31
+ const numStr = num.toString(base || 8);
32
+ return '000000000000'.substr(numStr.length + 12 - bytes) + numStr;
12
33
  }
34
+ /**
35
+ * Converting input to binary data
36
+ * @param input
37
+ * @param out
38
+ * @param offset
39
+ * @returns {Uint8Array}
40
+ */
13
41
  export function stringToUint8(input, out, offset) {
14
- let i;
15
- let length;
16
- out = out || clean(input.length);
17
- offset = offset || 0;
18
- for (i = 0, length = input.length; i < length; i += 1) {
19
- out[offset] = input.charCodeAt(i);
20
- offset += 1;
21
- }
22
- return out;
42
+ let i;
43
+ let length;
44
+ out = out || clean(input.length);
45
+ offset = offset || 0;
46
+ for (i = 0, length = input.length; i < length; i += 1) {
47
+ out[offset] = input.charCodeAt(i);
48
+ offset += 1;
49
+ }
50
+ return out;
23
51
  }
24
- //# sourceMappingURL=utils.js.map
@@ -1,5 +1,5 @@
1
1
  import { FileProvider } from '@loaders.gl/loader-utils';
2
- import { ZipSignature } from './search-from-the-end';
2
+ import { ZipSignature } from "./search-from-the-end.js";
3
3
  /**
4
4
  * zip central directory file header info
5
5
  * according to https://en.wikipedia.org/wiki/ZIP_(file_format)
@@ -1 +1 @@
1
- {"version":3,"file":"cd-file-header.d.ts","sourceRoot":"","sources":["../../src/parse-zip/cd-file-header.ts"],"names":[],"mappings":"AAIA,OAAO,EAAC,YAAY,EAA+C,MAAM,0BAA0B,CAAC;AAEpG,OAAO,EAAC,YAAY,EAAC,MAAM,uBAAuB,CAAC;AAGnD;;;GAGG;AACH,MAAM,MAAM,eAAe,GAAG;IAC5B,sBAAsB;IACtB,cAAc,EAAE,MAAM,CAAC;IACvB,wBAAwB;IACxB,gBAAgB,EAAE,MAAM,CAAC;IACzB,uBAAuB;IACvB,gBAAgB,EAAE,MAAM,CAAC;IACzB,uBAAuB;IACvB,cAAc,EAAE,MAAM,CAAC;IACvB,gBAAgB;IAChB,QAAQ,EAAE,MAAM,CAAC;IACjB,yBAAyB;IACzB,WAAW,EAAE,MAAM,CAAC;IACpB,2CAA2C;IAC3C,iBAAiB,EAAE,MAAM,CAAC;CAC3B,CAAC;AAyBF,eAAO,MAAM,SAAS,EAAE,YAAuD,CAAC;AAEhF;;;;;GAKG;AACH,eAAO,MAAM,oBAAoB,iBACjB,MAAM,QACd,YAAY,KACjB,QAAQ,eAAe,GAAG,IAAI,CA2ChC,CAAC;AAEF;;;GAGG;AACH,wBAAuB,uBAAuB,CAC5C,YAAY,EAAE,YAAY,GACzB,aAAa,CAAC,e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