llonebot-dist 6.6.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (134) hide show
  1. dist/default_config.json +68 -0
  2. dist/llonebot.js +48348 -0
  3. dist/llonebot.js.map +1 -0
  4. dist/node_modules/@borewit/text-codec/LICENSE.txt +9 -0
  5. dist/node_modules/@borewit/text-codec/README.md +76 -0
  6. dist/node_modules/@borewit/text-codec/lib/index.d.ts +8 -0
  7. dist/node_modules/@borewit/text-codec/lib/index.js +161 -0
  8. dist/node_modules/@borewit/text-codec/package.json +68 -0
  9. dist/node_modules/@minatojs/sql.js/LICENSE +44 -0
  10. dist/node_modules/@minatojs/sql.js/README.md +357 -0
  11. dist/node_modules/@minatojs/sql.js/dist/sql-wasm.d.ts +316 -0
  12. dist/node_modules/@minatojs/sql.js/dist/sql-wasm.js +225 -0
  13. dist/node_modules/@minatojs/sql.js/dist/sql-wasm.wasm +0 -0
  14. dist/node_modules/@minatojs/sql.js/package.json +58 -0
  15. dist/node_modules/@tokenizer/inflate/LICENSE +15 -0
  16. dist/node_modules/@tokenizer/inflate/README.md +114 -0
  17. dist/node_modules/@tokenizer/inflate/lib/GzipHandler.d.ts +6 -0
  18. dist/node_modules/@tokenizer/inflate/lib/GzipHandler.js +19 -0
  19. dist/node_modules/@tokenizer/inflate/lib/ZipHandler.d.ts +26 -0
  20. dist/node_modules/@tokenizer/inflate/lib/ZipHandler.js +233 -0
  21. dist/node_modules/@tokenizer/inflate/lib/ZipToken.d.ts +94 -0
  22. dist/node_modules/@tokenizer/inflate/lib/ZipToken.js +117 -0
  23. dist/node_modules/@tokenizer/inflate/lib/index.d.ts +3 -0
  24. dist/node_modules/@tokenizer/inflate/lib/index.js +2 -0
  25. dist/node_modules/@tokenizer/inflate/package.json +76 -0
  26. dist/node_modules/@tokenizer/token/README.md +19 -0
  27. dist/node_modules/@tokenizer/token/index.d.ts +30 -0
  28. dist/node_modules/@tokenizer/token/package.json +33 -0
  29. dist/node_modules/debug/LICENSE +20 -0
  30. dist/node_modules/debug/README.md +481 -0
  31. dist/node_modules/debug/package.json +64 -0
  32. dist/node_modules/debug/src/browser.js +272 -0
  33. dist/node_modules/debug/src/common.js +292 -0
  34. dist/node_modules/debug/src/index.js +10 -0
  35. dist/node_modules/debug/src/node.js +263 -0
  36. dist/node_modules/file-type/core.d.ts +253 -0
  37. dist/node_modules/file-type/core.js +1899 -0
  38. dist/node_modules/file-type/index.d.ts +98 -0
  39. dist/node_modules/file-type/index.js +86 -0
  40. dist/node_modules/file-type/license +9 -0
  41. dist/node_modules/file-type/package.json +288 -0
  42. dist/node_modules/file-type/readme.md +674 -0
  43. dist/node_modules/file-type/supported.js +356 -0
  44. dist/node_modules/file-type/util.js +60 -0
  45. dist/node_modules/ieee754/LICENSE +11 -0
  46. dist/node_modules/ieee754/README.md +51 -0
  47. dist/node_modules/ieee754/index.d.ts +10 -0
  48. dist/node_modules/ieee754/index.js +85 -0
  49. dist/node_modules/ieee754/package.json +52 -0
  50. dist/node_modules/ms/index.js +162 -0
  51. dist/node_modules/ms/license.md +21 -0
  52. dist/node_modules/ms/package.json +38 -0
  53. dist/node_modules/ms/readme.md +59 -0
  54. dist/node_modules/silk-wasm/LICENSE +21 -0
  55. dist/node_modules/silk-wasm/README.md +85 -0
  56. dist/node_modules/silk-wasm/lib/index.cjs +16 -0
  57. dist/node_modules/silk-wasm/lib/index.d.ts +70 -0
  58. dist/node_modules/silk-wasm/lib/index.mjs +16 -0
  59. dist/node_modules/silk-wasm/lib/silk.wasm +0 -0
  60. dist/node_modules/silk-wasm/lib/utils.d.ts +4 -0
  61. dist/node_modules/silk-wasm/package.json +39 -0
  62. dist/node_modules/strtok3/LICENSE.txt +21 -0
  63. dist/node_modules/strtok3/README.md +399 -0
  64. dist/node_modules/strtok3/lib/AbstractTokenizer.d.ts +76 -0
  65. dist/node_modules/strtok3/lib/AbstractTokenizer.js +108 -0
  66. dist/node_modules/strtok3/lib/BlobTokenizer.d.ts +29 -0
  67. dist/node_modules/strtok3/lib/BlobTokenizer.js +53 -0
  68. dist/node_modules/strtok3/lib/BufferTokenizer.d.ts +29 -0
  69. dist/node_modules/strtok3/lib/BufferTokenizer.js +52 -0
  70. dist/node_modules/strtok3/lib/FileTokenizer.d.ts +37 -0
  71. dist/node_modules/strtok3/lib/FileTokenizer.js +61 -0
  72. dist/node_modules/strtok3/lib/ReadStreamTokenizer.d.ts +31 -0
  73. dist/node_modules/strtok3/lib/ReadStreamTokenizer.js +102 -0
  74. dist/node_modules/strtok3/lib/core.d.ts +40 -0
  75. dist/node_modules/strtok3/lib/core.js +62 -0
  76. dist/node_modules/strtok3/lib/index.d.ts +16 -0
  77. dist/node_modules/strtok3/lib/index.js +22 -0
  78. dist/node_modules/strtok3/lib/stream/AbstractStreamReader.d.ts +54 -0
  79. dist/node_modules/strtok3/lib/stream/AbstractStreamReader.js +71 -0
  80. dist/node_modules/strtok3/lib/stream/Deferred.d.ts +6 -0
  81. dist/node_modules/strtok3/lib/stream/Deferred.js +10 -0
  82. dist/node_modules/strtok3/lib/stream/Errors.d.ts +10 -0
  83. dist/node_modules/strtok3/lib/stream/Errors.js +16 -0
  84. dist/node_modules/strtok3/lib/stream/StreamReader.d.ts +29 -0
  85. dist/node_modules/strtok3/lib/stream/StreamReader.js +83 -0
  86. dist/node_modules/strtok3/lib/stream/WebStreamByobReader.d.ts +14 -0
  87. dist/node_modules/strtok3/lib/stream/WebStreamByobReader.js +27 -0
  88. dist/node_modules/strtok3/lib/stream/WebStreamDefaultReader.d.ts +19 -0
  89. dist/node_modules/strtok3/lib/stream/WebStreamDefaultReader.js +62 -0
  90. dist/node_modules/strtok3/lib/stream/WebStreamReader.d.ts +14 -0
  91. dist/node_modules/strtok3/lib/stream/WebStreamReader.js +13 -0
  92. dist/node_modules/strtok3/lib/stream/WebStreamReaderFactory.d.ts +5 -0
  93. dist/node_modules/strtok3/lib/stream/WebStreamReaderFactory.js +19 -0
  94. dist/node_modules/strtok3/lib/stream/index.d.ts +6 -0
  95. dist/node_modules/strtok3/lib/stream/index.js +5 -0
  96. dist/node_modules/strtok3/lib/types.d.ts +139 -0
  97. dist/node_modules/strtok3/lib/types.js +1 -0
  98. dist/node_modules/strtok3/package.json +94 -0
  99. dist/node_modules/token-types/LICENSE.txt +9 -0
  100. dist/node_modules/token-types/README.md +120 -0
  101. dist/node_modules/token-types/lib/index.d.ts +135 -0
  102. dist/node_modules/token-types/lib/index.js +401 -0
  103. dist/node_modules/token-types/package.json +81 -0
  104. dist/node_modules/uint8array-extras/index.d.ts +312 -0
  105. dist/node_modules/uint8array-extras/index.js +321 -0
  106. dist/node_modules/uint8array-extras/license +9 -0
  107. dist/node_modules/uint8array-extras/package.json +54 -0
  108. dist/node_modules/uint8array-extras/readme.md +301 -0
  109. dist/node_modules/ws/LICENSE +20 -0
  110. dist/node_modules/ws/README.md +548 -0
  111. dist/node_modules/ws/browser.js +8 -0
  112. dist/node_modules/ws/index.js +13 -0
  113. dist/node_modules/ws/lib/buffer-util.js +131 -0
  114. dist/node_modules/ws/lib/constants.js +18 -0
  115. dist/node_modules/ws/lib/event-target.js +292 -0
  116. dist/node_modules/ws/lib/extension.js +203 -0
  117. dist/node_modules/ws/lib/limiter.js +55 -0
  118. dist/node_modules/ws/lib/permessage-deflate.js +528 -0
  119. dist/node_modules/ws/lib/receiver.js +706 -0
  120. dist/node_modules/ws/lib/sender.js +602 -0
  121. dist/node_modules/ws/lib/stream.js +161 -0
  122. dist/node_modules/ws/lib/subprotocol.js +62 -0
  123. dist/node_modules/ws/lib/validation.js +152 -0
  124. dist/node_modules/ws/lib/websocket-server.js +550 -0
  125. dist/node_modules/ws/lib/websocket.js +1388 -0
  126. dist/node_modules/ws/package.json +69 -0
  127. dist/node_modules/ws/wrapper.mjs +8 -0
  128. dist/package.json +1 -0
  129. dist/webui/assets/index-B9vGhdCO.js +256 -0
  130. dist/webui/assets/index-DaqFU7JR.css +1 -0
  131. dist/webui/index.html +13 -0
  132. dist/webui/logo.jpg +0 -0
  133. dist//344/275/277/347/224/250/350/257/264/346/230/216.txt +11 -0
  134. dist//346/233/264/346/226/260/346/227/245/345/277/227.txt +399 -0
@@ -0,0 +1,528 @@
1
+ 'use strict';
2
+
3
+ const zlib = require('zlib');
4
+
5
+ const bufferUtil = require('./buffer-util');
6
+ const Limiter = require('./limiter');
7
+ const { kStatusCode } = require('./constants');
8
+
9
+ const FastBuffer = Buffer[Symbol.species];
10
+ const TRAILER = Buffer.from([0x00, 0x00, 0xff, 0xff]);
11
+ const kPerMessageDeflate = Symbol('permessage-deflate');
12
+ const kTotalLength = Symbol('total-length');
13
+ const kCallback = Symbol('callback');
14
+ const kBuffers = Symbol('buffers');
15
+ const kError = Symbol('error');
16
+
17
+ //
18
+ // We limit zlib concurrency, which prevents severe memory fragmentation
19
+ // as documented in https://github.com/nodejs/node/issues/8871#issuecomment-250915913
20
+ // and https://github.com/websockets/ws/issues/1202
21
+ //
22
+ // Intentionally global; it's the global thread pool that's an issue.
23
+ //
24
+ let zlibLimiter;
25
+
26
+ /**
27
+ * permessage-deflate implementation.
28
+ */
29
+ class PerMessageDeflate {
30
+ /**
31
+ * Creates a PerMessageDeflate instance.
32
+ *
33
+ * @param {Object} [options] Configuration options
34
+ * @param {(Boolean|Number)} [options.clientMaxWindowBits] Advertise support
35
+ * for, or request, a custom client window size
36
+ * @param {Boolean} [options.clientNoContextTakeover=false] Advertise/
37
+ * acknowledge disabling of client context takeover
38
+ * @param {Number} [options.concurrencyLimit=10] The number of concurrent
39
+ * calls to zlib
40
+ * @param {(Boolean|Number)} [options.serverMaxWindowBits] Request/confirm the
41
+ * use of a custom server window size
42
+ * @param {Boolean} [options.serverNoContextTakeover=false] Request/accept
43
+ * disabling of server context takeover
44
+ * @param {Number} [options.threshold=1024] Size (in bytes) below which
45
+ * messages should not be compressed if context takeover is disabled
46
+ * @param {Object} [options.zlibDeflateOptions] Options to pass to zlib on
47
+ * deflate
48
+ * @param {Object} [options.zlibInflateOptions] Options to pass to zlib on
49
+ * inflate
50
+ * @param {Boolean} [isServer=false] Create the instance in either server or
51
+ * client mode
52
+ * @param {Number} [maxPayload=0] The maximum allowed message length
53
+ */
54
+ constructor(options, isServer, maxPayload) {
55
+ this._maxPayload = maxPayload | 0;
56
+ this._options = options || {};
57
+ this._threshold =
58
+ this._options.threshold !== undefined ? this._options.threshold : 1024;
59
+ this._isServer = !!isServer;
60
+ this._deflate = null;
61
+ this._inflate = null;
62
+
63
+ this.params = null;
64
+
65
+ if (!zlibLimiter) {
66
+ const concurrency =
67
+ this._options.concurrencyLimit !== undefined
68
+ ? this._options.concurrencyLimit
69
+ : 10;
70
+ zlibLimiter = new Limiter(concurrency);
71
+ }
72
+ }
73
+
74
+ /**
75
+ * @type {String}
76
+ */
77
+ static get extensionName() {
78
+ return 'permessage-deflate';
79
+ }
80
+
81
+ /**
82
+ * Create an extension negotiation offer.
83
+ *
84
+ * @return {Object} Extension parameters
85
+ * @public
86
+ */
87
+ offer() {
88
+ const params = {};
89
+
90
+ if (this._options.serverNoContextTakeover) {
91
+ params.server_no_context_takeover = true;
92
+ }
93
+ if (this._options.clientNoContextTakeover) {
94
+ params.client_no_context_takeover = true;
95
+ }
96
+ if (this._options.serverMaxWindowBits) {
97
+ params.server_max_window_bits = this._options.serverMaxWindowBits;
98
+ }
99
+ if (this._options.clientMaxWindowBits) {
100
+ params.client_max_window_bits = this._options.clientMaxWindowBits;
101
+ } else if (this._options.clientMaxWindowBits == null) {
102
+ params.client_max_window_bits = true;
103
+ }
104
+
105
+ return params;
106
+ }
107
+
108
+ /**
109
+ * Accept an extension negotiation offer/response.
110
+ *
111
+ * @param {Array} configurations The extension negotiation offers/reponse
112
+ * @return {Object} Accepted configuration
113
+ * @public
114
+ */
115
+ accept(configurations) {
116
+ configurations = this.normalizeParams(configurations);
117
+
118
+ this.params = this._isServer
119
+ ? this.acceptAsServer(configurations)
120
+ : this.acceptAsClient(configurations);
121
+
122
+ return this.params;
123
+ }
124
+
125
+ /**
126
+ * Releases all resources used by the extension.
127
+ *
128
+ * @public
129
+ */
130
+ cleanup() {
131
+ if (this._inflate) {
132
+ this._inflate.close();
133
+ this._inflate = null;
134
+ }
135
+
136
+ if (this._deflate) {
137
+ const callback = this._deflate[kCallback];
138
+
139
+ this._deflate.close();
140
+ this._deflate = null;
141
+
142
+ if (callback) {
143
+ callback(
144
+ new Error(
145
+ 'The deflate stream was closed while data was being processed'
146
+ )
147
+ );
148
+ }
149
+ }
150
+ }
151
+
152
+ /**
153
+ * Accept an extension negotiation offer.
154
+ *
155
+ * @param {Array} offers The extension negotiation offers
156
+ * @return {Object} Accepted configuration
157
+ * @private
158
+ */
159
+ acceptAsServer(offers) {
160
+ const opts = this._options;
161
+ const accepted = offers.find((params) => {
162
+ if (
163
+ (opts.serverNoContextTakeover === false &&
164
+ params.server_no_context_takeover) ||
165
+ (params.server_max_window_bits &&
166
+ (opts.serverMaxWindowBits === false ||
167
+ (typeof opts.serverMaxWindowBits === 'number' &&
168
+ opts.serverMaxWindowBits > params.server_max_window_bits))) ||
169
+ (typeof opts.clientMaxWindowBits === 'number' &&
170
+ !params.client_max_window_bits)
171
+ ) {
172
+ return false;
173
+ }
174
+
175
+ return true;
176
+ });
177
+
178
+ if (!accepted) {
179
+ throw new Error('None of the extension offers can be accepted');
180
+ }
181
+
182
+ if (opts.serverNoContextTakeover) {
183
+ accepted.server_no_context_takeover = true;
184
+ }
185
+ if (opts.clientNoContextTakeover) {
186
+ accepted.client_no_context_takeover = true;
187
+ }
188
+ if (typeof opts.serverMaxWindowBits === 'number') {
189
+ accepted.server_max_window_bits = opts.serverMaxWindowBits;
190
+ }
191
+ if (typeof opts.clientMaxWindowBits === 'number') {
192
+ accepted.client_max_window_bits = opts.clientMaxWindowBits;
193
+ } else if (
194
+ accepted.client_max_window_bits === true ||
195
+ opts.clientMaxWindowBits === false
196
+ ) {
197
+ delete accepted.client_max_window_bits;
198
+ }
199
+
200
+ return accepted;
201
+ }
202
+
203
+ /**
204
+ * Accept the extension negotiation response.
205
+ *
206
+ * @param {Array} response The extension negotiation response
207
+ * @return {Object} Accepted configuration
208
+ * @private
209
+ */
210
+ acceptAsClient(response) {
211
+ const params = response[0];
212
+
213
+ if (
214
+ this._options.clientNoContextTakeover === false &&
215
+ params.client_no_context_takeover
216
+ ) {
217
+ throw new Error('Unexpected parameter "client_no_context_takeover"');
218
+ }
219
+
220
+ if (!params.client_max_window_bits) {
221
+ if (typeof this._options.clientMaxWindowBits === 'number') {
222
+ params.client_max_window_bits = this._options.clientMaxWindowBits;
223
+ }
224
+ } else if (
225
+ this._options.clientMaxWindowBits === false ||
226
+ (typeof this._options.clientMaxWindowBits === 'number' &&
227
+ params.client_max_window_bits > this._options.clientMaxWindowBits)
228
+ ) {
229
+ throw new Error(
230
+ 'Unexpected or invalid parameter "client_max_window_bits"'
231
+ );
232
+ }
233
+
234
+ return params;
235
+ }
236
+
237
+ /**
238
+ * Normalize parameters.
239
+ *
240
+ * @param {Array} configurations The extension negotiation offers/reponse
241
+ * @return {Array} The offers/response with normalized parameters
242
+ * @private
243
+ */
244
+ normalizeParams(configurations) {
245
+ configurations.forEach((params) => {
246
+ Object.keys(params).forEach((key) => {
247
+ let value = params[key];
248
+
249
+ if (value.length > 1) {
250
+ throw new Error(`Parameter "${key}" must have only a single value`);
251
+ }
252
+
253
+ value = value[0];
254
+
255
+ if (key === 'client_max_window_bits') {
256
+ if (value !== true) {
257
+ const num = +value;
258
+ if (!Number.isInteger(num) || num < 8 || num > 15) {
259
+ throw new TypeError(
260
+ `Invalid value for parameter "${key}": ${value}`
261
+ );
262
+ }
263
+ value = num;
264
+ } else if (!this._isServer) {
265
+ throw new TypeError(
266
+ `Invalid value for parameter "${key}": ${value}`
267
+ );
268
+ }
269
+ } else if (key === 'server_max_window_bits') {
270
+ const num = +value;
271
+ if (!Number.isInteger(num) || num < 8 || num > 15) {
272
+ throw new TypeError(
273
+ `Invalid value for parameter "${key}": ${value}`
274
+ );
275
+ }
276
+ value = num;
277
+ } else if (
278
+ key === 'client_no_context_takeover' ||
279
+ key === 'server_no_context_takeover'
280
+ ) {
281
+ if (value !== true) {
282
+ throw new TypeError(
283
+ `Invalid value for parameter "${key}": ${value}`
284
+ );
285
+ }
286
+ } else {
287
+ throw new Error(`Unknown parameter "${key}"`);
288
+ }
289
+
290
+ params[key] = value;
291
+ });
292
+ });
293
+
294
+ return configurations;
295
+ }
296
+
297
+ /**
298
+ * Decompress data. Concurrency limited.
299
+ *
300
+ * @param {Buffer} data Compressed data
301
+ * @param {Boolean} fin Specifies whether or not this is the last fragment
302
+ * @param {Function} callback Callback
303
+ * @public
304
+ */
305
+ decompress(data, fin, callback) {
306
+ zlibLimiter.add((done) => {
307
+ this._decompress(data, fin, (err, result) => {
308
+ done();
309
+ callback(err, result);
310
+ });
311
+ });
312
+ }
313
+
314
+ /**
315
+ * Compress data. Concurrency limited.
316
+ *
317
+ * @param {(Buffer|String)} data Data to compress
318
+ * @param {Boolean} fin Specifies whether or not this is the last fragment
319
+ * @param {Function} callback Callback
320
+ * @public
321
+ */
322
+ compress(data, fin, callback) {
323
+ zlibLimiter.add((done) => {
324
+ this._compress(data, fin, (err, result) => {
325
+ done();
326
+ callback(err, result);
327
+ });
328
+ });
329
+ }
330
+
331
+ /**
332
+ * Decompress data.
333
+ *
334
+ * @param {Buffer} data Compressed data
335
+ * @param {Boolean} fin Specifies whether or not this is the last fragment
336
+ * @param {Function} callback Callback
337
+ * @private
338
+ */
339
+ _decompress(data, fin, callback) {
340
+ const endpoint = this._isServer ? 'client' : 'server';
341
+
342
+ if (!this._inflate) {
343
+ const key = `${endpoint}_max_window_bits`;
344
+ const windowBits =
345
+ typeof this.params[key] !== 'number'
346
+ ? zlib.Z_DEFAULT_WINDOWBITS
347
+ : this.params[key];
348
+
349
+ this._inflate = zlib.createInflateRaw({
350
+ ...this._options.zlibInflateOptions,
351
+ windowBits
352
+ });
353
+ this._inflate[kPerMessageDeflate] = this;
354
+ this._inflate[kTotalLength] = 0;
355
+ this._inflate[kBuffers] = [];
356
+ this._inflate.on('error', inflateOnError);
357
+ this._inflate.on('data', inflateOnData);
358
+ }
359
+
360
+ this._inflate[kCallback] = callback;
361
+
362
+ this._inflate.write(data);
363
+ if (fin) this._inflate.write(TRAILER);
364
+
365
+ this._inflate.flush(() => {
366
+ const err = this._inflate[kError];
367
+
368
+ if (err) {
369
+ this._inflate.close();
370
+ this._inflate = null;
371
+ callback(err);
372
+ return;
373
+ }
374
+
375
+ const data = bufferUtil.concat(
376
+ this._inflate[kBuffers],
377
+ this._inflate[kTotalLength]
378
+ );
379
+
380
+ if (this._inflate._readableState.endEmitted) {
381
+ this._inflate.close();
382
+ this._inflate = null;
383
+ } else {
384
+ this._inflate[kTotalLength] = 0;
385
+ this._inflate[kBuffers] = [];
386
+
387
+ if (fin && this.params[`${endpoint}_no_context_takeover`]) {
388
+ this._inflate.reset();
389
+ }
390
+ }
391
+
392
+ callback(null, data);
393
+ });
394
+ }
395
+
396
+ /**
397
+ * Compress data.
398
+ *
399
+ * @param {(Buffer|String)} data Data to compress
400
+ * @param {Boolean} fin Specifies whether or not this is the last fragment
401
+ * @param {Function} callback Callback
402
+ * @private
403
+ */
404
+ _compress(data, fin, callback) {
405
+ const endpoint = this._isServer ? 'server' : 'client';
406
+
407
+ if (!this._deflate) {
408
+ const key = `${endpoint}_max_window_bits`;
409
+ const windowBits =
410
+ typeof this.params[key] !== 'number'
411
+ ? zlib.Z_DEFAULT_WINDOWBITS
412
+ : this.params[key];
413
+
414
+ this._deflate = zlib.createDeflateRaw({
415
+ ...this._options.zlibDeflateOptions,
416
+ windowBits
417
+ });
418
+
419
+ this._deflate[kTotalLength] = 0;
420
+ this._deflate[kBuffers] = [];
421
+
422
+ this._deflate.on('data', deflateOnData);
423
+ }
424
+
425
+ this._deflate[kCallback] = callback;
426
+
427
+ this._deflate.write(data);
428
+ this._deflate.flush(zlib.Z_SYNC_FLUSH, () => {
429
+ if (!this._deflate) {
430
+ //
431
+ // The deflate stream was closed while data was being processed.
432
+ //
433
+ return;
434
+ }
435
+
436
+ let data = bufferUtil.concat(
437
+ this._deflate[kBuffers],
438
+ this._deflate[kTotalLength]
439
+ );
440
+
441
+ if (fin) {
442
+ data = new FastBuffer(data.buffer, data.byteOffset, data.length - 4);
443
+ }
444
+
445
+ //
446
+ // Ensure that the callback will not be called again in
447
+ // `PerMessageDeflate#cleanup()`.
448
+ //
449
+ this._deflate[kCallback] = null;
450
+
451
+ this._deflate[kTotalLength] = 0;
452
+ this._deflate[kBuffers] = [];
453
+
454
+ if (fin && this.params[`${endpoint}_no_context_takeover`]) {
455
+ this._deflate.reset();
456
+ }
457
+
458
+ callback(null, data);
459
+ });
460
+ }
461
+ }
462
+
463
+ module.exports = PerMessageDeflate;
464
+
465
+ /**
466
+ * The listener of the `zlib.DeflateRaw` stream `'data'` event.
467
+ *
468
+ * @param {Buffer} chunk A chunk of data
469
+ * @private
470
+ */
471
+ function deflateOnData(chunk) {
472
+ this[kBuffers].push(chunk);
473
+ this[kTotalLength] += chunk.length;
474
+ }
475
+
476
+ /**
477
+ * The listener of the `zlib.InflateRaw` stream `'data'` event.
478
+ *
479
+ * @param {Buffer} chunk A chunk of data
480
+ * @private
481
+ */
482
+ function inflateOnData(chunk) {
483
+ this[kTotalLength] += chunk.length;
484
+
485
+ if (
486
+ this[kPerMessageDeflate]._maxPayload < 1 ||
487
+ this[kTotalLength] <= this[kPerMessageDeflate]._maxPayload
488
+ ) {
489
+ this[kBuffers].push(chunk);
490
+ return;
491
+ }
492
+
493
+ this[kError] = new RangeError('Max payload size exceeded');
494
+ this[kError].code = 'WS_ERR_UNSUPPORTED_MESSAGE_LENGTH';
495
+ this[kError][kStatusCode] = 1009;
496
+ this.removeListener('data', inflateOnData);
497
+
498
+ //
499
+ // The choice to employ `zlib.reset()` over `zlib.close()` is dictated by the
500
+ // fact that in Node.js versions prior to 13.10.0, the callback for
501
+ // `zlib.flush()` is not called if `zlib.close()` is used. Utilizing
502
+ // `zlib.reset()` ensures that either the callback is invoked or an error is
503
+ // emitted.
504
+ //
505
+ this.reset();
506
+ }
507
+
508
+ /**
509
+ * The listener of the `zlib.InflateRaw` stream `'error'` event.
510
+ *
511
+ * @param {Error} err The emitted error
512
+ * @private
513
+ */
514
+ function inflateOnError(err) {
515
+ //
516
+ // There is no need to call `Zlib#close()` as the handle is automatically
517
+ // closed when an error is emitted.
518
+ //
519
+ this[kPerMessageDeflate]._inflate = null;
520
+
521
+ if (this[kError]) {
522
+ this[kCallback](this[kError]);
523
+ return;
524
+ }
525
+
526
+ err[kStatusCode] = 1007;
527
+ this[kCallback](err);
528
+ }