@loaders.gl/compression 3.1.0-alpha.5 → 3.1.0-beta.4

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 (73) hide show
  1. package/dist/brotli/decode.d.ts +5 -0
  2. package/dist/brotli/decode.d.ts.map +1 -0
  3. package/dist/brotli/decode.js +2346 -0
  4. package/dist/bundle.d.ts +1 -0
  5. package/dist/bundle.d.ts.map +1 -0
  6. package/dist/bundle.js +5 -0
  7. package/dist/compression-worker.d.ts +1 -0
  8. package/dist/compression-worker.d.ts.map +1 -0
  9. package/dist/compression-worker.js +4 -13
  10. package/dist/compression-worker.js.map +7 -1
  11. package/dist/dist.min.js +9 -2
  12. package/dist/dist.min.js.map +7 -1
  13. package/dist/es5/brotli/decode.js +2220 -0
  14. package/dist/es5/brotli/decode.js.map +1 -0
  15. package/dist/es5/compression-worker.js +1 -1
  16. package/dist/es5/compression-worker.js.map +1 -1
  17. package/dist/es5/lib/brotli-compression.js +17 -2
  18. package/dist/es5/lib/brotli-compression.js.map +1 -1
  19. package/dist/es5/lib/zstd-compression.js +1 -1
  20. package/dist/es5/lib/zstd-compression.js.map +1 -1
  21. package/dist/es5/workers/worker.js +1 -12
  22. package/dist/es5/workers/worker.js.map +1 -1
  23. package/dist/esm/brotli/decode.js +2213 -0
  24. package/dist/esm/brotli/decode.js.map +1 -0
  25. package/dist/esm/compression-worker.js +1 -1
  26. package/dist/esm/compression-worker.js.map +1 -1
  27. package/dist/esm/lib/brotli-compression.js +16 -2
  28. package/dist/esm/lib/brotli-compression.js.map +1 -1
  29. package/dist/esm/lib/zstd-compression.js +1 -1
  30. package/dist/esm/lib/zstd-compression.js.map +1 -1
  31. package/dist/esm/workers/worker.js +1 -10
  32. package/dist/esm/workers/worker.js.map +1 -1
  33. package/dist/index.d.ts +1 -0
  34. package/dist/index.d.ts.map +1 -0
  35. package/dist/index.js +24 -0
  36. package/dist/lib/brotli-compression.d.ts +1 -0
  37. package/dist/lib/brotli-compression.d.ts.map +1 -0
  38. package/dist/lib/brotli-compression.js +91 -0
  39. package/dist/lib/compression.d.ts +1 -0
  40. package/dist/lib/compression.d.ts.map +1 -0
  41. package/dist/lib/compression.js +57 -0
  42. package/dist/lib/deflate-compression.d.ts +1 -0
  43. package/dist/lib/deflate-compression.d.ts.map +1 -0
  44. package/dist/lib/deflate-compression.js +135 -0
  45. package/dist/lib/gzip-compression.d.ts +1 -0
  46. package/dist/lib/gzip-compression.d.ts.map +1 -0
  47. package/dist/lib/gzip-compression.js +17 -0
  48. package/dist/lib/lz4-compression.d.ts +1 -0
  49. package/dist/lib/lz4-compression.d.ts.map +1 -0
  50. package/dist/lib/lz4-compression.js +141 -0
  51. package/dist/lib/lzo-compression.d.ts +1 -0
  52. package/dist/lib/lzo-compression.d.ts.map +1 -0
  53. package/dist/lib/lzo-compression.js +58 -0
  54. package/dist/lib/no-compression.d.ts +1 -0
  55. package/dist/lib/no-compression.d.ts.map +1 -0
  56. package/dist/lib/no-compression.js +30 -0
  57. package/dist/lib/snappy-compression.d.ts +1 -0
  58. package/dist/lib/snappy-compression.d.ts.map +1 -0
  59. package/dist/lib/snappy-compression.js +27 -0
  60. package/dist/lib/zstd-compression.d.ts +1 -0
  61. package/dist/lib/zstd-compression.d.ts.map +1 -0
  62. package/dist/lib/zstd-compression.js +44 -0
  63. package/dist/types.d.ts +1 -0
  64. package/dist/types.d.ts.map +1 -0
  65. package/dist/types.js +2 -0
  66. package/dist/workers/worker.d.ts +1 -0
  67. package/dist/workers/worker.d.ts.map +1 -0
  68. package/dist/workers/worker.js +77 -0
  69. package/package.json +6 -7
  70. package/src/brotli/decode.ts +2441 -0
  71. package/src/lib/brotli-compression.ts +17 -3
  72. package/src/lib/zstd-compression.ts +1 -1
  73. package/src/workers/worker.ts +10 -10
@@ -0,0 +1,141 @@
1
+ "use strict";
2
+ // Copyright (c) 2012 Pierre Curto
3
+ Object.defineProperty(exports, "__esModule", { value: true });
4
+ exports.LZ4Compression = void 0;
5
+ // Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ // of this software and associated documentation files (the "Software"), to deal
7
+ // in the Software without restriction, including without limitation the rights
8
+ // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ // copies of the Software, and to permit persons to whom the Software is
10
+ // furnished to do so, subject to the following conditions:
11
+ // The above copyright notice and this permission notice shall be included in
12
+ // all copies or substantial portions of the Software.
13
+ // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14
+ // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15
+ // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16
+ // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17
+ // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18
+ // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19
+ // THE SOFTWARE.
20
+ /* eslint-disable complexity */
21
+ /* eslint-disable max-statements */
22
+ // LZ4
23
+ const loader_utils_1 = require("@loaders.gl/loader-utils");
24
+ const compression_1 = require("./compression");
25
+ // import lz4js from 'lz4js'; // https://bundlephobia.com/package/lz4
26
+ const LZ4_MAGIC_NUMBER = 0x184d2204;
27
+ let lz4js;
28
+ /**
29
+ * LZ4 compression / decompression
30
+ */
31
+ class LZ4Compression extends compression_1.Compression {
32
+ constructor(options) {
33
+ super(options);
34
+ this.name = 'lz4';
35
+ this.extensions = ['lz4'];
36
+ this.contentEncodings = ['x-lz4'];
37
+ this.isSupported = true;
38
+ this.options = options;
39
+ lz4js = lz4js || this.options?.modules?.lz4js;
40
+ if (!lz4js) {
41
+ throw new Error(this.name);
42
+ }
43
+ }
44
+ compressSync(input) {
45
+ const inputArray = new Uint8Array(input);
46
+ return lz4js.compress(inputArray).buffer;
47
+ }
48
+ /**
49
+ * Decompresses an ArrayBuffer containing an Lz4 frame. maxSize is optional; if not
50
+ * provided, a maximum size will be determined by examining the data. The
51
+ * returned ArrayBuffer will always be perfectly sized.
52
+ * If data provided without magic number we will parse it as block
53
+ */
54
+ decompressSync(data, maxSize) {
55
+ try {
56
+ const isMagicNumberExists = this.checkMagicNumber(data);
57
+ const inputArray = new Uint8Array(data);
58
+ if (isMagicNumberExists) {
59
+ return lz4js.decompress(inputArray, maxSize).buffer;
60
+ }
61
+ if (!maxSize) {
62
+ const error = new Error('Need to provide maxSize');
63
+ throw this.improveError(error);
64
+ }
65
+ let uncompressed = new Uint8Array(maxSize);
66
+ const uncompressedSize = this.decodeBlock(inputArray, uncompressed);
67
+ uncompressed = uncompressed.slice(0, uncompressedSize);
68
+ return (0, loader_utils_1.toArrayBuffer)(uncompressed);
69
+ }
70
+ catch (error) {
71
+ throw this.improveError(error);
72
+ }
73
+ }
74
+ /**
75
+ * Decode lz4 file as block
76
+ * Solution taken from here
77
+ * https://github.com/pierrec/node-lz4/blob/0dac687262403fd34f905b963da7220692f2a4a1/lib/binding.js#L25
78
+ * @param input
79
+ * @param output
80
+ * @param startIndex
81
+ * @param endIndex
82
+ */
83
+ decodeBlock(data, output, startIndex, endIndex) {
84
+ startIndex = startIndex || 0;
85
+ endIndex = endIndex || data.length - startIndex;
86
+ let uncompressedSize = 0;
87
+ // Process each sequence in the incoming data
88
+ for (let index = startIndex; index < endIndex;) {
89
+ const token = data[index++];
90
+ // Literals
91
+ let literalsLength = token >> 4;
92
+ if (literalsLength > 0) {
93
+ // length of literals
94
+ let length = literalsLength + 240;
95
+ while (length === 255) {
96
+ length = data[index++];
97
+ literalsLength += length;
98
+ }
99
+ // Copy the literals
100
+ const end = index + literalsLength;
101
+ while (index < end) {
102
+ output[uncompressedSize++] = data[index++];
103
+ }
104
+ // End of buffer?
105
+ if (index === endIndex) {
106
+ return uncompressedSize;
107
+ }
108
+ }
109
+ // Match copy
110
+ // 2 bytes offset (little endian)
111
+ const offset = data[index++] | (data[index++] << 8);
112
+ // 0 is an invalid offset value
113
+ if (offset === 0 || offset > uncompressedSize) {
114
+ return -(index - 2);
115
+ }
116
+ // length of match copy
117
+ let matchLength = token & 0xf;
118
+ let length = matchLength + 240;
119
+ while (length === 255) {
120
+ length = data[index++];
121
+ matchLength += length;
122
+ }
123
+ // Copy the match
124
+ let pos = uncompressedSize - offset; // position of the match copy in the current output
125
+ const end = uncompressedSize + matchLength + 4; // minmatch = 4
126
+ while (uncompressedSize < end) {
127
+ output[uncompressedSize++] = output[pos++];
128
+ }
129
+ }
130
+ return uncompressedSize;
131
+ }
132
+ /**
133
+ * Compare file magic with lz4 magic number
134
+ * @param input
135
+ */
136
+ checkMagicNumber(data) {
137
+ const magic = new Uint32Array(data.slice(0, 4));
138
+ return magic[0] === LZ4_MAGIC_NUMBER;
139
+ }
140
+ }
141
+ exports.LZ4Compression = LZ4Compression;
@@ -18,3 +18,4 @@ export declare class LZOCompression extends Compression {
18
18
  compress(input: ArrayBuffer): Promise<ArrayBuffer>;
19
19
  decompress(input: ArrayBuffer): Promise<ArrayBuffer>;
20
20
  }
21
+ //# sourceMappingURL=lzo-compression.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"lzo-compression.d.ts","sourceRoot":"","sources":["../../src/lib/lzo-compression.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAC,kBAAkB,EAAC,MAAM,eAAe,CAAC;AACtD,OAAO,EAAC,WAAW,EAAC,MAAM,eAAe,CAAC;AAW1C;;GAEG;AACH,qBAAa,cAAe,SAAQ,WAAW;IAC7C,QAAQ,CAAC,IAAI,SAAS;IACtB,QAAQ,CAAC,UAAU,UAAM;IACzB,QAAQ,CAAC,gBAAgB,UAAM;IAC/B,QAAQ,CAAC,WAAW,SAAS;IAC7B,QAAQ,CAAC,OAAO,EAAE,kBAAkB,CAAC;IAErC;;;OAGG;gBACS,OAAO,EAAE,kBAAkB;IAUjC,OAAO;IAKP,QAAQ,CAAC,KAAK,EAAE,WAAW,GAAG,OAAO,CAAC,WAAW,CAAC;IAOlD,UAAU,CAAC,KAAK,EAAE,WAAW,GAAG,OAAO,CAAC,WAAW,CAAC;CAY3D"}
@@ -0,0 +1,58 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.LZOCompression = void 0;
4
+ // LZO
5
+ // import {loadLibrary} from '@loaders.gl/worker-utils';
6
+ const loader_utils_1 = require("@loaders.gl/loader-utils");
7
+ const compression_1 = require("./compression");
8
+ // import {isBrowser} from '@loaders.gl/loader-utils';
9
+ // import lzo from 'lzo'; // https://bundlephobia.com/package/lzo
10
+ // import {decompress} from 'lzo-wasm';
11
+ // const LZO_WASM_JS_URL = './node_modules/lzo-wasm/lzo-wasm.js';
12
+ // const LZO_WASM_WASM_URL = './node_modules/lzo-wasm/lzo-wasm.wasm';
13
+ let lzo;
14
+ /**
15
+ * Lempel-Ziv-Oberheimer compression / decompression
16
+ */
17
+ class LZOCompression extends compression_1.Compression {
18
+ /**
19
+ * lzo is an injectable dependency due to big size
20
+ * @param options
21
+ */
22
+ constructor(options) {
23
+ super(options);
24
+ this.name = 'lzo';
25
+ this.extensions = [];
26
+ this.contentEncodings = [];
27
+ this.isSupported = false; // !isBrowser;
28
+ this.options = options;
29
+ lzo = lzo || this.options?.modules?.lzo;
30
+ if (!lzo) {
31
+ throw new Error(this.name);
32
+ }
33
+ }
34
+ async preload() {
35
+ // await loadLibrary(LZO_WASM_JS_URL);
36
+ // await loadLibrary(LZO_WASM_WASM_URL);
37
+ }
38
+ async compress(input) {
39
+ await this.preload();
40
+ // const inputArray = new Uint8Array(input);
41
+ const inputBuffer = (0, loader_utils_1.toBuffer)(input);
42
+ return lzo.compress(inputBuffer).buffer;
43
+ }
44
+ async decompress(input) {
45
+ try {
46
+ await this.preload();
47
+ // const inputArray = new Uint8Array(input);
48
+ const inputBuffer = (0, loader_utils_1.toBuffer)(input);
49
+ return lzo.decompress(inputBuffer).buffer;
50
+ }
51
+ catch (error) {
52
+ // TODO - solve SharedArrayBuffer issues
53
+ // return decompress(input);
54
+ throw error;
55
+ }
56
+ }
57
+ }
58
+ exports.LZOCompression = LZOCompression;
@@ -15,3 +15,4 @@ export declare class NoCompression extends Compression {
15
15
  compressBatches(asyncIterator: AsyncIterable<ArrayBuffer> | Iterable<ArrayBuffer>): AsyncIterable<ArrayBuffer>;
16
16
  decompressBatches(asyncIterator: AsyncIterable<ArrayBuffer> | Iterable<ArrayBuffer>): AsyncIterable<ArrayBuffer>;
17
17
  }
18
+ //# sourceMappingURL=no-compression.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"no-compression.d.ts","sourceRoot":"","sources":["../../src/lib/no-compression.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAC,kBAAkB,EAAC,MAAM,eAAe,CAAC;AACtD,OAAO,EAAC,WAAW,EAAC,MAAM,eAAe,CAAC;AAE1C;;GAEG;AACH,qBAAa,aAAc,SAAQ,WAAW;IAC5C,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAkB;IACvC,QAAQ,CAAC,UAAU,EAAE,MAAM,EAAE,CAAM;IACnC,QAAQ,CAAC,gBAAgB,EAAE,MAAM,EAAE,CAAM;IACzC,QAAQ,CAAC,WAAW,QAAQ;IAE5B,QAAQ,CAAC,OAAO,EAAE,kBAAkB,CAAC;gBAEzB,OAAO,CAAC,EAAE,kBAAkB;IAKxC,YAAY,CAAC,KAAK,EAAE,WAAW,GAAG,WAAW;IAI7C,cAAc,CAAC,KAAK,EAAE,WAAW,GAAG,WAAW;IAIxC,eAAe,CACpB,aAAa,EAAE,aAAa,CAAC,WAAW,CAAC,GAAG,QAAQ,CAAC,WAAW,CAAC,GAChE,aAAa,CAAC,WAAW,CAAC;IAItB,iBAAiB,CACtB,aAAa,EAAE,aAAa,CAAC,WAAW,CAAC,GAAG,QAAQ,CAAC,WAAW,CAAC,GAChE,aAAa,CAAC,WAAW,CAAC;CAG9B"}
@@ -0,0 +1,30 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.NoCompression = void 0;
4
+ const compression_1 = require("./compression");
5
+ /**
6
+ * Applies no compression.
7
+ */
8
+ class NoCompression extends compression_1.Compression {
9
+ constructor(options) {
10
+ super(options);
11
+ this.name = 'uncompressed';
12
+ this.extensions = [];
13
+ this.contentEncodings = [];
14
+ this.isSupported = true;
15
+ this.options = options || {};
16
+ }
17
+ compressSync(input) {
18
+ return input;
19
+ }
20
+ decompressSync(input) {
21
+ return input;
22
+ }
23
+ async *compressBatches(asyncIterator) {
24
+ return yield* asyncIterator;
25
+ }
26
+ async *decompressBatches(asyncIterator) {
27
+ return yield* asyncIterator;
28
+ }
29
+ }
30
+ exports.NoCompression = NoCompression;
@@ -13,3 +13,4 @@ export declare class SnappyCompression extends Compression {
13
13
  compressSync(input: ArrayBuffer): ArrayBuffer;
14
14
  decompressSync(input: ArrayBuffer): ArrayBuffer;
15
15
  }
16
+ //# sourceMappingURL=snappy-compression.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"snappy-compression.d.ts","sourceRoot":"","sources":["../../src/lib/snappy-compression.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAC,kBAAkB,EAAC,MAAM,eAAe,CAAC;AACtD,OAAO,EAAC,WAAW,EAAC,MAAM,eAAe,CAAC;AAG1C;;GAEG;AACH,qBAAa,iBAAkB,SAAQ,WAAW;IAChD,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAY;IACjC,QAAQ,CAAC,UAAU,UAAM;IACzB,QAAQ,CAAC,gBAAgB,UAAM;IAC/B,QAAQ,CAAC,WAAW,QAAQ;IAC5B,QAAQ,CAAC,OAAO,EAAE,kBAAkB,CAAC;gBAEzB,OAAO,CAAC,EAAE,kBAAkB;IAKxC,YAAY,CAAC,KAAK,EAAE,WAAW,GAAG,WAAW;IAK7C,cAAc,CAAC,KAAK,EAAE,WAAW,GAAG,WAAW;CAIhD"}
@@ -0,0 +1,27 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.SnappyCompression = void 0;
4
+ const compression_1 = require("./compression");
5
+ const snappyjs_1 = require("snappyjs"); // https://bundlephobia.com/package/snappy
6
+ /**
7
+ * Snappy/zippy compression / decompression
8
+ */
9
+ class SnappyCompression extends compression_1.Compression {
10
+ constructor(options) {
11
+ super(options);
12
+ this.name = 'snappy';
13
+ this.extensions = [];
14
+ this.contentEncodings = [];
15
+ this.isSupported = true;
16
+ this.options = options || {};
17
+ }
18
+ compressSync(input) {
19
+ // Accepts arrayBuffer - https://github.com/zhipeng-jia/snappyjs#usage
20
+ return (0, snappyjs_1.compress)(input);
21
+ }
22
+ decompressSync(input) {
23
+ // Accepts arrayBuffer - https://github.com/zhipeng-jia/snappyjs#usage
24
+ return (0, snappyjs_1.uncompress)(input);
25
+ }
26
+ }
27
+ exports.SnappyCompression = SnappyCompression;
@@ -18,3 +18,4 @@ export declare class ZstdCompression extends Compression {
18
18
  compressSync(input: ArrayBuffer): ArrayBuffer;
19
19
  decompressSync(input: ArrayBuffer): ArrayBuffer;
20
20
  }
21
+ //# sourceMappingURL=zstd-compression.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"zstd-compression.d.ts","sourceRoot":"","sources":["../../src/lib/zstd-compression.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAC,kBAAkB,EAAC,MAAM,eAAe,CAAC;AACtD,OAAO,EAAC,WAAW,EAAC,MAAM,eAAe,CAAC;AAM1C;;GAEG;AACH,qBAAa,eAAgB,SAAQ,WAAW;IAC9C,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAU;IAC/B,QAAQ,CAAC,UAAU,UAAM;IACzB,QAAQ,CAAC,gBAAgB,UAAM;IAC/B,QAAQ,CAAC,WAAW,QAAQ;IAC5B,QAAQ,CAAC,OAAO,EAAE,kBAAkB,CAAC;IAErC;;;OAGG;gBACS,OAAO,EAAE,kBAAkB;IAUjC,OAAO,IAAI,OAAO,CAAC,IAAI,CAAC;IAI9B,YAAY,CAAC,KAAK,EAAE,WAAW,GAAG,WAAW;IAM7C,cAAc,CAAC,KAAK,EAAE,WAAW,GAAG,WAAW;CAOhD"}
@@ -0,0 +1,44 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ZstdCompression = void 0;
4
+ const compression_1 = require("./compression");
5
+ // import {ZstdCodec} from 'zstd-codec'; // https://bundlephobia.com/package/zstd-codec
6
+ let ZstdCodec;
7
+ let zstd;
8
+ /**
9
+ * Zstandard compression / decompression
10
+ */
11
+ class ZstdCompression extends compression_1.Compression {
12
+ /**
13
+ * zstd-codec is an injectable dependency due to big size
14
+ * @param options
15
+ */
16
+ constructor(options) {
17
+ super(options);
18
+ this.name = 'zstd';
19
+ this.extensions = [];
20
+ this.contentEncodings = [];
21
+ this.isSupported = true;
22
+ this.options = options;
23
+ ZstdCodec = this.options?.modules?.['zstd-codec'];
24
+ if (!ZstdCodec) {
25
+ console.warn(`${this.name} library not installed`);
26
+ }
27
+ }
28
+ async preload() {
29
+ zstd = zstd || (await new Promise((resolve) => ZstdCodec.run((zstd) => resolve(zstd))));
30
+ }
31
+ compressSync(input) {
32
+ const simpleZstd = new zstd.Simple();
33
+ const inputArray = new Uint8Array(input);
34
+ return simpleZstd.compress(inputArray).buffer;
35
+ }
36
+ decompressSync(input) {
37
+ const simpleZstd = new zstd.Simple();
38
+ // var ddict = new zstd.Dict.Decompression(dictData);
39
+ // var jsonBytes = simpleZstd.decompressUsingDict(jsonZstData, ddict);
40
+ const inputArray = new Uint8Array(input);
41
+ return simpleZstd.decompress(inputArray).buffer;
42
+ }
43
+ }
44
+ exports.ZstdCompression = ZstdCompression;
package/dist/types.d.ts CHANGED
@@ -1 +1,2 @@
1
1
  export type { Compression, CompressionOptions } from './lib/compression';
2
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,YAAY,EAAC,WAAW,EAAE,kBAAkB,EAAC,MAAM,mBAAmB,CAAC"}
package/dist/types.js ADDED
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -1 +1,2 @@
1
1
  export {};
2
+ //# sourceMappingURL=worker.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"worker.d.ts","sourceRoot":"","sources":["../../src/workers/worker.ts"],"names":[],"mappings":""}
@@ -0,0 +1,77 @@
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 worker_utils_1 = require("@loaders.gl/worker-utils");
7
+ // Compressors
8
+ const no_compression_1 = require("../lib/no-compression");
9
+ const brotli_compression_1 = require("../lib/brotli-compression");
10
+ const deflate_compression_1 = require("../lib/deflate-compression");
11
+ const gzip_compression_1 = require("../lib/gzip-compression");
12
+ const lz4_compression_1 = require("../lib/lz4-compression");
13
+ // import {LZOCompression} from '../lib/lzo-compression';
14
+ const snappy_compression_1 = require("../lib/snappy-compression");
15
+ const zstd_compression_1 = require("../lib/zstd-compression");
16
+ // Import big dependencies
17
+ // import brotli from 'brotli'; - brotli has problems with decompress in browsers
18
+ // import brotliDecompress from 'brotli/decompress';
19
+ const lz4js_1 = __importDefault(require("lz4js"));
20
+ // import lzo from 'lzo';
21
+ // import {ZstdCodec} from 'zstd-codec';
22
+ // Inject large dependencies through Compression constructor options
23
+ const modules = {
24
+ // brotli has problems with decompress in browsers
25
+ // brotli: {
26
+ // decompress: brotliDecompress,
27
+ // compress: () => {
28
+ // throw new Error('brotli compress');
29
+ // }
30
+ // },
31
+ lz4js: lz4js_1.default
32
+ // lzo,
33
+ // 'zstd-codec': ZstdCodec
34
+ };
35
+ /** @type {Compression[]} */
36
+ const COMPRESSIONS = [
37
+ new no_compression_1.NoCompression({ modules }),
38
+ new brotli_compression_1.BrotliCompression({ modules }),
39
+ new deflate_compression_1.DeflateCompression({ modules }),
40
+ new gzip_compression_1.GZipCompression({ modules }),
41
+ // new LZOCompression({modules}),
42
+ new lz4_compression_1.LZ4Compression({ modules }),
43
+ new snappy_compression_1.SnappyCompression({ modules }),
44
+ new zstd_compression_1.ZstdCompression({ modules })
45
+ ];
46
+ (0, worker_utils_1.createWorker)(async (data, options = {}) => {
47
+ const operation = getOperation(String(options?.operation));
48
+ const compression = getCompression(String(options?.compression));
49
+ // @ts-ignore
50
+ switch (operation) {
51
+ case 'compress':
52
+ return await compression.compress(data);
53
+ case 'decompress':
54
+ return await compression.decompress(data);
55
+ default:
56
+ throw new Error('invalid option');
57
+ }
58
+ });
59
+ function getOperation(operation) {
60
+ switch (operation) {
61
+ case 'compress':
62
+ case 'deflate':
63
+ return 'compress';
64
+ case 'decompress':
65
+ case 'inflate':
66
+ return 'decompress';
67
+ default:
68
+ throw new Error(`@loaders.gl/compression: Unsupported operation ${operation}. Expected 'compress' or 'decompress'`);
69
+ }
70
+ }
71
+ function getCompression(name) {
72
+ const Compression = COMPRESSIONS.find((compression_) => name === compression_.name);
73
+ if (!Compression) {
74
+ throw new Error(`@loaders.gl/compression: Unsupported compression ${name}`);
75
+ }
76
+ return Compression;
77
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@loaders.gl/compression",
3
- "version": "3.1.0-alpha.5",
3
+ "version": "3.1.0-beta.4",
4
4
  "description": "Decompression and compression plugins for loaders.gl",
5
5
  "license": "MIT",
6
6
  "publishConfig": {
@@ -33,14 +33,13 @@
33
33
  },
34
34
  "scripts": {
35
35
  "pre-build": "npm run build-bundle && npm run build-worker",
36
- "post-build": "tsc",
37
- "build-bundle": "webpack --display=minimal --config ../../scripts/webpack/bundle.js",
38
- "build-worker": "webpack --entry ./src/workers/worker.ts --output ./dist/compression-worker.js --config ../../scripts/webpack/worker.js"
36
+ "build-bundle": "esbuild src/bundle.ts --outfile=dist/dist.min.js --bundle --minify --sourcemap --external:{fs,path,crypto}",
37
+ "build-worker": "esbuild src/workers/worker.ts --outfile=dist/compression-worker.js --bundle --minify --sourcemap --external:{fs,path,crypto}"
39
38
  },
40
39
  "dependencies": {
41
40
  "@babel/runtime": "^7.3.1",
42
- "@loaders.gl/loader-utils": "3.1.0-alpha.5",
43
- "@loaders.gl/worker-utils": "3.1.0-alpha.5",
41
+ "@loaders.gl/loader-utils": "3.1.0-beta.4",
42
+ "@loaders.gl/worker-utils": "3.1.0-beta.4",
44
43
  "@types/brotli": "^1.3.0",
45
44
  "@types/pako": "^1.0.1",
46
45
  "lzo-wasm": "^0.0.4",
@@ -59,5 +58,5 @@
59
58
  "lzo": "^0.4.11",
60
59
  "zstd-codec": "^0.1"
61
60
  },
62
- "gitHead": "352241dd910a8c6307a235dadbe154ca915b885b"
61
+ "gitHead": "5c7c74215416b30fcea98f5cecc820c8a21023b3"
63
62
  }