@novnc/novnc 1.0.0 → 1.2.0

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 (87) hide show
  1. package/AUTHORS +13 -0
  2. package/LICENSE.txt +2 -1
  3. package/README.md +69 -3
  4. package/core/base64.js +35 -41
  5. package/core/decoders/copyrect.js +22 -0
  6. package/core/decoders/hextile.js +137 -0
  7. package/core/decoders/raw.js +56 -0
  8. package/core/decoders/rre.js +44 -0
  9. package/core/decoders/tight.js +315 -0
  10. package/core/decoders/tightpng.js +27 -0
  11. package/core/deflator.js +85 -0
  12. package/core/des.js +90 -95
  13. package/core/display.js +254 -297
  14. package/core/encodings.js +7 -3
  15. package/core/inflator.js +48 -20
  16. package/core/input/domkeytable.js +21 -24
  17. package/core/input/fixedkeys.js +3 -1
  18. package/core/input/gesturehandler.js +567 -0
  19. package/core/input/keyboard.js +194 -120
  20. package/core/input/keysym.js +2 -0
  21. package/core/input/keysymdef.js +3 -3
  22. package/core/input/util.js +53 -12
  23. package/core/input/vkeys.js +2 -1
  24. package/core/rfb.js +1937 -1496
  25. package/core/util/browser.js +80 -29
  26. package/core/util/cursor.js +253 -0
  27. package/core/util/element.js +32 -0
  28. package/core/util/events.js +59 -55
  29. package/core/util/eventtarget.js +25 -30
  30. package/core/util/int.js +15 -0
  31. package/core/util/logging.js +21 -16
  32. package/core/util/polyfill.js +15 -8
  33. package/core/util/strings.js +21 -8
  34. package/core/websock.js +145 -167
  35. package/docs/API.md +31 -10
  36. package/lib/base64.js +115 -0
  37. package/lib/decoders/copyrect.js +44 -0
  38. package/lib/decoders/hextile.js +173 -0
  39. package/lib/decoders/raw.js +78 -0
  40. package/lib/decoders/rre.js +65 -0
  41. package/lib/decoders/tight.js +350 -0
  42. package/lib/decoders/tightpng.js +67 -0
  43. package/lib/deflator.js +99 -0
  44. package/lib/des.js +314 -0
  45. package/lib/display.js +733 -0
  46. package/lib/encodings.js +64 -0
  47. package/lib/inflator.js +87 -0
  48. package/lib/input/domkeytable.js +282 -0
  49. package/lib/input/fixedkeys.js +123 -0
  50. package/lib/input/gesturehandler.js +642 -0
  51. package/lib/input/keyboard.js +429 -0
  52. package/lib/input/keysym.js +1135 -0
  53. package/lib/input/keysymdef.js +1354 -0
  54. package/lib/input/util.js +304 -0
  55. package/lib/input/vkeys.js +127 -0
  56. package/lib/input/xtscancodes.js +505 -0
  57. package/lib/rfb.js +3448 -0
  58. package/lib/util/browser.js +131 -0
  59. package/lib/util/cursor.js +314 -0
  60. package/lib/util/element.js +43 -0
  61. package/lib/util/events.js +142 -0
  62. package/lib/util/eventtarget.js +64 -0
  63. package/lib/util/int.js +22 -0
  64. package/lib/util/logging.js +79 -0
  65. package/lib/util/polyfill.js +72 -0
  66. package/lib/util/strings.js +38 -0
  67. package/lib/vendor/pako/lib/utils/common.js +67 -0
  68. package/lib/vendor/pako/lib/zlib/adler32.js +33 -0
  69. package/lib/vendor/pako/lib/zlib/constants.js +51 -0
  70. package/lib/vendor/pako/lib/zlib/crc32.js +42 -0
  71. package/lib/vendor/pako/lib/zlib/deflate.js +2159 -0
  72. package/lib/vendor/pako/lib/zlib/gzheader.js +53 -0
  73. package/lib/vendor/pako/lib/zlib/inffast.js +445 -0
  74. package/lib/vendor/pako/lib/zlib/inflate.js +2114 -0
  75. package/lib/vendor/pako/lib/zlib/inftrees.js +418 -0
  76. package/lib/vendor/pako/lib/zlib/messages.js +36 -0
  77. package/lib/vendor/pako/lib/zlib/trees.js +1499 -0
  78. package/lib/vendor/pako/lib/zlib/zstream.js +46 -0
  79. package/lib/vendor/promise.js +255 -0
  80. package/lib/websock.js +374 -0
  81. package/package.json +48 -28
  82. package/vendor/pako/lib/zlib/deflate.js +30 -30
  83. package/vendor/pako/lib/zlib/inflate.js +17 -17
  84. package/core/input/mouse.js +0 -280
  85. package/docs/API-internal.md +0 -125
  86. package/docs/EMBEDDING.md +0 -83
  87. package/docs/VERSION +0 -1
@@ -0,0 +1,350 @@
1
+ "use strict";
2
+
3
+ function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
4
+
5
+ Object.defineProperty(exports, "__esModule", {
6
+ value: true
7
+ });
8
+ exports.default = void 0;
9
+
10
+ var Log = _interopRequireWildcard(require("../util/logging.js"));
11
+
12
+ var _inflator = _interopRequireDefault(require("../inflator.js"));
13
+
14
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
15
+
16
+ function _getRequireWildcardCache() { if (typeof WeakMap !== "function") return null; var cache = new WeakMap(); _getRequireWildcardCache = function _getRequireWildcardCache() { return cache; }; return cache; }
17
+
18
+ function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
19
+
20
+ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
21
+
22
+ function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
23
+
24
+ function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
25
+
26
+ var TightDecoder = /*#__PURE__*/function () {
27
+ function TightDecoder() {
28
+ _classCallCheck(this, TightDecoder);
29
+
30
+ this._ctl = null;
31
+ this._filter = null;
32
+ this._numColors = 0;
33
+ this._palette = new Uint8Array(1024); // 256 * 4 (max palette size * max bytes-per-pixel)
34
+
35
+ this._len = 0;
36
+ this._zlibs = [];
37
+
38
+ for (var i = 0; i < 4; i++) {
39
+ this._zlibs[i] = new _inflator.default();
40
+ }
41
+ }
42
+
43
+ _createClass(TightDecoder, [{
44
+ key: "decodeRect",
45
+ value: function decodeRect(x, y, width, height, sock, display, depth) {
46
+ if (this._ctl === null) {
47
+ if (sock.rQwait("TIGHT compression-control", 1)) {
48
+ return false;
49
+ }
50
+
51
+ this._ctl = sock.rQshift8(); // Reset streams if the server requests it
52
+
53
+ for (var i = 0; i < 4; i++) {
54
+ if (this._ctl >> i & 1) {
55
+ this._zlibs[i].reset();
56
+
57
+ Log.Info("Reset zlib stream " + i);
58
+ }
59
+ } // Figure out filter
60
+
61
+
62
+ this._ctl = this._ctl >> 4;
63
+ }
64
+
65
+ var ret;
66
+
67
+ if (this._ctl === 0x08) {
68
+ ret = this._fillRect(x, y, width, height, sock, display, depth);
69
+ } else if (this._ctl === 0x09) {
70
+ ret = this._jpegRect(x, y, width, height, sock, display, depth);
71
+ } else if (this._ctl === 0x0A) {
72
+ ret = this._pngRect(x, y, width, height, sock, display, depth);
73
+ } else if ((this._ctl & 0x80) == 0) {
74
+ ret = this._basicRect(this._ctl, x, y, width, height, sock, display, depth);
75
+ } else {
76
+ throw new Error("Illegal tight compression received (ctl: " + this._ctl + ")");
77
+ }
78
+
79
+ if (ret) {
80
+ this._ctl = null;
81
+ }
82
+
83
+ return ret;
84
+ }
85
+ }, {
86
+ key: "_fillRect",
87
+ value: function _fillRect(x, y, width, height, sock, display, depth) {
88
+ if (sock.rQwait("TIGHT", 3)) {
89
+ return false;
90
+ }
91
+
92
+ var rQi = sock.rQi;
93
+ var rQ = sock.rQ;
94
+ display.fillRect(x, y, width, height, [rQ[rQi + 2], rQ[rQi + 1], rQ[rQi]], false);
95
+ sock.rQskipBytes(3);
96
+ return true;
97
+ }
98
+ }, {
99
+ key: "_jpegRect",
100
+ value: function _jpegRect(x, y, width, height, sock, display, depth) {
101
+ var data = this._readData(sock);
102
+
103
+ if (data === null) {
104
+ return false;
105
+ }
106
+
107
+ display.imageRect(x, y, width, height, "image/jpeg", data);
108
+ return true;
109
+ }
110
+ }, {
111
+ key: "_pngRect",
112
+ value: function _pngRect(x, y, width, height, sock, display, depth) {
113
+ throw new Error("PNG received in standard Tight rect");
114
+ }
115
+ }, {
116
+ key: "_basicRect",
117
+ value: function _basicRect(ctl, x, y, width, height, sock, display, depth) {
118
+ if (this._filter === null) {
119
+ if (ctl & 0x4) {
120
+ if (sock.rQwait("TIGHT", 1)) {
121
+ return false;
122
+ }
123
+
124
+ this._filter = sock.rQshift8();
125
+ } else {
126
+ // Implicit CopyFilter
127
+ this._filter = 0;
128
+ }
129
+ }
130
+
131
+ var streamId = ctl & 0x3;
132
+ var ret;
133
+
134
+ switch (this._filter) {
135
+ case 0:
136
+ // CopyFilter
137
+ ret = this._copyFilter(streamId, x, y, width, height, sock, display, depth);
138
+ break;
139
+
140
+ case 1:
141
+ // PaletteFilter
142
+ ret = this._paletteFilter(streamId, x, y, width, height, sock, display, depth);
143
+ break;
144
+
145
+ case 2:
146
+ // GradientFilter
147
+ ret = this._gradientFilter(streamId, x, y, width, height, sock, display, depth);
148
+ break;
149
+
150
+ default:
151
+ throw new Error("Illegal tight filter received (ctl: " + this._filter + ")");
152
+ }
153
+
154
+ if (ret) {
155
+ this._filter = null;
156
+ }
157
+
158
+ return ret;
159
+ }
160
+ }, {
161
+ key: "_copyFilter",
162
+ value: function _copyFilter(streamId, x, y, width, height, sock, display, depth) {
163
+ var uncompressedSize = width * height * 3;
164
+ var data;
165
+
166
+ if (uncompressedSize < 12) {
167
+ if (sock.rQwait("TIGHT", uncompressedSize)) {
168
+ return false;
169
+ }
170
+
171
+ data = sock.rQshiftBytes(uncompressedSize);
172
+ } else {
173
+ data = this._readData(sock);
174
+
175
+ if (data === null) {
176
+ return false;
177
+ }
178
+
179
+ this._zlibs[streamId].setInput(data);
180
+
181
+ data = this._zlibs[streamId].inflate(uncompressedSize);
182
+
183
+ this._zlibs[streamId].setInput(null);
184
+ }
185
+
186
+ display.blitRgbImage(x, y, width, height, data, 0, false);
187
+ return true;
188
+ }
189
+ }, {
190
+ key: "_paletteFilter",
191
+ value: function _paletteFilter(streamId, x, y, width, height, sock, display, depth) {
192
+ if (this._numColors === 0) {
193
+ if (sock.rQwait("TIGHT palette", 1)) {
194
+ return false;
195
+ }
196
+
197
+ var numColors = sock.rQpeek8() + 1;
198
+ var paletteSize = numColors * 3;
199
+
200
+ if (sock.rQwait("TIGHT palette", 1 + paletteSize)) {
201
+ return false;
202
+ }
203
+
204
+ this._numColors = numColors;
205
+ sock.rQskipBytes(1);
206
+ sock.rQshiftTo(this._palette, paletteSize);
207
+ }
208
+
209
+ var bpp = this._numColors <= 2 ? 1 : 8;
210
+ var rowSize = Math.floor((width * bpp + 7) / 8);
211
+ var uncompressedSize = rowSize * height;
212
+ var data;
213
+
214
+ if (uncompressedSize < 12) {
215
+ if (sock.rQwait("TIGHT", uncompressedSize)) {
216
+ return false;
217
+ }
218
+
219
+ data = sock.rQshiftBytes(uncompressedSize);
220
+ } else {
221
+ data = this._readData(sock);
222
+
223
+ if (data === null) {
224
+ return false;
225
+ }
226
+
227
+ this._zlibs[streamId].setInput(data);
228
+
229
+ data = this._zlibs[streamId].inflate(uncompressedSize);
230
+
231
+ this._zlibs[streamId].setInput(null);
232
+ } // Convert indexed (palette based) image data to RGB
233
+
234
+
235
+ if (this._numColors == 2) {
236
+ this._monoRect(x, y, width, height, data, this._palette, display);
237
+ } else {
238
+ this._paletteRect(x, y, width, height, data, this._palette, display);
239
+ }
240
+
241
+ this._numColors = 0;
242
+ return true;
243
+ }
244
+ }, {
245
+ key: "_monoRect",
246
+ value: function _monoRect(x, y, width, height, data, palette, display) {
247
+ // Convert indexed (palette based) image data to RGB
248
+ // TODO: reduce number of calculations inside loop
249
+ var dest = this._getScratchBuffer(width * height * 4);
250
+
251
+ var w = Math.floor((width + 7) / 8);
252
+ var w1 = Math.floor(width / 8);
253
+
254
+ for (var _y = 0; _y < height; _y++) {
255
+ var dp = void 0,
256
+ sp = void 0,
257
+ _x = void 0;
258
+
259
+ for (_x = 0; _x < w1; _x++) {
260
+ for (var b = 7; b >= 0; b--) {
261
+ dp = (_y * width + _x * 8 + 7 - b) * 4;
262
+ sp = (data[_y * w + _x] >> b & 1) * 3;
263
+ dest[dp] = palette[sp];
264
+ dest[dp + 1] = palette[sp + 1];
265
+ dest[dp + 2] = palette[sp + 2];
266
+ dest[dp + 3] = 255;
267
+ }
268
+ }
269
+
270
+ for (var _b = 7; _b >= 8 - width % 8; _b--) {
271
+ dp = (_y * width + _x * 8 + 7 - _b) * 4;
272
+ sp = (data[_y * w + _x] >> _b & 1) * 3;
273
+ dest[dp] = palette[sp];
274
+ dest[dp + 1] = palette[sp + 1];
275
+ dest[dp + 2] = palette[sp + 2];
276
+ dest[dp + 3] = 255;
277
+ }
278
+ }
279
+
280
+ display.blitRgbxImage(x, y, width, height, dest, 0, false);
281
+ }
282
+ }, {
283
+ key: "_paletteRect",
284
+ value: function _paletteRect(x, y, width, height, data, palette, display) {
285
+ // Convert indexed (palette based) image data to RGB
286
+ var dest = this._getScratchBuffer(width * height * 4);
287
+
288
+ var total = width * height * 4;
289
+
290
+ for (var i = 0, j = 0; i < total; i += 4, j++) {
291
+ var sp = data[j] * 3;
292
+ dest[i] = palette[sp];
293
+ dest[i + 1] = palette[sp + 1];
294
+ dest[i + 2] = palette[sp + 2];
295
+ dest[i + 3] = 255;
296
+ }
297
+
298
+ display.blitRgbxImage(x, y, width, height, dest, 0, false);
299
+ }
300
+ }, {
301
+ key: "_gradientFilter",
302
+ value: function _gradientFilter(streamId, x, y, width, height, sock, display, depth) {
303
+ throw new Error("Gradient filter not implemented");
304
+ }
305
+ }, {
306
+ key: "_readData",
307
+ value: function _readData(sock) {
308
+ if (this._len === 0) {
309
+ if (sock.rQwait("TIGHT", 3)) {
310
+ return null;
311
+ }
312
+
313
+ var byte;
314
+ byte = sock.rQshift8();
315
+ this._len = byte & 0x7f;
316
+
317
+ if (byte & 0x80) {
318
+ byte = sock.rQshift8();
319
+ this._len |= (byte & 0x7f) << 7;
320
+
321
+ if (byte & 0x80) {
322
+ byte = sock.rQshift8();
323
+ this._len |= byte << 14;
324
+ }
325
+ }
326
+ }
327
+
328
+ if (sock.rQwait("TIGHT", this._len)) {
329
+ return null;
330
+ }
331
+
332
+ var data = sock.rQshiftBytes(this._len);
333
+ this._len = 0;
334
+ return data;
335
+ }
336
+ }, {
337
+ key: "_getScratchBuffer",
338
+ value: function _getScratchBuffer(size) {
339
+ if (!this._scratchBuffer || this._scratchBuffer.length < size) {
340
+ this._scratchBuffer = new Uint8Array(size);
341
+ }
342
+
343
+ return this._scratchBuffer;
344
+ }
345
+ }]);
346
+
347
+ return TightDecoder;
348
+ }();
349
+
350
+ exports.default = TightDecoder;
@@ -0,0 +1,67 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = void 0;
7
+
8
+ var _tight = _interopRequireDefault(require("./tight.js"));
9
+
10
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
11
+
12
+ function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
13
+
14
+ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
15
+
16
+ function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
17
+
18
+ function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
19
+
20
+ function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); if (superClass) _setPrototypeOf(subClass, superClass); }
21
+
22
+ function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
23
+
24
+ function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
25
+
26
+ function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); }
27
+
28
+ function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
29
+
30
+ function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Date.prototype.toString.call(Reflect.construct(Date, [], function () {})); return true; } catch (e) { return false; } }
31
+
32
+ function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
33
+
34
+ var TightPNGDecoder = /*#__PURE__*/function (_TightDecoder) {
35
+ _inherits(TightPNGDecoder, _TightDecoder);
36
+
37
+ var _super = _createSuper(TightPNGDecoder);
38
+
39
+ function TightPNGDecoder() {
40
+ _classCallCheck(this, TightPNGDecoder);
41
+
42
+ return _super.apply(this, arguments);
43
+ }
44
+
45
+ _createClass(TightPNGDecoder, [{
46
+ key: "_pngRect",
47
+ value: function _pngRect(x, y, width, height, sock, display, depth) {
48
+ var data = this._readData(sock);
49
+
50
+ if (data === null) {
51
+ return false;
52
+ }
53
+
54
+ display.imageRect(x, y, width, height, "image/png", data);
55
+ return true;
56
+ }
57
+ }, {
58
+ key: "_basicRect",
59
+ value: function _basicRect(ctl, x, y, width, height, sock, display, depth) {
60
+ throw new Error("BasicCompression received in TightPNG rect");
61
+ }
62
+ }]);
63
+
64
+ return TightPNGDecoder;
65
+ }(_tight.default);
66
+
67
+ exports.default = TightPNGDecoder;
@@ -0,0 +1,99 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = void 0;
7
+
8
+ var _deflate2 = require("../lib/vendor/pako/lib/zlib/deflate.js");
9
+
10
+ var _zstream = _interopRequireDefault(require("../lib/vendor/pako/lib/zlib/zstream.js"));
11
+
12
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
13
+
14
+ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
15
+
16
+ function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
17
+
18
+ function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
19
+
20
+ var Deflator = /*#__PURE__*/function () {
21
+ function Deflator() {
22
+ _classCallCheck(this, Deflator);
23
+
24
+ this.strm = new _zstream.default();
25
+ this.chunkSize = 1024 * 10 * 10;
26
+ this.outputBuffer = new Uint8Array(this.chunkSize);
27
+ this.windowBits = 5;
28
+ (0, _deflate2.deflateInit)(this.strm, this.windowBits);
29
+ }
30
+
31
+ _createClass(Deflator, [{
32
+ key: "deflate",
33
+ value: function deflate(inData) {
34
+ /* eslint-disable camelcase */
35
+ this.strm.input = inData;
36
+ this.strm.avail_in = this.strm.input.length;
37
+ this.strm.next_in = 0;
38
+ this.strm.output = this.outputBuffer;
39
+ this.strm.avail_out = this.chunkSize;
40
+ this.strm.next_out = 0;
41
+ /* eslint-enable camelcase */
42
+
43
+ var lastRet = (0, _deflate2.deflate)(this.strm, _deflate2.Z_FULL_FLUSH);
44
+ var outData = new Uint8Array(this.strm.output.buffer, 0, this.strm.next_out);
45
+
46
+ if (lastRet < 0) {
47
+ throw new Error("zlib deflate failed");
48
+ }
49
+
50
+ if (this.strm.avail_in > 0) {
51
+ // Read chunks until done
52
+ var chunks = [outData];
53
+ var totalLen = outData.length;
54
+
55
+ do {
56
+ /* eslint-disable camelcase */
57
+ this.strm.output = new Uint8Array(this.chunkSize);
58
+ this.strm.next_out = 0;
59
+ this.strm.avail_out = this.chunkSize;
60
+ /* eslint-enable camelcase */
61
+
62
+ lastRet = (0, _deflate2.deflate)(this.strm, _deflate2.Z_FULL_FLUSH);
63
+
64
+ if (lastRet < 0) {
65
+ throw new Error("zlib deflate failed");
66
+ }
67
+
68
+ var chunk = new Uint8Array(this.strm.output.buffer, 0, this.strm.next_out);
69
+ totalLen += chunk.length;
70
+ chunks.push(chunk);
71
+ } while (this.strm.avail_in > 0); // Combine chunks into a single data
72
+
73
+
74
+ var newData = new Uint8Array(totalLen);
75
+ var offset = 0;
76
+
77
+ for (var i = 0; i < chunks.length; i++) {
78
+ newData.set(chunks[i], offset);
79
+ offset += chunks[i].length;
80
+ }
81
+
82
+ outData = newData;
83
+ }
84
+ /* eslint-disable camelcase */
85
+
86
+
87
+ this.strm.input = null;
88
+ this.strm.avail_in = 0;
89
+ this.strm.next_in = 0;
90
+ /* eslint-enable camelcase */
91
+
92
+ return outData;
93
+ }
94
+ }]);
95
+
96
+ return Deflator;
97
+ }();
98
+
99
+ exports.default = Deflator;