@loaders.gl/compression 3.4.14 → 3.4.15
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.
- package/dist/es5/brotli/decode.js +331 -331
- package/dist/es5/brotli/decode.js.map +1 -1
- package/dist/es5/bundle.js +1 -1
- package/dist/es5/bundle.js.map +1 -1
- package/dist/es5/compression-worker.js +3 -3
- package/dist/es5/compression-worker.js.map +1 -1
- package/dist/es5/index.js +11 -11
- package/dist/es5/lib/brotli-compression.js +67 -146
- package/dist/es5/lib/brotli-compression.js.map +1 -1
- package/dist/es5/lib/compression.js +36 -141
- package/dist/es5/lib/compression.js.map +1 -1
- package/dist/es5/lib/deflate-compression.js +103 -296
- package/dist/es5/lib/deflate-compression.js.map +1 -1
- package/dist/es5/lib/gzip-compression.js +13 -27
- package/dist/es5/lib/gzip-compression.js.map +1 -1
- package/dist/es5/lib/lz4-compression.js +71 -94
- package/dist/es5/lib/lz4-compression.js.map +1 -1
- package/dist/es5/lib/lzo-compression.js +28 -100
- package/dist/es5/lib/lzo-compression.js.map +1 -1
- package/dist/es5/lib/no-compression.js +22 -75
- package/dist/es5/lib/no-compression.js.map +1 -1
- package/dist/es5/lib/snappy-compression.js +16 -35
- package/dist/es5/lib/snappy-compression.js.map +1 -1
- package/dist/es5/lib/zstd-compression.js +28 -74
- package/dist/es5/lib/zstd-compression.js.map +1 -1
- package/dist/es5/workers/worker.js +23 -51
- package/dist/es5/workers/worker.js.map +1 -1
- package/dist/esm/compression-worker.js +1 -1
- package/package.json +4 -4
|
@@ -5,115 +5,92 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
value: true
|
|
6
6
|
});
|
|
7
7
|
exports.LZ4Compression = void 0;
|
|
8
|
-
var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));
|
|
9
|
-
var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
|
|
10
|
-
var _assertThisInitialized2 = _interopRequireDefault(require("@babel/runtime/helpers/assertThisInitialized"));
|
|
11
|
-
var _inherits2 = _interopRequireDefault(require("@babel/runtime/helpers/inherits"));
|
|
12
|
-
var _possibleConstructorReturn2 = _interopRequireDefault(require("@babel/runtime/helpers/possibleConstructorReturn"));
|
|
13
|
-
var _getPrototypeOf2 = _interopRequireDefault(require("@babel/runtime/helpers/getPrototypeOf"));
|
|
14
8
|
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
15
9
|
var _loaderUtils = require("@loaders.gl/loader-utils");
|
|
16
10
|
var _compression = require("./compression");
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
var LZ4Compression = function (_Compression) {
|
|
22
|
-
(0, _inherits2.default)(LZ4Compression, _Compression);
|
|
23
|
-
var _super = _createSuper(LZ4Compression);
|
|
24
|
-
function LZ4Compression(options) {
|
|
11
|
+
const LZ4_MAGIC_NUMBER = 0x184d2204;
|
|
12
|
+
let lz4js;
|
|
13
|
+
class LZ4Compression extends _compression.Compression {
|
|
14
|
+
constructor(options) {
|
|
25
15
|
var _this$options, _this$options$modules;
|
|
26
|
-
|
|
27
|
-
(0,
|
|
28
|
-
|
|
29
|
-
(0, _defineProperty2.default)(
|
|
30
|
-
(0, _defineProperty2.default)(
|
|
31
|
-
(0, _defineProperty2.default)(
|
|
32
|
-
|
|
33
|
-
(
|
|
34
|
-
_this.options = options;
|
|
35
|
-
lz4js = lz4js || ((_this$options = _this.options) === null || _this$options === void 0 ? void 0 : (_this$options$modules = _this$options.modules) === null || _this$options$modules === void 0 ? void 0 : _this$options$modules.lz4js);
|
|
16
|
+
super(options);
|
|
17
|
+
(0, _defineProperty2.default)(this, "name", 'lz4');
|
|
18
|
+
(0, _defineProperty2.default)(this, "extensions", ['lz4']);
|
|
19
|
+
(0, _defineProperty2.default)(this, "contentEncodings", ['x-lz4']);
|
|
20
|
+
(0, _defineProperty2.default)(this, "isSupported", true);
|
|
21
|
+
(0, _defineProperty2.default)(this, "options", void 0);
|
|
22
|
+
this.options = options;
|
|
23
|
+
lz4js = lz4js || ((_this$options = this.options) === null || _this$options === void 0 ? void 0 : (_this$options$modules = _this$options.modules) === null || _this$options$modules === void 0 ? void 0 : _this$options$modules.lz4js);
|
|
36
24
|
if (!lz4js) {
|
|
37
|
-
throw new Error(
|
|
25
|
+
throw new Error(this.name);
|
|
38
26
|
}
|
|
39
|
-
return _this;
|
|
40
27
|
}
|
|
41
|
-
(
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
return lz4js.decompress(inputArray, maxSize).buffer;
|
|
55
|
-
}
|
|
56
|
-
if (!maxSize) {
|
|
57
|
-
var error = new Error('Need to provide maxSize');
|
|
58
|
-
throw this.improveError(error);
|
|
59
|
-
}
|
|
60
|
-
var uncompressed = new Uint8Array(maxSize);
|
|
61
|
-
var uncompressedSize = this.decodeBlock(inputArray, uncompressed);
|
|
62
|
-
uncompressed = uncompressed.slice(0, uncompressedSize);
|
|
63
|
-
return (0, _loaderUtils.toArrayBuffer)(uncompressed);
|
|
64
|
-
} catch (error) {
|
|
28
|
+
compressSync(input) {
|
|
29
|
+
const inputArray = new Uint8Array(input);
|
|
30
|
+
return lz4js.compress(inputArray).buffer;
|
|
31
|
+
}
|
|
32
|
+
decompressSync(data, maxSize) {
|
|
33
|
+
try {
|
|
34
|
+
const isMagicNumberExists = this.checkMagicNumber(data);
|
|
35
|
+
const inputArray = new Uint8Array(data);
|
|
36
|
+
if (isMagicNumberExists) {
|
|
37
|
+
return lz4js.decompress(inputArray, maxSize).buffer;
|
|
38
|
+
}
|
|
39
|
+
if (!maxSize) {
|
|
40
|
+
const error = new Error('Need to provide maxSize');
|
|
65
41
|
throw this.improveError(error);
|
|
66
42
|
}
|
|
43
|
+
let uncompressed = new Uint8Array(maxSize);
|
|
44
|
+
const uncompressedSize = this.decodeBlock(inputArray, uncompressed);
|
|
45
|
+
uncompressed = uncompressed.slice(0, uncompressedSize);
|
|
46
|
+
return (0, _loaderUtils.toArrayBuffer)(uncompressed);
|
|
47
|
+
} catch (error) {
|
|
48
|
+
throw this.improveError(error);
|
|
67
49
|
}
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
var _length = literalsLength + 240;
|
|
79
|
-
while (_length === 255) {
|
|
80
|
-
_length = data[index++];
|
|
81
|
-
literalsLength += _length;
|
|
82
|
-
}
|
|
83
|
-
var _end = index + literalsLength;
|
|
84
|
-
while (index < _end) {
|
|
85
|
-
output[uncompressedSize++] = data[index++];
|
|
86
|
-
}
|
|
87
|
-
if (index === endIndex) {
|
|
88
|
-
return uncompressedSize;
|
|
89
|
-
}
|
|
90
|
-
}
|
|
91
|
-
var offset = data[index++] | data[index++] << 8;
|
|
92
|
-
if (offset === 0 || offset > uncompressedSize) {
|
|
93
|
-
return -(index - 2);
|
|
94
|
-
}
|
|
95
|
-
var matchLength = token & 0xf;
|
|
96
|
-
var length = matchLength + 240;
|
|
50
|
+
}
|
|
51
|
+
decodeBlock(data, output, startIndex, endIndex) {
|
|
52
|
+
startIndex = startIndex || 0;
|
|
53
|
+
endIndex = endIndex || data.length - startIndex;
|
|
54
|
+
let uncompressedSize = 0;
|
|
55
|
+
for (let index = startIndex; index < endIndex;) {
|
|
56
|
+
const token = data[index++];
|
|
57
|
+
let literalsLength = token >> 4;
|
|
58
|
+
if (literalsLength > 0) {
|
|
59
|
+
let length = literalsLength + 240;
|
|
97
60
|
while (length === 255) {
|
|
98
61
|
length = data[index++];
|
|
99
|
-
|
|
62
|
+
literalsLength += length;
|
|
100
63
|
}
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
64
|
+
const end = index + literalsLength;
|
|
65
|
+
while (index < end) {
|
|
66
|
+
output[uncompressedSize++] = data[index++];
|
|
67
|
+
}
|
|
68
|
+
if (index === endIndex) {
|
|
69
|
+
return uncompressedSize;
|
|
105
70
|
}
|
|
106
71
|
}
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
72
|
+
const offset = data[index++] | data[index++] << 8;
|
|
73
|
+
if (offset === 0 || offset > uncompressedSize) {
|
|
74
|
+
return -(index - 2);
|
|
75
|
+
}
|
|
76
|
+
let matchLength = token & 0xf;
|
|
77
|
+
let length = matchLength + 240;
|
|
78
|
+
while (length === 255) {
|
|
79
|
+
length = data[index++];
|
|
80
|
+
matchLength += length;
|
|
81
|
+
}
|
|
82
|
+
let pos = uncompressedSize - offset;
|
|
83
|
+
const end = uncompressedSize + matchLength + 4;
|
|
84
|
+
while (uncompressedSize < end) {
|
|
85
|
+
output[uncompressedSize++] = output[pos++];
|
|
86
|
+
}
|
|
114
87
|
}
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
88
|
+
return uncompressedSize;
|
|
89
|
+
}
|
|
90
|
+
checkMagicNumber(data) {
|
|
91
|
+
const magic = new Uint32Array(data.slice(0, 4));
|
|
92
|
+
return magic[0] === LZ4_MAGIC_NUMBER;
|
|
93
|
+
}
|
|
94
|
+
}
|
|
118
95
|
exports.LZ4Compression = LZ4Compression;
|
|
119
96
|
//# sourceMappingURL=lz4-compression.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"lz4-compression.js","names":["_loaderUtils","require","_compression","_createSuper","Derived","hasNativeReflectConstruct","_isNativeReflectConstruct","_createSuperInternal","Super","_getPrototypeOf2","default","result","NewTarget","constructor","Reflect","construct","arguments","apply","_possibleConstructorReturn2","sham","Proxy","Boolean","prototype","valueOf","call","e","LZ4_MAGIC_NUMBER","lz4js","LZ4Compression","_Compression","_inherits2","_super","options","_this$options","_this$options$modules","_this","_classCallCheck2","_defineProperty2","_assertThisInitialized2","modules","Error","name","_createClass2","key","value","compressSync","input","inputArray","Uint8Array","compress","buffer","decompressSync","data","maxSize","isMagicNumberExists","checkMagicNumber","decompress","error","improveError","uncompressed","uncompressedSize","decodeBlock","slice","toArrayBuffer","output","startIndex","endIndex","length","index","token","literalsLength","end","offset","matchLength","pos","magic","Uint32Array","Compression","exports"],"sources":["../../../src/lib/lz4-compression.ts"],"sourcesContent":["// Copyright (c) 2012 Pierre Curto\n\n// Permission is hereby granted, free of charge, to any person obtaining a copy\n// of this software and associated documentation files (the \"Software\"), to deal\n// in the Software without restriction, including without limitation the rights\n// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n// copies of the Software, and to permit persons to whom the Software is\n// furnished to do so, subject to the following conditions:\n\n// The above copyright notice and this permission notice shall be included in\n// all copies or substantial portions of the Software.\n\n// THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN\n// THE SOFTWARE.\n\n/* eslint-disable complexity */\n/* eslint-disable max-statements */\n\n// LZ4\nimport {toArrayBuffer} from '@loaders.gl/loader-utils';\nimport type {CompressionOptions} from './compression';\nimport {Compression} from './compression';\n// import lz4js from 'lz4js'; // https://bundlephobia.com/package/lz4\nconst LZ4_MAGIC_NUMBER = 0x184d2204;\n\nlet lz4js;\n\n/**\n * LZ4 compression / decompression\n */\nexport class LZ4Compression extends Compression {\n readonly name: string = 'lz4';\n readonly extensions = ['lz4'];\n readonly contentEncodings = ['x-lz4'];\n readonly isSupported = true;\n readonly options: CompressionOptions;\n\n constructor(options: CompressionOptions) {\n super(options);\n this.options = options;\n\n lz4js = lz4js || this.options?.modules?.lz4js;\n if (!lz4js) {\n throw new Error(this.name);\n }\n }\n\n compressSync(input: ArrayBuffer): ArrayBuffer {\n const inputArray = new Uint8Array(input);\n return lz4js.compress(inputArray).buffer;\n }\n\n /**\n * Decompresses an ArrayBuffer containing an Lz4 frame. maxSize is optional; if not\n * provided, a maximum size will be determined by examining the data. The\n * returned ArrayBuffer will always be perfectly sized.\n * If data provided without magic number we will parse it as block\n */\n decompressSync(data: ArrayBuffer, maxSize?: number): ArrayBuffer {\n try {\n const isMagicNumberExists = this.checkMagicNumber(data);\n const inputArray = new Uint8Array(data);\n\n if (isMagicNumberExists) {\n return lz4js.decompress(inputArray, maxSize).buffer;\n }\n\n if (!maxSize) {\n const error = new Error('Need to provide maxSize');\n throw this.improveError(error);\n }\n\n let uncompressed = new Uint8Array(maxSize);\n const uncompressedSize = this.decodeBlock(inputArray, uncompressed);\n uncompressed = uncompressed.slice(0, uncompressedSize);\n\n return toArrayBuffer(uncompressed);\n } catch (error) {\n throw this.improveError(error);\n }\n }\n\n /**\n * Decode lz4 file as block\n * Solution taken from here\n * https://github.com/pierrec/node-lz4/blob/0dac687262403fd34f905b963da7220692f2a4a1/lib/binding.js#L25\n * @param input\n * @param output\n * @param startIndex\n * @param endIndex\n */\n decodeBlock(\n data: Uint8Array,\n output: Uint8Array,\n startIndex?: number,\n endIndex?: number\n ): number {\n startIndex = startIndex || 0;\n endIndex = endIndex || data.length - startIndex;\n\n let uncompressedSize = 0;\n // Process each sequence in the incoming data\n for (let index = startIndex; index < endIndex; ) {\n const token = data[index++];\n\n // Literals\n let literalsLength = token >> 4;\n\n if (literalsLength > 0) {\n // length of literals\n let length = literalsLength + 240;\n\n while (length === 255) {\n length = data[index++];\n literalsLength += length;\n }\n\n // Copy the literals\n const end = index + literalsLength;\n\n while (index < end) {\n output[uncompressedSize++] = data[index++];\n }\n\n // End of buffer?\n if (index === endIndex) {\n return uncompressedSize;\n }\n }\n\n // Match copy\n // 2 bytes offset (little endian)\n const offset = data[index++] | (data[index++] << 8);\n\n // 0 is an invalid offset value\n if (offset === 0 || offset > uncompressedSize) {\n return -(index - 2);\n }\n\n // length of match copy\n let matchLength = token & 0xf;\n let length = matchLength + 240;\n\n while (length === 255) {\n length = data[index++];\n matchLength += length;\n }\n\n // Copy the match\n let pos = uncompressedSize - offset; // position of the match copy in the current output\n const end = uncompressedSize + matchLength + 4; // minmatch = 4\n\n while (uncompressedSize < end) {\n output[uncompressedSize++] = output[pos++];\n }\n }\n\n return uncompressedSize;\n }\n\n /**\n * Compare file magic with lz4 magic number\n * @param input\n */\n checkMagicNumber(data: ArrayBuffer): boolean {\n const magic = new Uint32Array(data.slice(0, 4));\n return magic[0] === LZ4_MAGIC_NUMBER;\n }\n}\n"],"mappings":";;;;;;;;;;;;;;AAwBA,IAAAA,YAAA,GAAAC,OAAA;AAEA,IAAAC,YAAA,GAAAD,OAAA;AAA0C,SAAAE,aAAAC,OAAA,QAAAC,yBAAA,GAAAC,yBAAA,oBAAAC,qBAAA,QAAAC,KAAA,OAAAC,gBAAA,CAAAC,OAAA,EAAAN,OAAA,GAAAO,MAAA,MAAAN,yBAAA,QAAAO,SAAA,OAAAH,gBAAA,CAAAC,OAAA,QAAAG,WAAA,EAAAF,MAAA,GAAAG,OAAA,CAAAC,SAAA,CAAAP,KAAA,EAAAQ,SAAA,EAAAJ,SAAA,YAAAD,MAAA,GAAAH,KAAA,CAAAS,KAAA,OAAAD,SAAA,gBAAAE,2BAAA,CAAAR,OAAA,QAAAC,MAAA;AAAA,SAAAL,0BAAA,eAAAQ,OAAA,qBAAAA,OAAA,CAAAC,SAAA,oBAAAD,OAAA,CAAAC,SAAA,CAAAI,IAAA,2BAAAC,KAAA,oCAAAC,OAAA,CAAAC,SAAA,CAAAC,OAAA,C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AAGX,gBAAgB,GAAGa,WAAW,GAAG,CAAC;QAE9C,OAAOb,gBAAgB,GAAGW,GAAG,EAAE;UAC7BP,MAAM,CAACJ,gBAAgB,EAAE,CAAC,GAAGI,MAAM,CAACU,GAAG,EAAE,CAAC;QAC5C;MACF;MAEA,OAAOd,gBAAgB;IACzB;EAAC;IAAAjB,GAAA;IAAAC,KAAA,EAMD,SAAAW,iBAAiBH,IAAiB,EAAW;MAC3C,IAAMuB,KAAK,GAAG,IAAIC,WAAW,CAACxB,IAAI,CAACU,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;MAC/C,OAAOa,KAAK,CAAC,CAAC,CAAC,KAAKjD,gBAAgB;IACtC;EAAC;EAAA,OAAAE,cAAA;AAAA,EAzIiCiD,wBAAW;AAAAC,OAAA,CAAAlD,cAAA,GAAAA,cAAA"}
|
|
1
|
+
{"version":3,"file":"lz4-compression.js","names":["_loaderUtils","require","_compression","LZ4_MAGIC_NUMBER","lz4js","LZ4Compression","Compression","constructor","options","_this$options","_this$options$modules","_defineProperty2","default","modules","Error","name","compressSync","input","inputArray","Uint8Array","compress","buffer","decompressSync","data","maxSize","isMagicNumberExists","checkMagicNumber","decompress","error","improveError","uncompressed","uncompressedSize","decodeBlock","slice","toArrayBuffer","output","startIndex","endIndex","length","index","token","literalsLength","end","offset","matchLength","pos","magic","Uint32Array","exports"],"sources":["../../../src/lib/lz4-compression.ts"],"sourcesContent":["// Copyright (c) 2012 Pierre Curto\n\n// Permission is hereby granted, free of charge, to any person obtaining a copy\n// of this software and associated documentation files (the \"Software\"), to deal\n// in the Software without restriction, including without limitation the rights\n// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n// copies of the Software, and to permit persons to whom the Software is\n// furnished to do so, subject to the following conditions:\n\n// The above copyright notice and this permission notice shall be included in\n// all copies or substantial portions of the Software.\n\n// THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN\n// THE SOFTWARE.\n\n/* eslint-disable complexity */\n/* eslint-disable max-statements */\n\n// LZ4\nimport {toArrayBuffer} from '@loaders.gl/loader-utils';\nimport type {CompressionOptions} from './compression';\nimport {Compression} from './compression';\n// import lz4js from 'lz4js'; // https://bundlephobia.com/package/lz4\nconst LZ4_MAGIC_NUMBER = 0x184d2204;\n\nlet lz4js;\n\n/**\n * LZ4 compression / decompression\n */\nexport class LZ4Compression extends Compression {\n readonly name: string = 'lz4';\n readonly extensions = ['lz4'];\n readonly contentEncodings = ['x-lz4'];\n readonly isSupported = true;\n readonly options: CompressionOptions;\n\n constructor(options: CompressionOptions) {\n super(options);\n this.options = options;\n\n lz4js = lz4js || this.options?.modules?.lz4js;\n if (!lz4js) {\n throw new Error(this.name);\n }\n }\n\n compressSync(input: ArrayBuffer): ArrayBuffer {\n const inputArray = new Uint8Array(input);\n return lz4js.compress(inputArray).buffer;\n }\n\n /**\n * Decompresses an ArrayBuffer containing an Lz4 frame. maxSize is optional; if not\n * provided, a maximum size will be determined by examining the data. The\n * returned ArrayBuffer will always be perfectly sized.\n * If data provided without magic number we will parse it as block\n */\n decompressSync(data: ArrayBuffer, maxSize?: number): ArrayBuffer {\n try {\n const isMagicNumberExists = this.checkMagicNumber(data);\n const inputArray = new Uint8Array(data);\n\n if (isMagicNumberExists) {\n return lz4js.decompress(inputArray, maxSize).buffer;\n }\n\n if (!maxSize) {\n const error = new Error('Need to provide maxSize');\n throw this.improveError(error);\n }\n\n let uncompressed = new Uint8Array(maxSize);\n const uncompressedSize = this.decodeBlock(inputArray, uncompressed);\n uncompressed = uncompressed.slice(0, uncompressedSize);\n\n return toArrayBuffer(uncompressed);\n } catch (error) {\n throw this.improveError(error);\n }\n }\n\n /**\n * Decode lz4 file as block\n * Solution taken from here\n * https://github.com/pierrec/node-lz4/blob/0dac687262403fd34f905b963da7220692f2a4a1/lib/binding.js#L25\n * @param input\n * @param output\n * @param startIndex\n * @param endIndex\n */\n decodeBlock(\n data: Uint8Array,\n output: Uint8Array,\n startIndex?: number,\n endIndex?: number\n ): number {\n startIndex = startIndex || 0;\n endIndex = endIndex || data.length - startIndex;\n\n let uncompressedSize = 0;\n // Process each sequence in the incoming data\n for (let index = startIndex; index < endIndex; ) {\n const token = data[index++];\n\n // Literals\n let literalsLength = token >> 4;\n\n if (literalsLength > 0) {\n // length of literals\n let length = literalsLength + 240;\n\n while (length === 255) {\n length = data[index++];\n literalsLength += length;\n }\n\n // Copy the literals\n const end = index + literalsLength;\n\n while (index < end) {\n output[uncompressedSize++] = data[index++];\n }\n\n // End of buffer?\n if (index === endIndex) {\n return uncompressedSize;\n }\n }\n\n // Match copy\n // 2 bytes offset (little endian)\n const offset = data[index++] | (data[index++] << 8);\n\n // 0 is an invalid offset value\n if (offset === 0 || offset > uncompressedSize) {\n return -(index - 2);\n }\n\n // length of match copy\n let matchLength = token & 0xf;\n let length = matchLength + 240;\n\n while (length === 255) {\n length = data[index++];\n matchLength += length;\n }\n\n // Copy the match\n let pos = uncompressedSize - offset; // position of the match copy in the current output\n const end = uncompressedSize + matchLength + 4; // minmatch = 4\n\n while (uncompressedSize < end) {\n output[uncompressedSize++] = output[pos++];\n }\n }\n\n return uncompressedSize;\n }\n\n /**\n * Compare file magic with lz4 magic number\n * @param input\n */\n checkMagicNumber(data: ArrayBuffer): boolean {\n const magic = new Uint32Array(data.slice(0, 4));\n return magic[0] === LZ4_MAGIC_NUMBER;\n }\n}\n"],"mappings":";;;;;;;;AAwBA,IAAAA,YAAA,GAAAC,O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gB,KAAK,EAAE,CAAC;QAC5C;QAGA,IAAIA,KAAK,KAAKF,QAAQ,EAAE;UACtB,OAAON,gBAAgB;QACzB;MACF;MAIA,MAAMY,MAAM,GAAGpB,IAAI,CAACgB,KAAK,EAAE,CAAC,GAAIhB,IAAI,CAACgB,KAAK,EAAE,CAAC,IAAI,CAAE;MAGnD,IAAII,MAAM,KAAK,CAAC,IAAIA,MAAM,GAAGZ,gBAAgB,EAAE;QAC7C,OAAO,EAAEQ,KAAK,GAAG,CAAC,CAAC;MACrB;MAGA,IAAIK,WAAW,GAAGJ,KAAK,GAAG,GAAG;MAC7B,IAAIF,MAAM,GAAGM,WAAW,GAAG,GAAG;MAE9B,OAAON,MAAM,KAAK,GAAG,EAAE;QACrBA,MAAM,GAAGf,IAAI,CAACgB,KAAK,EAAE,CAAC;QACtBK,WAAW,IAAIN,MAAM;MACvB;MAGA,IAAIO,GAAG,GAAGd,gBAAgB,GAAGY,MAAM;MACnC,MAAMD,GAAG,GAAGX,gBAAgB,GAAGa,WAAW,GAAG,CAAC;MAE9C,OAAOb,gBAAgB,GAAGW,GAAG,EAAE;QAC7BP,MAAM,CAACJ,gBAAgB,EAAE,CAAC,GAAGI,MAAM,CAACU,GAAG,EAAE,CAAC;MAC5C;IACF;IAEA,OAAOd,gBAAgB;EACzB;EAMAL,gBAAgBA,CAACH,IAAiB,EAAW;IAC3C,MAAMuB,KAAK,GAAG,IAAIC,WAAW,CAACxB,IAAI,CAACU,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;IAC/C,OAAOa,KAAK,CAAC,CAAC,CAAC,KAAK3C,gBAAgB;EACtC;AACF;AAAC6C,OAAA,CAAA3C,cAAA,GAAAA,cAAA"}
|
|
@@ -5,112 +5,40 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
value: true
|
|
6
6
|
});
|
|
7
7
|
exports.LZOCompression = void 0;
|
|
8
|
-
var _regenerator = _interopRequireDefault(require("@babel/runtime/regenerator"));
|
|
9
|
-
var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator"));
|
|
10
|
-
var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));
|
|
11
|
-
var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
|
|
12
|
-
var _assertThisInitialized2 = _interopRequireDefault(require("@babel/runtime/helpers/assertThisInitialized"));
|
|
13
|
-
var _inherits2 = _interopRequireDefault(require("@babel/runtime/helpers/inherits"));
|
|
14
|
-
var _possibleConstructorReturn2 = _interopRequireDefault(require("@babel/runtime/helpers/possibleConstructorReturn"));
|
|
15
|
-
var _getPrototypeOf2 = _interopRequireDefault(require("@babel/runtime/helpers/getPrototypeOf"));
|
|
16
8
|
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
17
9
|
var _loaderUtils = require("@loaders.gl/loader-utils");
|
|
18
10
|
var _compression = require("./compression");
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
var LZOCompression = function (_Compression) {
|
|
23
|
-
(0, _inherits2.default)(LZOCompression, _Compression);
|
|
24
|
-
var _super = _createSuper(LZOCompression);
|
|
25
|
-
function LZOCompression(options) {
|
|
11
|
+
let lzo;
|
|
12
|
+
class LZOCompression extends _compression.Compression {
|
|
13
|
+
constructor(options) {
|
|
26
14
|
var _this$options, _this$options$modules;
|
|
27
|
-
|
|
28
|
-
(0,
|
|
29
|
-
|
|
30
|
-
(0, _defineProperty2.default)(
|
|
31
|
-
(0, _defineProperty2.default)(
|
|
32
|
-
(0, _defineProperty2.default)(
|
|
33
|
-
|
|
34
|
-
(
|
|
35
|
-
_this.options = options;
|
|
36
|
-
lzo = lzo || ((_this$options = _this.options) === null || _this$options === void 0 ? void 0 : (_this$options$modules = _this$options.modules) === null || _this$options$modules === void 0 ? void 0 : _this$options$modules.lzo);
|
|
15
|
+
super(options);
|
|
16
|
+
(0, _defineProperty2.default)(this, "name", 'lzo');
|
|
17
|
+
(0, _defineProperty2.default)(this, "extensions", []);
|
|
18
|
+
(0, _defineProperty2.default)(this, "contentEncodings", []);
|
|
19
|
+
(0, _defineProperty2.default)(this, "isSupported", false);
|
|
20
|
+
(0, _defineProperty2.default)(this, "options", void 0);
|
|
21
|
+
this.options = options;
|
|
22
|
+
lzo = lzo || ((_this$options = this.options) === null || _this$options === void 0 ? void 0 : (_this$options$modules = _this$options.modules) === null || _this$options$modules === void 0 ? void 0 : _this$options$modules.lzo);
|
|
37
23
|
if (!lzo) {
|
|
38
|
-
throw new Error(
|
|
24
|
+
throw new Error(this.name);
|
|
39
25
|
}
|
|
40
|
-
return _this;
|
|
41
26
|
}
|
|
42
|
-
(
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
}()
|
|
59
|
-
}, {
|
|
60
|
-
key: "compress",
|
|
61
|
-
value: function () {
|
|
62
|
-
var _compress = (0, _asyncToGenerator2.default)(_regenerator.default.mark(function _callee2(input) {
|
|
63
|
-
var inputBuffer;
|
|
64
|
-
return _regenerator.default.wrap(function _callee2$(_context2) {
|
|
65
|
-
while (1) switch (_context2.prev = _context2.next) {
|
|
66
|
-
case 0:
|
|
67
|
-
_context2.next = 2;
|
|
68
|
-
return this.preload();
|
|
69
|
-
case 2:
|
|
70
|
-
inputBuffer = (0, _loaderUtils.toBuffer)(input);
|
|
71
|
-
return _context2.abrupt("return", lzo.compress(inputBuffer).buffer);
|
|
72
|
-
case 4:
|
|
73
|
-
case "end":
|
|
74
|
-
return _context2.stop();
|
|
75
|
-
}
|
|
76
|
-
}, _callee2, this);
|
|
77
|
-
}));
|
|
78
|
-
function compress(_x) {
|
|
79
|
-
return _compress.apply(this, arguments);
|
|
80
|
-
}
|
|
81
|
-
return compress;
|
|
82
|
-
}()
|
|
83
|
-
}, {
|
|
84
|
-
key: "decompress",
|
|
85
|
-
value: function () {
|
|
86
|
-
var _decompress = (0, _asyncToGenerator2.default)(_regenerator.default.mark(function _callee3(input) {
|
|
87
|
-
var inputBuffer;
|
|
88
|
-
return _regenerator.default.wrap(function _callee3$(_context3) {
|
|
89
|
-
while (1) switch (_context3.prev = _context3.next) {
|
|
90
|
-
case 0:
|
|
91
|
-
_context3.prev = 0;
|
|
92
|
-
_context3.next = 3;
|
|
93
|
-
return this.preload();
|
|
94
|
-
case 3:
|
|
95
|
-
inputBuffer = (0, _loaderUtils.toBuffer)(input);
|
|
96
|
-
return _context3.abrupt("return", lzo.decompress(inputBuffer).buffer);
|
|
97
|
-
case 7:
|
|
98
|
-
_context3.prev = 7;
|
|
99
|
-
_context3.t0 = _context3["catch"](0);
|
|
100
|
-
throw _context3.t0;
|
|
101
|
-
case 10:
|
|
102
|
-
case "end":
|
|
103
|
-
return _context3.stop();
|
|
104
|
-
}
|
|
105
|
-
}, _callee3, this, [[0, 7]]);
|
|
106
|
-
}));
|
|
107
|
-
function decompress(_x2) {
|
|
108
|
-
return _decompress.apply(this, arguments);
|
|
109
|
-
}
|
|
110
|
-
return decompress;
|
|
111
|
-
}()
|
|
112
|
-
}]);
|
|
113
|
-
return LZOCompression;
|
|
114
|
-
}(_compression.Compression);
|
|
27
|
+
async preload() {}
|
|
28
|
+
async compress(input) {
|
|
29
|
+
await this.preload();
|
|
30
|
+
const inputBuffer = (0, _loaderUtils.toBuffer)(input);
|
|
31
|
+
return lzo.compress(inputBuffer).buffer;
|
|
32
|
+
}
|
|
33
|
+
async decompress(input) {
|
|
34
|
+
try {
|
|
35
|
+
await this.preload();
|
|
36
|
+
const inputBuffer = (0, _loaderUtils.toBuffer)(input);
|
|
37
|
+
return lzo.decompress(inputBuffer).buffer;
|
|
38
|
+
} catch (error) {
|
|
39
|
+
throw error;
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
}
|
|
115
43
|
exports.LZOCompression = LZOCompression;
|
|
116
44
|
//# sourceMappingURL=lzo-compression.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"lzo-compression.js","names":["_loaderUtils","require","_compression","
|
|
1
|
+
{"version":3,"file":"lzo-compression.js","names":["_loaderUtils","require","_compression","lzo","LZOCompression","Compression","constructor","options","_this$options","_this$options$modules","_defineProperty2","default","modules","Error","name","preload","compress","input","inputBuffer","toBuffer","buffer","decompress","error","exports"],"sources":["../../../src/lib/lzo-compression.ts"],"sourcesContent":["// LZO\n// import {loadLibrary} from '@loaders.gl/worker-utils';\nimport {toBuffer} from '@loaders.gl/loader-utils';\n\nimport type {CompressionOptions} from './compression';\nimport {Compression} from './compression';\n// import {isBrowser} from '@loaders.gl/loader-utils';\n\n// import lzo from 'lzo'; // https://bundlephobia.com/package/lzo\n// import {decompress} from 'lzo-wasm';\n\n// const LZO_WASM_JS_URL = './node_modules/lzo-wasm/lzo-wasm.js';\n// const LZO_WASM_WASM_URL = './node_modules/lzo-wasm/lzo-wasm.wasm';\n\nlet lzo;\n\n/**\n * Lempel-Ziv-Oberheimer compression / decompression\n */\nexport class LZOCompression extends Compression {\n readonly name = 'lzo';\n readonly extensions = [];\n readonly contentEncodings = [];\n readonly isSupported = false; // !isBrowser;\n readonly options: CompressionOptions;\n\n /**\n * lzo is an injectable dependency due to big size\n * @param options\n */\n constructor(options: CompressionOptions) {\n super(options);\n this.options = options;\n\n lzo = lzo || this.options?.modules?.lzo;\n if (!lzo) {\n throw new Error(this.name);\n }\n }\n\n async preload() {\n // await loadLibrary(LZO_WASM_JS_URL);\n // await loadLibrary(LZO_WASM_WASM_URL);\n }\n\n async compress(input: ArrayBuffer): Promise<ArrayBuffer> {\n await this.preload();\n // const inputArray = new Uint8Array(input);\n const inputBuffer = toBuffer(input);\n return lzo.compress(inputBuffer).buffer;\n }\n\n async decompress(input: ArrayBuffer): Promise<ArrayBuffer> {\n try {\n await this.preload();\n // const inputArray = new Uint8Array(input);\n const inputBuffer = toBuffer(input);\n return lzo.decompress(inputBuffer).buffer;\n } catch (error) {\n // TODO - solve SharedArrayBuffer issues\n // return decompress(input);\n throw error;\n }\n }\n}\n"],"mappings":";;;;;;;;AAEA,IAAAA,YAAA,GAAAC,OAAA;AAGA,IAAAC,YAAA,GAAAD,OAAA;AASA,IAAIE,GAAG;AAKA,MAAMC,cAAc,SAASC,wBAAW,CAAC;EAW9CC,WAAWA,CAACC,OAA2B,EAAE;IAAA,IAAAC,aAAA,EAAAC,qBAAA;IACvC,KAAK,CAACF,OAAO,CAAC;IAAC,IAAAG,gBAAA,CAAAC,OAAA,gBAXD,KAAK;IAAA,IAAAD,gBAAA,CAAAC,OAAA,sBACC,EAAE;IAAA,IAAAD,gBAAA,CAAAC,OAAA,4BACI,EAAE;IAAA,IAAAD,gBAAA,CAAAC,OAAA,uBACP,KAAK;IAAA,IAAAD,gBAAA,CAAAC,OAAA;IAS1B,IAAI,CAACJ,OAAO,GAAGA,OAAO;IAEtBJ,GAAG,GAAGA,GAAG,MAAAK,aAAA,GAAI,IAAI,CAACD,OAAO,cAAAC,aAAA,wBAAAC,qBAAA,GAAZD,aAAA,CAAcI,OAAO,cAAAH,qBAAA,uBAArBA,qBAAA,CAAuBN,GAAG;IACvC,IAAI,CAACA,GAAG,EAAE;MACR,MAAM,IAAIU,KAAK,CAAC,IAAI,CAACC,IAAI,CAAC;IAC5B;EACF;EAEA,MAAMC,OAAOA,CAAA,EAAG,CAGhB;EAEA,MAAMC,QAAQA,CAACC,KAAkB,EAAwB;IACvD,MAAM,IAAI,CAACF,OAAO,CAAC,CAAC;IAEpB,MAAMG,WAAW,GAAG,IAAAC,qBAAQ,EAACF,KAAK,CAAC;IACnC,OAAOd,GAAG,CAACa,QAAQ,CAACE,WAAW,CAAC,CAACE,MAAM;EACzC;EAEA,MAAMC,UAAUA,CAACJ,KAAkB,EAAwB;IACzD,IAAI;MACF,MAAM,IAAI,CAACF,OAAO,CAAC,CAAC;MAEpB,MAAMG,WAAW,GAAG,IAAAC,qBAAQ,EAACF,KAAK,CAAC;MACnC,OAAOd,GAAG,CAACkB,UAAU,CAACH,WAAW,CAAC,CAACE,MAAM;IAC3C,CAAC,CAAC,OAAOE,KAAK,EAAE;MAGd,MAAMA,KAAK;IACb;EACF;AACF;AAACC,OAAA,CAAAnB,cAAA,GAAAA,cAAA"}
|
|
@@ -5,83 +5,30 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
value: true
|
|
6
6
|
});
|
|
7
7
|
exports.NoCompression = void 0;
|
|
8
|
-
var _regenerator = _interopRequireDefault(require("@babel/runtime/regenerator"));
|
|
9
|
-
var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));
|
|
10
|
-
var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
|
|
11
|
-
var _assertThisInitialized2 = _interopRequireDefault(require("@babel/runtime/helpers/assertThisInitialized"));
|
|
12
|
-
var _inherits2 = _interopRequireDefault(require("@babel/runtime/helpers/inherits"));
|
|
13
|
-
var _possibleConstructorReturn2 = _interopRequireDefault(require("@babel/runtime/helpers/possibleConstructorReturn"));
|
|
14
|
-
var _getPrototypeOf2 = _interopRequireDefault(require("@babel/runtime/helpers/getPrototypeOf"));
|
|
15
8
|
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
16
|
-
var _wrapAsyncGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/wrapAsyncGenerator"));
|
|
17
|
-
var _awaitAsyncGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/awaitAsyncGenerator"));
|
|
18
|
-
var _asyncGeneratorDelegate2 = _interopRequireDefault(require("@babel/runtime/helpers/asyncGeneratorDelegate"));
|
|
19
9
|
var _compression = require("./compression");
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
(0, _classCallCheck2.default)(this, NoCompression);
|
|
30
|
-
_this = _super.call(this, options);
|
|
31
|
-
(0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "name", 'uncompressed');
|
|
32
|
-
(0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "extensions", []);
|
|
33
|
-
(0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "contentEncodings", []);
|
|
34
|
-
(0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "isSupported", true);
|
|
35
|
-
(0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "options", void 0);
|
|
36
|
-
_this.options = options || {};
|
|
37
|
-
return _this;
|
|
10
|
+
class NoCompression extends _compression.Compression {
|
|
11
|
+
constructor(options) {
|
|
12
|
+
super(options);
|
|
13
|
+
(0, _defineProperty2.default)(this, "name", 'uncompressed');
|
|
14
|
+
(0, _defineProperty2.default)(this, "extensions", []);
|
|
15
|
+
(0, _defineProperty2.default)(this, "contentEncodings", []);
|
|
16
|
+
(0, _defineProperty2.default)(this, "isSupported", true);
|
|
17
|
+
(0, _defineProperty2.default)(this, "options", void 0);
|
|
18
|
+
this.options = options || {};
|
|
38
19
|
}
|
|
39
|
-
(
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
return (0, _wrapAsyncGenerator2.default)(_regenerator.default.mark(function _callee() {
|
|
53
|
-
return _regenerator.default.wrap(function _callee$(_context) {
|
|
54
|
-
while (1) switch (_context.prev = _context.next) {
|
|
55
|
-
case 0:
|
|
56
|
-
return _context.delegateYield((0, _asyncGeneratorDelegate2.default)(_asyncIterator(asyncIterator), _awaitAsyncGenerator2.default), "t0", 1);
|
|
57
|
-
case 1:
|
|
58
|
-
return _context.abrupt("return", _context.t0);
|
|
59
|
-
case 2:
|
|
60
|
-
case "end":
|
|
61
|
-
return _context.stop();
|
|
62
|
-
}
|
|
63
|
-
}, _callee);
|
|
64
|
-
}))();
|
|
65
|
-
}
|
|
66
|
-
}, {
|
|
67
|
-
key: "decompressBatches",
|
|
68
|
-
value: function decompressBatches(asyncIterator) {
|
|
69
|
-
return (0, _wrapAsyncGenerator2.default)(_regenerator.default.mark(function _callee2() {
|
|
70
|
-
return _regenerator.default.wrap(function _callee2$(_context2) {
|
|
71
|
-
while (1) switch (_context2.prev = _context2.next) {
|
|
72
|
-
case 0:
|
|
73
|
-
return _context2.delegateYield((0, _asyncGeneratorDelegate2.default)(_asyncIterator(asyncIterator), _awaitAsyncGenerator2.default), "t0", 1);
|
|
74
|
-
case 1:
|
|
75
|
-
return _context2.abrupt("return", _context2.t0);
|
|
76
|
-
case 2:
|
|
77
|
-
case "end":
|
|
78
|
-
return _context2.stop();
|
|
79
|
-
}
|
|
80
|
-
}, _callee2);
|
|
81
|
-
}))();
|
|
82
|
-
}
|
|
83
|
-
}]);
|
|
84
|
-
return NoCompression;
|
|
85
|
-
}(_compression.Compression);
|
|
20
|
+
compressSync(input) {
|
|
21
|
+
return input;
|
|
22
|
+
}
|
|
23
|
+
decompressSync(input) {
|
|
24
|
+
return input;
|
|
25
|
+
}
|
|
26
|
+
async *compressBatches(asyncIterator) {
|
|
27
|
+
return yield* asyncIterator;
|
|
28
|
+
}
|
|
29
|
+
async *decompressBatches(asyncIterator) {
|
|
30
|
+
return yield* asyncIterator;
|
|
31
|
+
}
|
|
32
|
+
}
|
|
86
33
|
exports.NoCompression = NoCompression;
|
|
87
34
|
//# sourceMappingURL=no-compression.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"no-compression.js","names":["_compression","require","
|
|
1
|
+
{"version":3,"file":"no-compression.js","names":["_compression","require","NoCompression","Compression","constructor","options","_defineProperty2","default","compressSync","input","decompressSync","compressBatches","asyncIterator","decompressBatches","exports"],"sources":["../../../src/lib/no-compression.ts"],"sourcesContent":["// NO COMPRESSION\nimport type {CompressionOptions} from './compression';\nimport {Compression} from './compression';\n\n/**\n * Applies no compression.\n */\nexport class NoCompression extends Compression {\n readonly name: string = 'uncompressed';\n readonly extensions: string[] = [];\n readonly contentEncodings: string[] = [];\n readonly isSupported = true;\n\n readonly options: CompressionOptions;\n\n constructor(options?: CompressionOptions) {\n super(options);\n this.options = options || {};\n }\n\n compressSync(input: ArrayBuffer): ArrayBuffer {\n return input;\n }\n\n decompressSync(input: ArrayBuffer): ArrayBuffer {\n return input;\n }\n\n async *compressBatches(\n asyncIterator: AsyncIterable<ArrayBuffer> | Iterable<ArrayBuffer>\n ): AsyncIterable<ArrayBuffer> {\n return yield* asyncIterator;\n }\n\n async *decompressBatches(\n asyncIterator: AsyncIterable<ArrayBuffer> | Iterable<ArrayBuffer>\n ): AsyncIterable<ArrayBuffer> {\n return yield* asyncIterator;\n }\n}\n"],"mappings":";;;;;;;;AAEA,IAAAA,YAAA,GAAAC,OAAA;AAKO,MAAMC,aAAa,SAASC,wBAAW,CAAC;EAQ7CC,WAAWA,CAACC,OAA4B,EAAE;IACxC,KAAK,CAACA,OAAO,CAAC;IAAC,IAAAC,gBAAA,CAAAC,OAAA,gBARO,cAAc;IAAA,IAAAD,gBAAA,CAAAC,OAAA,sBACN,EAAE;IAAA,IAAAD,gBAAA,CAAAC,OAAA,4BACI,EAAE;IAAA,IAAAD,gBAAA,CAAAC,OAAA,uBACjB,IAAI;IAAA,IAAAD,gBAAA,CAAAC,OAAA;IAMzB,IAAI,CAACF,OAAO,GAAGA,OAAO,IAAI,CAAC,CAAC;EAC9B;EAEAG,YAAYA,CAACC,KAAkB,EAAe;IAC5C,OAAOA,KAAK;EACd;EAEAC,cAAcA,CAACD,KAAkB,EAAe;IAC9C,OAAOA,KAAK;EACd;EAEA,OAAOE,eAAeA,CACpBC,aAAiE,EACrC;IAC5B,OAAO,OAAOA,aAAa;EAC7B;EAEA,OAAOC,iBAAiBA,CACtBD,aAAiE,EACrC;IAC5B,OAAO,OAAOA,aAAa;EAC7B;AACF;AAACE,OAAA,CAAAZ,aAAA,GAAAA,aAAA"}
|
|
@@ -5,44 +5,25 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
value: true
|
|
6
6
|
});
|
|
7
7
|
exports.SnappyCompression = void 0;
|
|
8
|
-
var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));
|
|
9
|
-
var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
|
|
10
|
-
var _assertThisInitialized2 = _interopRequireDefault(require("@babel/runtime/helpers/assertThisInitialized"));
|
|
11
|
-
var _inherits2 = _interopRequireDefault(require("@babel/runtime/helpers/inherits"));
|
|
12
|
-
var _possibleConstructorReturn2 = _interopRequireDefault(require("@babel/runtime/helpers/possibleConstructorReturn"));
|
|
13
|
-
var _getPrototypeOf2 = _interopRequireDefault(require("@babel/runtime/helpers/getPrototypeOf"));
|
|
14
8
|
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
15
9
|
var _compression = require("./compression");
|
|
16
10
|
var _snappyjs = require("snappyjs");
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
(0,
|
|
25
|
-
|
|
26
|
-
(0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "name", 'snappy');
|
|
27
|
-
(0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "extensions", []);
|
|
28
|
-
(0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "contentEncodings", []);
|
|
29
|
-
(0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "isSupported", true);
|
|
30
|
-
(0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "options", void 0);
|
|
31
|
-
_this.options = options || {};
|
|
32
|
-
return _this;
|
|
11
|
+
class SnappyCompression extends _compression.Compression {
|
|
12
|
+
constructor(options) {
|
|
13
|
+
super(options);
|
|
14
|
+
(0, _defineProperty2.default)(this, "name", 'snappy');
|
|
15
|
+
(0, _defineProperty2.default)(this, "extensions", []);
|
|
16
|
+
(0, _defineProperty2.default)(this, "contentEncodings", []);
|
|
17
|
+
(0, _defineProperty2.default)(this, "isSupported", true);
|
|
18
|
+
(0, _defineProperty2.default)(this, "options", void 0);
|
|
19
|
+
this.options = options || {};
|
|
33
20
|
}
|
|
34
|
-
(
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
value: function decompressSync(input) {
|
|
42
|
-
return (0, _snappyjs.uncompress)(input);
|
|
43
|
-
}
|
|
44
|
-
}]);
|
|
45
|
-
return SnappyCompression;
|
|
46
|
-
}(_compression.Compression);
|
|
21
|
+
compressSync(input) {
|
|
22
|
+
return (0, _snappyjs.compress)(input);
|
|
23
|
+
}
|
|
24
|
+
decompressSync(input) {
|
|
25
|
+
return (0, _snappyjs.uncompress)(input);
|
|
26
|
+
}
|
|
27
|
+
}
|
|
47
28
|
exports.SnappyCompression = SnappyCompression;
|
|
48
29
|
//# sourceMappingURL=snappy-compression.js.map
|