@loaders.gl/compression 4.0.0-alpha.8 → 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 (35) hide show
  1. package/dist/compression-worker-node.js +2 -2
  2. package/dist/compression-worker-node.js.map +2 -2
  3. package/dist/compression-worker.d.ts +0 -2
  4. package/dist/compression-worker.d.ts.map +1 -1
  5. package/dist/compression-worker.js +2 -2
  6. package/dist/compression-worker.js.map +2 -2
  7. package/dist/dist.min.js +3 -3
  8. package/dist/dist.min.js.map +2 -2
  9. package/dist/es5/compression-worker.js +2 -4
  10. package/dist/es5/compression-worker.js.map +1 -1
  11. package/dist/es5/lib/deflate-compression.js +9 -7
  12. package/dist/es5/lib/deflate-compression.js.map +1 -1
  13. package/dist/esm/compression-worker.js +1 -2
  14. package/dist/esm/compression-worker.js.map +1 -1
  15. package/dist/esm/lib/deflate-compression.js +11 -9
  16. package/dist/esm/lib/deflate-compression.js.map +1 -1
  17. package/dist/lib/deflate-compression.d.ts +2 -0
  18. package/dist/lib/deflate-compression.d.ts.map +1 -1
  19. package/package.json +4 -4
  20. package/src/compression-worker.ts +1 -3
  21. package/src/lib/deflate-compression.ts +6 -2
  22. package/dist/brotli/decode.js +0 -2346
  23. package/dist/bundle.js +0 -5
  24. package/dist/index.js +0 -24
  25. package/dist/lib/brotli-compression.js +0 -92
  26. package/dist/lib/compression.js +0 -57
  27. package/dist/lib/deflate-compression.js +0 -135
  28. package/dist/lib/gzip-compression.js +0 -17
  29. package/dist/lib/lz4-compression.js +0 -141
  30. package/dist/lib/lzo-compression.js +0 -58
  31. package/dist/lib/no-compression.js +0 -30
  32. package/dist/lib/snappy-compression.js +0 -27
  33. package/dist/lib/zstd-compression.js +0 -47
  34. package/dist/types.js +0 -2
  35. package/dist/workers/worker.js +0 -77
package/dist/bundle.js DELETED
@@ -1,5 +0,0 @@
1
- "use strict";
2
- // @ts-nocheck
3
- const moduleExports = require('./index');
4
- globalThis.loaders = globalThis.loaders || {};
5
- module.exports = Object.assign(globalThis.loaders, moduleExports);
package/dist/index.js DELETED
@@ -1,24 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.compressOnWorker = exports.CompressionWorker = exports.LZOCompression = exports.ZstdCompression = exports.LZ4Compression = exports.SnappyCompression = exports.BrotliCompression = exports.GZipCompression = exports.DeflateCompression = exports.NoCompression = exports.Compression = void 0;
4
- var compression_1 = require("./lib/compression");
5
- Object.defineProperty(exports, "Compression", { enumerable: true, get: function () { return compression_1.Compression; } });
6
- var no_compression_1 = require("./lib/no-compression");
7
- Object.defineProperty(exports, "NoCompression", { enumerable: true, get: function () { return no_compression_1.NoCompression; } });
8
- var deflate_compression_1 = require("./lib/deflate-compression");
9
- Object.defineProperty(exports, "DeflateCompression", { enumerable: true, get: function () { return deflate_compression_1.DeflateCompression; } });
10
- var gzip_compression_1 = require("./lib/gzip-compression");
11
- Object.defineProperty(exports, "GZipCompression", { enumerable: true, get: function () { return gzip_compression_1.GZipCompression; } });
12
- var brotli_compression_1 = require("./lib/brotli-compression");
13
- Object.defineProperty(exports, "BrotliCompression", { enumerable: true, get: function () { return brotli_compression_1.BrotliCompression; } });
14
- var snappy_compression_1 = require("./lib/snappy-compression");
15
- Object.defineProperty(exports, "SnappyCompression", { enumerable: true, get: function () { return snappy_compression_1.SnappyCompression; } });
16
- var lz4_compression_1 = require("./lib/lz4-compression");
17
- Object.defineProperty(exports, "LZ4Compression", { enumerable: true, get: function () { return lz4_compression_1.LZ4Compression; } });
18
- var zstd_compression_1 = require("./lib/zstd-compression");
19
- Object.defineProperty(exports, "ZstdCompression", { enumerable: true, get: function () { return zstd_compression_1.ZstdCompression; } });
20
- var lzo_compression_1 = require("./lib/lzo-compression");
21
- Object.defineProperty(exports, "LZOCompression", { enumerable: true, get: function () { return lzo_compression_1.LZOCompression; } });
22
- var compression_worker_1 = require("./compression-worker");
23
- Object.defineProperty(exports, "CompressionWorker", { enumerable: true, get: function () { return compression_worker_1.CompressionWorker; } });
24
- Object.defineProperty(exports, "compressOnWorker", { enumerable: true, get: function () { return compression_worker_1.compressOnWorker; } });
@@ -1,92 +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.BrotliCompression = void 0;
7
- const compression_1 = require("./compression");
8
- const loader_utils_1 = require("@loaders.gl/loader-utils");
9
- // import brotli from 'brotli'; // https://bundlephobia.com/package/brotli
10
- const decode_1 = require("../brotli/decode");
11
- const zlib_1 = __importDefault(require("zlib"));
12
- const loader_utils_2 = require("@loaders.gl/loader-utils");
13
- const DEFAULT_BROTLI_OPTIONS = {
14
- brotli: {
15
- mode: 0,
16
- quality: 8,
17
- lgwin: 22
18
- }
19
- };
20
- let brotli;
21
- /**
22
- * brotli compression / decompression
23
- */
24
- class BrotliCompression extends compression_1.Compression {
25
- constructor(options) {
26
- super(options);
27
- this.name = 'brotli';
28
- this.extensions = ['br'];
29
- this.contentEncodings = ['br'];
30
- this.isSupported = true;
31
- this.options = options;
32
- }
33
- /**
34
- * brotli is an injectable dependency due to big size
35
- * @param options
36
- */
37
- async preload() {
38
- brotli = brotli || this.options?.modules?.brotli;
39
- if (!brotli) {
40
- // eslint-disable-next-line no-console
41
- console.warn(`${this.name} library not installed`);
42
- }
43
- }
44
- async compress(input) {
45
- // On Node.js we can use built-in zlib
46
- if (!loader_utils_1.isBrowser && this.options.brotli?.useZlib) {
47
- const buffer = await (0, loader_utils_2.promisify1)(zlib_1.default.brotliCompress)(input);
48
- return (0, loader_utils_1.toArrayBuffer)(buffer);
49
- }
50
- return this.compressSync(input);
51
- }
52
- compressSync(input) {
53
- // On Node.js we can use built-in zlib
54
- if (!loader_utils_1.isBrowser && this.options.brotli?.useZlib) {
55
- const buffer = zlib_1.default.brotliCompressSync(input);
56
- return (0, loader_utils_1.toArrayBuffer)(buffer);
57
- }
58
- const brotliOptions = { ...DEFAULT_BROTLI_OPTIONS.brotli, ...this.options?.brotli };
59
- const inputArray = new Uint8Array(input);
60
- if (!brotli) {
61
- throw new Error('brotli compression: brotli module not installed');
62
- }
63
- // @ts-ignore brotli types state that only Buffers are accepted...
64
- const outputArray = brotli.compress(inputArray, brotliOptions);
65
- return outputArray.buffer;
66
- }
67
- async decompress(input) {
68
- // On Node.js we can use built-in zlib
69
- if (!loader_utils_1.isBrowser && this.options.brotli?.useZlib) {
70
- const buffer = await (0, loader_utils_2.promisify1)(zlib_1.default.brotliDecompress)(input);
71
- return (0, loader_utils_1.toArrayBuffer)(buffer);
72
- }
73
- return this.decompressSync(input);
74
- }
75
- decompressSync(input) {
76
- // On Node.js we can use built-in zlib
77
- if (!loader_utils_1.isBrowser && this.options.brotli?.useZlib) {
78
- const buffer = zlib_1.default.brotliDecompressSync(input);
79
- return (0, loader_utils_1.toArrayBuffer)(buffer);
80
- }
81
- const brotliOptions = { ...DEFAULT_BROTLI_OPTIONS.brotli, ...this.options?.brotli };
82
- const inputArray = new Uint8Array(input);
83
- if (brotli) {
84
- // @ts-ignore brotli types state that only Buffers are accepted...
85
- const outputArray = brotli.decompress(inputArray, brotliOptions);
86
- return outputArray.buffer;
87
- }
88
- const outputArray = (0, decode_1.BrotliDecode)(inputArray, undefined);
89
- return outputArray.buffer;
90
- }
91
- }
92
- exports.BrotliCompression = BrotliCompression;
@@ -1,57 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.Compression = void 0;
4
- // Compression interface
5
- const loader_utils_1 = require("@loaders.gl/loader-utils");
6
- /** Compression */
7
- class Compression {
8
- constructor(options) {
9
- this.compressBatches = this.compressBatches.bind(this);
10
- this.decompressBatches = this.decompressBatches.bind(this);
11
- }
12
- /** Preloads any dynamic libraries. May enable sync functions */
13
- async preload() {
14
- return;
15
- }
16
- /** Asynchronously compress data */
17
- async compress(input) {
18
- await this.preload();
19
- return this.compressSync(input);
20
- }
21
- /** Asynchronously decompress data */
22
- async decompress(input, size) {
23
- await this.preload();
24
- return this.decompressSync(input, size);
25
- }
26
- /** Synchronously compress data */
27
- compressSync(input) {
28
- throw new Error(`${this.name}: sync compression not supported`);
29
- }
30
- /** Synchronously compress data */
31
- decompressSync(input, size) {
32
- throw new Error(`${this.name}: sync decompression not supported`);
33
- }
34
- /** Compress batches */
35
- async *compressBatches(asyncIterator) {
36
- // TODO - implement incremental compression
37
- const input = await this.concatenate(asyncIterator);
38
- yield this.compress(input);
39
- }
40
- /** Decompress batches */
41
- async *decompressBatches(asyncIterator) {
42
- // TODO - implement incremental compression
43
- const input = await this.concatenate(asyncIterator);
44
- yield this.decompress(input);
45
- }
46
- // HELPERS
47
- concatenate(asyncIterator) {
48
- return (0, loader_utils_1.concatenateArrayBuffersAsync)(asyncIterator);
49
- }
50
- improveError(error) {
51
- if (!error.message.includes(this.name)) {
52
- error.message = `${this.name} ${error.message}`;
53
- }
54
- return error;
55
- }
56
- }
57
- exports.Compression = Compression;
@@ -1,135 +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.DeflateCompression = void 0;
7
- const compression_1 = require("./compression");
8
- const loader_utils_1 = require("@loaders.gl/loader-utils");
9
- const pako_1 = __importDefault(require("pako")); // https://bundlephobia.com/package/pako
10
- const zlib_1 = __importDefault(require("zlib"));
11
- const loader_utils_2 = require("@loaders.gl/loader-utils");
12
- /**
13
- * DEFLATE compression / decompression
14
- */
15
- class DeflateCompression extends compression_1.Compression {
16
- constructor(options = {}) {
17
- super(options);
18
- this.name = 'deflate';
19
- this.extensions = [];
20
- this.contentEncodings = ['deflate'];
21
- this.isSupported = true;
22
- this._chunks = [];
23
- this.options = options;
24
- }
25
- async compress(input) {
26
- // On Node.js we can use built-in zlib
27
- if (!loader_utils_1.isBrowser && this.options.deflate?.useZlib) {
28
- const buffer = this.options.deflate?.gzip
29
- ? await (0, loader_utils_2.promisify1)(zlib_1.default.gzip)(input)
30
- : await (0, loader_utils_2.promisify1)(zlib_1.default.deflate)(input);
31
- return (0, loader_utils_1.toArrayBuffer)(buffer);
32
- }
33
- return this.compressSync(input);
34
- }
35
- async decompress(input) {
36
- // On Node.js we can use built-in zlib
37
- if (!loader_utils_1.isBrowser && this.options.deflate?.useZlib) {
38
- const buffer = this.options.deflate?.gzip
39
- ? await (0, loader_utils_2.promisify1)(zlib_1.default.gunzip)(input)
40
- : await (0, loader_utils_2.promisify1)(zlib_1.default.inflate)(input);
41
- return (0, loader_utils_1.toArrayBuffer)(buffer);
42
- }
43
- return this.decompressSync(input);
44
- }
45
- compressSync(input) {
46
- // On Node.js we can use built-in zlib
47
- if (!loader_utils_1.isBrowser && this.options.deflate?.useZlib) {
48
- const buffer = this.options.deflate?.gzip ? zlib_1.default.gzipSync(input) : zlib_1.default.deflateSync(input);
49
- return (0, loader_utils_1.toArrayBuffer)(buffer);
50
- }
51
- const pakoOptions = this.options?.deflate || {};
52
- const inputArray = new Uint8Array(input);
53
- return pako_1.default.deflate(inputArray, pakoOptions).buffer;
54
- }
55
- decompressSync(input) {
56
- // On Node.js we can use built-in zlib
57
- if (!loader_utils_1.isBrowser && this.options.deflate?.useZlib) {
58
- const buffer = this.options.deflate?.gzip ? zlib_1.default.gunzipSync(input) : zlib_1.default.inflateSync(input);
59
- return (0, loader_utils_1.toArrayBuffer)(buffer);
60
- }
61
- const pakoOptions = this.options?.deflate || {};
62
- const inputArray = new Uint8Array(input);
63
- return pako_1.default.inflate(inputArray, pakoOptions).buffer;
64
- }
65
- async *compressBatches(asyncIterator) {
66
- const pakoOptions = this.options?.deflate || {};
67
- const pakoProcessor = new pako_1.default.Deflate(pakoOptions);
68
- yield* this.transformBatches(pakoProcessor, asyncIterator);
69
- }
70
- async *decompressBatches(asyncIterator) {
71
- const pakoOptions = this.options?.deflate || {};
72
- const pakoProcessor = new pako_1.default.Inflate(pakoOptions);
73
- yield* this.transformBatches(pakoProcessor, asyncIterator);
74
- }
75
- async *transformBatches(pakoProcessor, asyncIterator) {
76
- pakoProcessor.onData = this._onData.bind(this);
77
- pakoProcessor.onEnd = this._onEnd.bind(this);
78
- for await (const chunk of asyncIterator) {
79
- const uint8Array = new Uint8Array(chunk);
80
- const ok = pakoProcessor.push(uint8Array, false); // false -> not last chunk
81
- if (!ok) {
82
- throw new Error(`${this._getError()}write`);
83
- }
84
- const chunks = this._getChunks();
85
- yield* chunks;
86
- }
87
- // End
88
- const emptyChunk = new Uint8Array(0);
89
- const ok = pakoProcessor.push(emptyChunk, true); // true -> last chunk
90
- if (!ok) {
91
- // For some reason we get error but it still works???
92
- // throw new Error(this._getError() + 'end');
93
- }
94
- const chunks = this._getChunks();
95
- yield* chunks;
96
- }
97
- _onData(chunk) {
98
- this._chunks.push(chunk);
99
- }
100
- _onEnd(status) {
101
- if (status !== 0) {
102
- throw new Error(this._getError(status) + this._chunks.length);
103
- }
104
- }
105
- _getChunks() {
106
- const chunks = this._chunks;
107
- this._chunks = [];
108
- return chunks;
109
- }
110
- // TODO - For some reason we don't get the error message from pako in _onEnd?
111
- _getError(code = 0) {
112
- const MESSAGES = {
113
- /* Z_NEED_DICT 2 */
114
- 2: 'need dictionary',
115
- /* Z_STREAM_END 1 */
116
- 1: 'stream end',
117
- /* Z_OK 0 */
118
- 0: '',
119
- /* Z_ERRNO (-1) */
120
- '-1': 'file error',
121
- /* Z_STREAM_ERROR (-2) */
122
- '-2': 'stream error',
123
- /* Z_DATA_ERROR (-3) */
124
- '-3': 'data error',
125
- /* Z_MEM_ERROR (-4) */
126
- '-4': 'insufficient memory',
127
- /* Z_BUF_ERROR (-5) */
128
- '-5': 'buffer error',
129
- /* Z_VERSION_ERROR (-6) */
130
- '-6': 'incompatible version'
131
- };
132
- return `${this.name}: ${MESSAGES[code]}`;
133
- }
134
- }
135
- exports.DeflateCompression = DeflateCompression;
@@ -1,17 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.GZipCompression = void 0;
4
- const deflate_compression_1 = require("./deflate-compression");
5
- /**
6
- * GZIP compression / decompression
7
- */
8
- class GZipCompression extends deflate_compression_1.DeflateCompression {
9
- constructor(options) {
10
- super({ ...options, deflate: { ...options?.gzip, gzip: true } });
11
- this.name = 'gzip';
12
- this.extensions = ['gz', 'gzip'];
13
- this.contentEncodings = ['gzip', 'x-gzip'];
14
- this.isSupported = true;
15
- }
16
- }
17
- exports.GZipCompression = GZipCompression;
@@ -1,141 +0,0 @@
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;
@@ -1,58 +0,0 @@
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;
@@ -1,30 +0,0 @@
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;
@@ -1,27 +0,0 @@
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;
@@ -1,47 +0,0 @@
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
- // eslint-disable-next-line no-console
26
- console.warn(`${this.name} library not installed`);
27
- }
28
- }
29
- async preload() {
30
- if (!zstd && ZstdCodec) {
31
- zstd = await new Promise((resolve) => ZstdCodec.run((zstd) => resolve(zstd)));
32
- }
33
- }
34
- compressSync(input) {
35
- const simpleZstd = new zstd.Simple();
36
- const inputArray = new Uint8Array(input);
37
- return simpleZstd.compress(inputArray).buffer;
38
- }
39
- decompressSync(input) {
40
- const simpleZstd = new zstd.Simple();
41
- // var ddict = new zstd.Dict.Decompression(dictData);
42
- // var jsonBytes = simpleZstd.decompressUsingDict(jsonZstData, ddict);
43
- const inputArray = new Uint8Array(input);
44
- return simpleZstd.decompress(inputArray).buffer;
45
- }
46
- }
47
- exports.ZstdCompression = ZstdCompression;
package/dist/types.js DELETED
@@ -1,2 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });