@loaders.gl/zip 4.0.0-alpha.9 → 4.0.0-beta.1

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 (81) hide show
  1. package/dist/dist.min.js +5143 -36
  2. package/dist/es5/filesystems/zip-filesystem.js +372 -0
  3. package/dist/es5/filesystems/zip-filesystem.js.map +1 -0
  4. package/dist/es5/hash-file-utility.js +130 -0
  5. package/dist/es5/hash-file-utility.js.map +1 -0
  6. package/dist/es5/index.js +80 -3
  7. package/dist/es5/index.js.map +1 -1
  8. package/dist/es5/parse-zip/cd-file-header.js +163 -0
  9. package/dist/es5/parse-zip/cd-file-header.js.map +1 -0
  10. package/dist/es5/parse-zip/end-of-central-directory.js +98 -0
  11. package/dist/es5/parse-zip/end-of-central-directory.js.map +1 -0
  12. package/dist/es5/parse-zip/local-file-header.js +117 -0
  13. package/dist/es5/parse-zip/local-file-header.js.map +1 -0
  14. package/dist/es5/parse-zip/search-from-the-end.js +69 -0
  15. package/dist/es5/parse-zip/search-from-the-end.js.map +1 -0
  16. package/dist/es5/tar-builder.js +8 -8
  17. package/dist/es5/tar-builder.js.map +1 -1
  18. package/dist/es5/zip-loader.js +2 -4
  19. package/dist/es5/zip-loader.js.map +1 -1
  20. package/dist/es5/zip-writer.js +19 -10
  21. package/dist/es5/zip-writer.js.map +1 -1
  22. package/dist/esm/filesystems/zip-filesystem.js +99 -0
  23. package/dist/esm/filesystems/zip-filesystem.js.map +1 -0
  24. package/dist/esm/hash-file-utility.js +55 -0
  25. package/dist/esm/hash-file-utility.js.map +1 -0
  26. package/dist/esm/index.js +7 -1
  27. package/dist/esm/index.js.map +1 -1
  28. package/dist/esm/parse-zip/cd-file-header.js +54 -0
  29. package/dist/esm/parse-zip/cd-file-header.js.map +1 -0
  30. package/dist/esm/parse-zip/end-of-central-directory.js +31 -0
  31. package/dist/esm/parse-zip/end-of-central-directory.js.map +1 -0
  32. package/dist/esm/parse-zip/local-file-header.js +41 -0
  33. package/dist/esm/parse-zip/local-file-header.js.map +1 -0
  34. package/dist/esm/parse-zip/search-from-the-end.js +16 -0
  35. package/dist/esm/parse-zip/search-from-the-end.js.map +1 -0
  36. package/dist/esm/tar-builder.js +2 -2
  37. package/dist/esm/tar-builder.js.map +1 -1
  38. package/dist/esm/zip-loader.js +1 -2
  39. package/dist/esm/zip-loader.js.map +1 -1
  40. package/dist/esm/zip-writer.js +8 -5
  41. package/dist/esm/zip-writer.js.map +1 -1
  42. package/dist/filesystems/zip-filesystem.d.ts +45 -0
  43. package/dist/filesystems/zip-filesystem.d.ts.map +1 -0
  44. package/dist/hash-file-utility.d.ts +35 -0
  45. package/dist/hash-file-utility.d.ts.map +1 -0
  46. package/dist/index.d.ts +8 -1
  47. package/dist/index.d.ts.map +1 -1
  48. package/dist/parse-zip/cd-file-header.d.ts +36 -0
  49. package/dist/parse-zip/cd-file-header.d.ts.map +1 -0
  50. package/dist/parse-zip/end-of-central-directory.d.ts +18 -0
  51. package/dist/parse-zip/end-of-central-directory.d.ts.map +1 -0
  52. package/dist/parse-zip/local-file-header.d.ts +28 -0
  53. package/dist/parse-zip/local-file-header.d.ts.map +1 -0
  54. package/dist/parse-zip/search-from-the-end.d.ts +11 -0
  55. package/dist/parse-zip/search-from-the-end.d.ts.map +1 -0
  56. package/dist/tar-builder.d.ts +2 -2
  57. package/dist/tar-builder.d.ts.map +1 -1
  58. package/dist/zip-loader.d.ts +0 -1
  59. package/dist/zip-loader.d.ts.map +1 -1
  60. package/dist/zip-writer.d.ts +12 -2
  61. package/dist/zip-writer.d.ts.map +1 -1
  62. package/package.json +6 -3
  63. package/src/filesystems/zip-filesystem.ts +142 -0
  64. package/src/hash-file-utility.ts +101 -0
  65. package/src/index.ts +20 -1
  66. package/src/parse-zip/cd-file-header.ts +114 -0
  67. package/src/parse-zip/end-of-central-directory.ts +71 -0
  68. package/src/parse-zip/local-file-header.ts +95 -0
  69. package/src/parse-zip/search-from-the-end.ts +38 -0
  70. package/src/tar-builder.ts +2 -2
  71. package/src/zip-loader.ts +2 -3
  72. package/src/zip-writer.ts +23 -10
  73. package/dist/bundle.js +0 -5
  74. package/dist/index.js +0 -12
  75. package/dist/lib/tar/header.js +0 -99
  76. package/dist/lib/tar/tar.js +0 -131
  77. package/dist/lib/tar/types.js +0 -2
  78. package/dist/lib/tar/utils.js +0 -54
  79. package/dist/tar-builder.js +0 -38
  80. package/dist/zip-loader.js +0 -61
  81. package/dist/zip-writer.js +0 -37
@@ -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,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;
@@ -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;
@@ -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
- }