infront-logger 1.1.19 → 1.1.21

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/index.es.js CHANGED
@@ -1,3 +1,2767 @@
1
+ import require$$0$1 from "util";
2
+ import require$$0 from "events";
3
+ import https from "https";
4
+ var commonjsGlobal = typeof globalThis !== "undefined" ? globalThis : typeof window !== "undefined" ? window : typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : {};
5
+ function getDefaultExportFromCjs(x) {
6
+ return x && x.__esModule && Object.prototype.hasOwnProperty.call(x, "default") ? x["default"] : x;
7
+ }
8
+ function getAugmentedNamespace(n) {
9
+ if (n.__esModule) return n;
10
+ var f = n.default;
11
+ if (typeof f == "function") {
12
+ var a = function a2() {
13
+ if (this instanceof a2) {
14
+ return Reflect.construct(f, arguments, this.constructor);
15
+ }
16
+ return f.apply(this, arguments);
17
+ };
18
+ a.prototype = f.prototype;
19
+ } else a = {};
20
+ Object.defineProperty(a, "__esModule", { value: true });
21
+ Object.keys(n).forEach(function(k) {
22
+ var d = Object.getOwnPropertyDescriptor(n, k);
23
+ Object.defineProperty(a, k, d.get ? d : {
24
+ enumerable: true,
25
+ get: function() {
26
+ return n[k];
27
+ }
28
+ });
29
+ });
30
+ return a;
31
+ }
32
+ var dist = { exports: {} };
33
+ var modern = { exports: {} };
34
+ var browser = deprecate;
35
+ function deprecate(fn, msg) {
36
+ if (config$1("noDeprecation")) {
37
+ return fn;
38
+ }
39
+ var warned = false;
40
+ function deprecated() {
41
+ if (!warned) {
42
+ if (config$1("throwDeprecation")) {
43
+ throw new Error(msg);
44
+ } else if (config$1("traceDeprecation")) {
45
+ console.trace(msg);
46
+ } else {
47
+ console.warn(msg);
48
+ }
49
+ warned = true;
50
+ }
51
+ return fn.apply(this, arguments);
52
+ }
53
+ return deprecated;
54
+ }
55
+ function config$1(name) {
56
+ try {
57
+ if (!commonjsGlobal.localStorage) return false;
58
+ } catch (_) {
59
+ return false;
60
+ }
61
+ var val = commonjsGlobal.localStorage[name];
62
+ if (null == val) return false;
63
+ return String(val).toLowerCase() === "true";
64
+ }
65
+ var streamBrowser = require$$0.EventEmitter;
66
+ const __viteBrowserExternal = {};
67
+ const __viteBrowserExternal$1 = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
68
+ __proto__: null,
69
+ default: __viteBrowserExternal
70
+ }, Symbol.toStringTag, { value: "Module" }));
71
+ const require$$2 = /* @__PURE__ */ getAugmentedNamespace(__viteBrowserExternal$1);
72
+ function destroy(err, cb) {
73
+ var _this = this;
74
+ var readableDestroyed = this._readableState && this._readableState.destroyed;
75
+ var writableDestroyed = this._writableState && this._writableState.destroyed;
76
+ if (readableDestroyed || writableDestroyed) {
77
+ if (cb) {
78
+ cb(err);
79
+ } else if (err) {
80
+ if (!this._writableState) {
81
+ process.nextTick(emitErrorNT, this, err);
82
+ } else if (!this._writableState.errorEmitted) {
83
+ this._writableState.errorEmitted = true;
84
+ process.nextTick(emitErrorNT, this, err);
85
+ }
86
+ }
87
+ return this;
88
+ }
89
+ if (this._readableState) {
90
+ this._readableState.destroyed = true;
91
+ }
92
+ if (this._writableState) {
93
+ this._writableState.destroyed = true;
94
+ }
95
+ this._destroy(err || null, function(err2) {
96
+ if (!cb && err2) {
97
+ if (!_this._writableState) {
98
+ process.nextTick(emitErrorAndCloseNT, _this, err2);
99
+ } else if (!_this._writableState.errorEmitted) {
100
+ _this._writableState.errorEmitted = true;
101
+ process.nextTick(emitErrorAndCloseNT, _this, err2);
102
+ } else {
103
+ process.nextTick(emitCloseNT, _this);
104
+ }
105
+ } else if (cb) {
106
+ process.nextTick(emitCloseNT, _this);
107
+ cb(err2);
108
+ } else {
109
+ process.nextTick(emitCloseNT, _this);
110
+ }
111
+ });
112
+ return this;
113
+ }
114
+ function emitErrorAndCloseNT(self2, err) {
115
+ emitErrorNT(self2, err);
116
+ emitCloseNT(self2);
117
+ }
118
+ function emitCloseNT(self2) {
119
+ if (self2._writableState && !self2._writableState.emitClose) return;
120
+ if (self2._readableState && !self2._readableState.emitClose) return;
121
+ self2.emit("close");
122
+ }
123
+ function undestroy() {
124
+ if (this._readableState) {
125
+ this._readableState.destroyed = false;
126
+ this._readableState.reading = false;
127
+ this._readableState.ended = false;
128
+ this._readableState.endEmitted = false;
129
+ }
130
+ if (this._writableState) {
131
+ this._writableState.destroyed = false;
132
+ this._writableState.ended = false;
133
+ this._writableState.ending = false;
134
+ this._writableState.finalCalled = false;
135
+ this._writableState.prefinished = false;
136
+ this._writableState.finished = false;
137
+ this._writableState.errorEmitted = false;
138
+ }
139
+ }
140
+ function emitErrorNT(self2, err) {
141
+ self2.emit("error", err);
142
+ }
143
+ function errorOrDestroy(stream, err) {
144
+ var rState = stream._readableState;
145
+ var wState = stream._writableState;
146
+ if (rState && rState.autoDestroy || wState && wState.autoDestroy) stream.destroy(err);
147
+ else stream.emit("error", err);
148
+ }
149
+ var destroy_1 = {
150
+ destroy,
151
+ undestroy,
152
+ errorOrDestroy
153
+ };
154
+ var errorsBrowser = {};
155
+ function _inheritsLoose(subClass, superClass) {
156
+ subClass.prototype = Object.create(superClass.prototype);
157
+ subClass.prototype.constructor = subClass;
158
+ subClass.__proto__ = superClass;
159
+ }
160
+ var codes = {};
161
+ function createErrorType(code, message, Base) {
162
+ if (!Base) {
163
+ Base = Error;
164
+ }
165
+ function getMessage(arg1, arg2, arg3) {
166
+ if (typeof message === "string") {
167
+ return message;
168
+ } else {
169
+ return message(arg1, arg2, arg3);
170
+ }
171
+ }
172
+ var NodeError = /* @__PURE__ */ function(_Base) {
173
+ _inheritsLoose(NodeError2, _Base);
174
+ function NodeError2(arg1, arg2, arg3) {
175
+ return _Base.call(this, getMessage(arg1, arg2, arg3)) || this;
176
+ }
177
+ return NodeError2;
178
+ }(Base);
179
+ NodeError.prototype.name = Base.name;
180
+ NodeError.prototype.code = code;
181
+ codes[code] = NodeError;
182
+ }
183
+ function oneOf(expected, thing) {
184
+ if (Array.isArray(expected)) {
185
+ var len = expected.length;
186
+ expected = expected.map(function(i) {
187
+ return String(i);
188
+ });
189
+ if (len > 2) {
190
+ return "one of ".concat(thing, " ").concat(expected.slice(0, len - 1).join(", "), ", or ") + expected[len - 1];
191
+ } else if (len === 2) {
192
+ return "one of ".concat(thing, " ").concat(expected[0], " or ").concat(expected[1]);
193
+ } else {
194
+ return "of ".concat(thing, " ").concat(expected[0]);
195
+ }
196
+ } else {
197
+ return "of ".concat(thing, " ").concat(String(expected));
198
+ }
199
+ }
200
+ function startsWith(str, search, pos) {
201
+ return str.substr(0, search.length) === search;
202
+ }
203
+ function endsWith(str, search, this_len) {
204
+ if (this_len === void 0 || this_len > str.length) {
205
+ this_len = str.length;
206
+ }
207
+ return str.substring(this_len - search.length, this_len) === search;
208
+ }
209
+ function includes(str, search, start) {
210
+ if (typeof start !== "number") {
211
+ start = 0;
212
+ }
213
+ if (start + search.length > str.length) {
214
+ return false;
215
+ } else {
216
+ return str.indexOf(search, start) !== -1;
217
+ }
218
+ }
219
+ createErrorType("ERR_INVALID_OPT_VALUE", function(name, value) {
220
+ return 'The value "' + value + '" is invalid for option "' + name + '"';
221
+ }, TypeError);
222
+ createErrorType("ERR_INVALID_ARG_TYPE", function(name, expected, actual) {
223
+ var determiner;
224
+ if (typeof expected === "string" && startsWith(expected, "not ")) {
225
+ determiner = "must not be";
226
+ expected = expected.replace(/^not /, "");
227
+ } else {
228
+ determiner = "must be";
229
+ }
230
+ var msg;
231
+ if (endsWith(name, " argument")) {
232
+ msg = "The ".concat(name, " ").concat(determiner, " ").concat(oneOf(expected, "type"));
233
+ } else {
234
+ var type = includes(name, ".") ? "property" : "argument";
235
+ msg = 'The "'.concat(name, '" ').concat(type, " ").concat(determiner, " ").concat(oneOf(expected, "type"));
236
+ }
237
+ msg += ". Received type ".concat(typeof actual);
238
+ return msg;
239
+ }, TypeError);
240
+ createErrorType("ERR_STREAM_PUSH_AFTER_EOF", "stream.push() after EOF");
241
+ createErrorType("ERR_METHOD_NOT_IMPLEMENTED", function(name) {
242
+ return "The " + name + " method is not implemented";
243
+ });
244
+ createErrorType("ERR_STREAM_PREMATURE_CLOSE", "Premature close");
245
+ createErrorType("ERR_STREAM_DESTROYED", function(name) {
246
+ return "Cannot call " + name + " after a stream was destroyed";
247
+ });
248
+ createErrorType("ERR_MULTIPLE_CALLBACK", "Callback called multiple times");
249
+ createErrorType("ERR_STREAM_CANNOT_PIPE", "Cannot pipe, not readable");
250
+ createErrorType("ERR_STREAM_WRITE_AFTER_END", "write after end");
251
+ createErrorType("ERR_STREAM_NULL_VALUES", "May not write null values to stream", TypeError);
252
+ createErrorType("ERR_UNKNOWN_ENCODING", function(arg) {
253
+ return "Unknown encoding: " + arg;
254
+ }, TypeError);
255
+ createErrorType("ERR_STREAM_UNSHIFT_AFTER_END_EVENT", "stream.unshift() after end event");
256
+ errorsBrowser.codes = codes;
257
+ var ERR_INVALID_OPT_VALUE = errorsBrowser.codes.ERR_INVALID_OPT_VALUE;
258
+ function highWaterMarkFrom(options, isDuplex, duplexKey) {
259
+ return options.highWaterMark != null ? options.highWaterMark : isDuplex ? options[duplexKey] : null;
260
+ }
261
+ function getHighWaterMark(state2, options, duplexKey, isDuplex) {
262
+ var hwm = highWaterMarkFrom(options, isDuplex, duplexKey);
263
+ if (hwm != null) {
264
+ if (!(isFinite(hwm) && Math.floor(hwm) === hwm) || hwm < 0) {
265
+ var name = isDuplex ? duplexKey : "highWaterMark";
266
+ throw new ERR_INVALID_OPT_VALUE(name, hwm);
267
+ }
268
+ return Math.floor(hwm);
269
+ }
270
+ return state2.objectMode ? 16 : 16 * 1024;
271
+ }
272
+ var state = {
273
+ getHighWaterMark
274
+ };
275
+ var inherits_browser = { exports: {} };
276
+ if (typeof Object.create === "function") {
277
+ inherits_browser.exports = function inherits(ctor, superCtor) {
278
+ if (superCtor) {
279
+ ctor.super_ = superCtor;
280
+ ctor.prototype = Object.create(superCtor.prototype, {
281
+ constructor: {
282
+ value: ctor,
283
+ enumerable: false,
284
+ writable: true,
285
+ configurable: true
286
+ }
287
+ });
288
+ }
289
+ };
290
+ } else {
291
+ inherits_browser.exports = function inherits(ctor, superCtor) {
292
+ if (superCtor) {
293
+ ctor.super_ = superCtor;
294
+ var TempCtor = function() {
295
+ };
296
+ TempCtor.prototype = superCtor.prototype;
297
+ ctor.prototype = new TempCtor();
298
+ ctor.prototype.constructor = ctor;
299
+ }
300
+ };
301
+ }
302
+ var inherits_browserExports = inherits_browser.exports;
303
+ var buffer_list;
304
+ var hasRequiredBuffer_list;
305
+ function requireBuffer_list() {
306
+ if (hasRequiredBuffer_list) return buffer_list;
307
+ hasRequiredBuffer_list = 1;
308
+ function ownKeys(object2, enumerableOnly) {
309
+ var keys = Object.keys(object2);
310
+ if (Object.getOwnPropertySymbols) {
311
+ var symbols = Object.getOwnPropertySymbols(object2);
312
+ enumerableOnly && (symbols = symbols.filter(function(sym) {
313
+ return Object.getOwnPropertyDescriptor(object2, sym).enumerable;
314
+ })), keys.push.apply(keys, symbols);
315
+ }
316
+ return keys;
317
+ }
318
+ function _objectSpread(target) {
319
+ for (var i = 1; i < arguments.length; i++) {
320
+ var source = null != arguments[i] ? arguments[i] : {};
321
+ i % 2 ? ownKeys(Object(source), true).forEach(function(key) {
322
+ _defineProperty(target, key, source[key]);
323
+ }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function(key) {
324
+ Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key));
325
+ });
326
+ }
327
+ return target;
328
+ }
329
+ function _defineProperty(obj, key, value) {
330
+ key = _toPropertyKey(key);
331
+ if (key in obj) {
332
+ Object.defineProperty(obj, key, { value, enumerable: true, configurable: true, writable: true });
333
+ } else {
334
+ obj[key] = value;
335
+ }
336
+ return obj;
337
+ }
338
+ function _classCallCheck(instance, Constructor) {
339
+ if (!(instance instanceof Constructor)) {
340
+ throw new TypeError("Cannot call a class as a function");
341
+ }
342
+ }
343
+ function _defineProperties(target, props) {
344
+ for (var i = 0; i < props.length; i++) {
345
+ var descriptor = props[i];
346
+ descriptor.enumerable = descriptor.enumerable || false;
347
+ descriptor.configurable = true;
348
+ if ("value" in descriptor) descriptor.writable = true;
349
+ Object.defineProperty(target, _toPropertyKey(descriptor.key), descriptor);
350
+ }
351
+ }
352
+ function _createClass(Constructor, protoProps, staticProps) {
353
+ if (protoProps) _defineProperties(Constructor.prototype, protoProps);
354
+ Object.defineProperty(Constructor, "prototype", { writable: false });
355
+ return Constructor;
356
+ }
357
+ function _toPropertyKey(arg) {
358
+ var key = _toPrimitive(arg, "string");
359
+ return typeof key === "symbol" ? key : String(key);
360
+ }
361
+ function _toPrimitive(input, hint) {
362
+ if (typeof input !== "object" || input === null) return input;
363
+ var prim = input[Symbol.toPrimitive];
364
+ if (prim !== void 0) {
365
+ var res = prim.call(input, hint);
366
+ if (typeof res !== "object") return res;
367
+ throw new TypeError("@@toPrimitive must return a primitive value.");
368
+ }
369
+ return String(input);
370
+ }
371
+ var _require2 = require$$2, Buffer2 = _require2.Buffer;
372
+ var _require22 = require$$0$1, inspect2 = _require22.inspect;
373
+ var custom = inspect2 && inspect2.custom || "inspect";
374
+ function copyBuffer(src, target, offset) {
375
+ Buffer2.prototype.copy.call(src, target, offset);
376
+ }
377
+ buffer_list = /* @__PURE__ */ function() {
378
+ function BufferList() {
379
+ _classCallCheck(this, BufferList);
380
+ this.head = null;
381
+ this.tail = null;
382
+ this.length = 0;
383
+ }
384
+ _createClass(BufferList, [{
385
+ key: "push",
386
+ value: function push(v) {
387
+ var entry = {
388
+ data: v,
389
+ next: null
390
+ };
391
+ if (this.length > 0) this.tail.next = entry;
392
+ else this.head = entry;
393
+ this.tail = entry;
394
+ ++this.length;
395
+ }
396
+ }, {
397
+ key: "unshift",
398
+ value: function unshift(v) {
399
+ var entry = {
400
+ data: v,
401
+ next: this.head
402
+ };
403
+ if (this.length === 0) this.tail = entry;
404
+ this.head = entry;
405
+ ++this.length;
406
+ }
407
+ }, {
408
+ key: "shift",
409
+ value: function shift() {
410
+ if (this.length === 0) return;
411
+ var ret = this.head.data;
412
+ if (this.length === 1) this.head = this.tail = null;
413
+ else this.head = this.head.next;
414
+ --this.length;
415
+ return ret;
416
+ }
417
+ }, {
418
+ key: "clear",
419
+ value: function clear() {
420
+ this.head = this.tail = null;
421
+ this.length = 0;
422
+ }
423
+ }, {
424
+ key: "join",
425
+ value: function join(s) {
426
+ if (this.length === 0) return "";
427
+ var p = this.head;
428
+ var ret = "" + p.data;
429
+ while (p = p.next) ret += s + p.data;
430
+ return ret;
431
+ }
432
+ }, {
433
+ key: "concat",
434
+ value: function concat(n) {
435
+ if (this.length === 0) return Buffer2.alloc(0);
436
+ var ret = Buffer2.allocUnsafe(n >>> 0);
437
+ var p = this.head;
438
+ var i = 0;
439
+ while (p) {
440
+ copyBuffer(p.data, ret, i);
441
+ i += p.data.length;
442
+ p = p.next;
443
+ }
444
+ return ret;
445
+ }
446
+ // Consumes a specified amount of bytes or characters from the buffered data.
447
+ }, {
448
+ key: "consume",
449
+ value: function consume(n, hasStrings) {
450
+ var ret;
451
+ if (n < this.head.data.length) {
452
+ ret = this.head.data.slice(0, n);
453
+ this.head.data = this.head.data.slice(n);
454
+ } else if (n === this.head.data.length) {
455
+ ret = this.shift();
456
+ } else {
457
+ ret = hasStrings ? this._getString(n) : this._getBuffer(n);
458
+ }
459
+ return ret;
460
+ }
461
+ }, {
462
+ key: "first",
463
+ value: function first() {
464
+ return this.head.data;
465
+ }
466
+ // Consumes a specified amount of characters from the buffered data.
467
+ }, {
468
+ key: "_getString",
469
+ value: function _getString(n) {
470
+ var p = this.head;
471
+ var c = 1;
472
+ var ret = p.data;
473
+ n -= ret.length;
474
+ while (p = p.next) {
475
+ var str = p.data;
476
+ var nb = n > str.length ? str.length : n;
477
+ if (nb === str.length) ret += str;
478
+ else ret += str.slice(0, n);
479
+ n -= nb;
480
+ if (n === 0) {
481
+ if (nb === str.length) {
482
+ ++c;
483
+ if (p.next) this.head = p.next;
484
+ else this.head = this.tail = null;
485
+ } else {
486
+ this.head = p;
487
+ p.data = str.slice(nb);
488
+ }
489
+ break;
490
+ }
491
+ ++c;
492
+ }
493
+ this.length -= c;
494
+ return ret;
495
+ }
496
+ // Consumes a specified amount of bytes from the buffered data.
497
+ }, {
498
+ key: "_getBuffer",
499
+ value: function _getBuffer(n) {
500
+ var ret = Buffer2.allocUnsafe(n);
501
+ var p = this.head;
502
+ var c = 1;
503
+ p.data.copy(ret);
504
+ n -= p.data.length;
505
+ while (p = p.next) {
506
+ var buf = p.data;
507
+ var nb = n > buf.length ? buf.length : n;
508
+ buf.copy(ret, ret.length - n, 0, nb);
509
+ n -= nb;
510
+ if (n === 0) {
511
+ if (nb === buf.length) {
512
+ ++c;
513
+ if (p.next) this.head = p.next;
514
+ else this.head = this.tail = null;
515
+ } else {
516
+ this.head = p;
517
+ p.data = buf.slice(nb);
518
+ }
519
+ break;
520
+ }
521
+ ++c;
522
+ }
523
+ this.length -= c;
524
+ return ret;
525
+ }
526
+ // Make sure the linked list only shows the minimal necessary information.
527
+ }, {
528
+ key: custom,
529
+ value: function value(_, options) {
530
+ return inspect2(this, _objectSpread(_objectSpread({}, options), {}, {
531
+ // Only inspect one level.
532
+ depth: 0,
533
+ // It should not recurse.
534
+ customInspect: false
535
+ }));
536
+ }
537
+ }]);
538
+ return BufferList;
539
+ }();
540
+ return buffer_list;
541
+ }
542
+ var string_decoder = {};
543
+ var safeBuffer = { exports: {} };
544
+ /*! safe-buffer. MIT License. Feross Aboukhadijeh <https://feross.org/opensource> */
545
+ var hasRequiredSafeBuffer;
546
+ function requireSafeBuffer() {
547
+ if (hasRequiredSafeBuffer) return safeBuffer.exports;
548
+ hasRequiredSafeBuffer = 1;
549
+ (function(module, exports) {
550
+ var buffer = require$$2;
551
+ var Buffer2 = buffer.Buffer;
552
+ function copyProps(src, dst) {
553
+ for (var key in src) {
554
+ dst[key] = src[key];
555
+ }
556
+ }
557
+ if (Buffer2.from && Buffer2.alloc && Buffer2.allocUnsafe && Buffer2.allocUnsafeSlow) {
558
+ module.exports = buffer;
559
+ } else {
560
+ copyProps(buffer, exports);
561
+ exports.Buffer = SafeBuffer;
562
+ }
563
+ function SafeBuffer(arg, encodingOrOffset, length) {
564
+ return Buffer2(arg, encodingOrOffset, length);
565
+ }
566
+ SafeBuffer.prototype = Object.create(Buffer2.prototype);
567
+ copyProps(Buffer2, SafeBuffer);
568
+ SafeBuffer.from = function(arg, encodingOrOffset, length) {
569
+ if (typeof arg === "number") {
570
+ throw new TypeError("Argument must not be a number");
571
+ }
572
+ return Buffer2(arg, encodingOrOffset, length);
573
+ };
574
+ SafeBuffer.alloc = function(size, fill, encoding) {
575
+ if (typeof size !== "number") {
576
+ throw new TypeError("Argument must be a number");
577
+ }
578
+ var buf = Buffer2(size);
579
+ if (fill !== void 0) {
580
+ if (typeof encoding === "string") {
581
+ buf.fill(fill, encoding);
582
+ } else {
583
+ buf.fill(fill);
584
+ }
585
+ } else {
586
+ buf.fill(0);
587
+ }
588
+ return buf;
589
+ };
590
+ SafeBuffer.allocUnsafe = function(size) {
591
+ if (typeof size !== "number") {
592
+ throw new TypeError("Argument must be a number");
593
+ }
594
+ return Buffer2(size);
595
+ };
596
+ SafeBuffer.allocUnsafeSlow = function(size) {
597
+ if (typeof size !== "number") {
598
+ throw new TypeError("Argument must be a number");
599
+ }
600
+ return buffer.SlowBuffer(size);
601
+ };
602
+ })(safeBuffer, safeBuffer.exports);
603
+ return safeBuffer.exports;
604
+ }
605
+ var hasRequiredString_decoder;
606
+ function requireString_decoder() {
607
+ if (hasRequiredString_decoder) return string_decoder;
608
+ hasRequiredString_decoder = 1;
609
+ var Buffer2 = requireSafeBuffer().Buffer;
610
+ var isEncoding = Buffer2.isEncoding || function(encoding) {
611
+ encoding = "" + encoding;
612
+ switch (encoding && encoding.toLowerCase()) {
613
+ case "hex":
614
+ case "utf8":
615
+ case "utf-8":
616
+ case "ascii":
617
+ case "binary":
618
+ case "base64":
619
+ case "ucs2":
620
+ case "ucs-2":
621
+ case "utf16le":
622
+ case "utf-16le":
623
+ case "raw":
624
+ return true;
625
+ default:
626
+ return false;
627
+ }
628
+ };
629
+ function _normalizeEncoding(enc) {
630
+ if (!enc) return "utf8";
631
+ var retried;
632
+ while (true) {
633
+ switch (enc) {
634
+ case "utf8":
635
+ case "utf-8":
636
+ return "utf8";
637
+ case "ucs2":
638
+ case "ucs-2":
639
+ case "utf16le":
640
+ case "utf-16le":
641
+ return "utf16le";
642
+ case "latin1":
643
+ case "binary":
644
+ return "latin1";
645
+ case "base64":
646
+ case "ascii":
647
+ case "hex":
648
+ return enc;
649
+ default:
650
+ if (retried) return;
651
+ enc = ("" + enc).toLowerCase();
652
+ retried = true;
653
+ }
654
+ }
655
+ }
656
+ function normalizeEncoding(enc) {
657
+ var nenc = _normalizeEncoding(enc);
658
+ if (typeof nenc !== "string" && (Buffer2.isEncoding === isEncoding || !isEncoding(enc))) throw new Error("Unknown encoding: " + enc);
659
+ return nenc || enc;
660
+ }
661
+ string_decoder.StringDecoder = StringDecoder;
662
+ function StringDecoder(encoding) {
663
+ this.encoding = normalizeEncoding(encoding);
664
+ var nb;
665
+ switch (this.encoding) {
666
+ case "utf16le":
667
+ this.text = utf16Text;
668
+ this.end = utf16End;
669
+ nb = 4;
670
+ break;
671
+ case "utf8":
672
+ this.fillLast = utf8FillLast;
673
+ nb = 4;
674
+ break;
675
+ case "base64":
676
+ this.text = base64Text;
677
+ this.end = base64End;
678
+ nb = 3;
679
+ break;
680
+ default:
681
+ this.write = simpleWrite;
682
+ this.end = simpleEnd;
683
+ return;
684
+ }
685
+ this.lastNeed = 0;
686
+ this.lastTotal = 0;
687
+ this.lastChar = Buffer2.allocUnsafe(nb);
688
+ }
689
+ StringDecoder.prototype.write = function(buf) {
690
+ if (buf.length === 0) return "";
691
+ var r;
692
+ var i;
693
+ if (this.lastNeed) {
694
+ r = this.fillLast(buf);
695
+ if (r === void 0) return "";
696
+ i = this.lastNeed;
697
+ this.lastNeed = 0;
698
+ } else {
699
+ i = 0;
700
+ }
701
+ if (i < buf.length) return r ? r + this.text(buf, i) : this.text(buf, i);
702
+ return r || "";
703
+ };
704
+ StringDecoder.prototype.end = utf8End;
705
+ StringDecoder.prototype.text = utf8Text;
706
+ StringDecoder.prototype.fillLast = function(buf) {
707
+ if (this.lastNeed <= buf.length) {
708
+ buf.copy(this.lastChar, this.lastTotal - this.lastNeed, 0, this.lastNeed);
709
+ return this.lastChar.toString(this.encoding, 0, this.lastTotal);
710
+ }
711
+ buf.copy(this.lastChar, this.lastTotal - this.lastNeed, 0, buf.length);
712
+ this.lastNeed -= buf.length;
713
+ };
714
+ function utf8CheckByte(byte) {
715
+ if (byte <= 127) return 0;
716
+ else if (byte >> 5 === 6) return 2;
717
+ else if (byte >> 4 === 14) return 3;
718
+ else if (byte >> 3 === 30) return 4;
719
+ return byte >> 6 === 2 ? -1 : -2;
720
+ }
721
+ function utf8CheckIncomplete(self2, buf, i) {
722
+ var j = buf.length - 1;
723
+ if (j < i) return 0;
724
+ var nb = utf8CheckByte(buf[j]);
725
+ if (nb >= 0) {
726
+ if (nb > 0) self2.lastNeed = nb - 1;
727
+ return nb;
728
+ }
729
+ if (--j < i || nb === -2) return 0;
730
+ nb = utf8CheckByte(buf[j]);
731
+ if (nb >= 0) {
732
+ if (nb > 0) self2.lastNeed = nb - 2;
733
+ return nb;
734
+ }
735
+ if (--j < i || nb === -2) return 0;
736
+ nb = utf8CheckByte(buf[j]);
737
+ if (nb >= 0) {
738
+ if (nb > 0) {
739
+ if (nb === 2) nb = 0;
740
+ else self2.lastNeed = nb - 3;
741
+ }
742
+ return nb;
743
+ }
744
+ return 0;
745
+ }
746
+ function utf8CheckExtraBytes(self2, buf, p) {
747
+ if ((buf[0] & 192) !== 128) {
748
+ self2.lastNeed = 0;
749
+ return "�";
750
+ }
751
+ if (self2.lastNeed > 1 && buf.length > 1) {
752
+ if ((buf[1] & 192) !== 128) {
753
+ self2.lastNeed = 1;
754
+ return "�";
755
+ }
756
+ if (self2.lastNeed > 2 && buf.length > 2) {
757
+ if ((buf[2] & 192) !== 128) {
758
+ self2.lastNeed = 2;
759
+ return "�";
760
+ }
761
+ }
762
+ }
763
+ }
764
+ function utf8FillLast(buf) {
765
+ var p = this.lastTotal - this.lastNeed;
766
+ var r = utf8CheckExtraBytes(this, buf);
767
+ if (r !== void 0) return r;
768
+ if (this.lastNeed <= buf.length) {
769
+ buf.copy(this.lastChar, p, 0, this.lastNeed);
770
+ return this.lastChar.toString(this.encoding, 0, this.lastTotal);
771
+ }
772
+ buf.copy(this.lastChar, p, 0, buf.length);
773
+ this.lastNeed -= buf.length;
774
+ }
775
+ function utf8Text(buf, i) {
776
+ var total = utf8CheckIncomplete(this, buf, i);
777
+ if (!this.lastNeed) return buf.toString("utf8", i);
778
+ this.lastTotal = total;
779
+ var end = buf.length - (total - this.lastNeed);
780
+ buf.copy(this.lastChar, 0, end);
781
+ return buf.toString("utf8", i, end);
782
+ }
783
+ function utf8End(buf) {
784
+ var r = buf && buf.length ? this.write(buf) : "";
785
+ if (this.lastNeed) return r + "�";
786
+ return r;
787
+ }
788
+ function utf16Text(buf, i) {
789
+ if ((buf.length - i) % 2 === 0) {
790
+ var r = buf.toString("utf16le", i);
791
+ if (r) {
792
+ var c = r.charCodeAt(r.length - 1);
793
+ if (c >= 55296 && c <= 56319) {
794
+ this.lastNeed = 2;
795
+ this.lastTotal = 4;
796
+ this.lastChar[0] = buf[buf.length - 2];
797
+ this.lastChar[1] = buf[buf.length - 1];
798
+ return r.slice(0, -1);
799
+ }
800
+ }
801
+ return r;
802
+ }
803
+ this.lastNeed = 1;
804
+ this.lastTotal = 2;
805
+ this.lastChar[0] = buf[buf.length - 1];
806
+ return buf.toString("utf16le", i, buf.length - 1);
807
+ }
808
+ function utf16End(buf) {
809
+ var r = buf && buf.length ? this.write(buf) : "";
810
+ if (this.lastNeed) {
811
+ var end = this.lastTotal - this.lastNeed;
812
+ return r + this.lastChar.toString("utf16le", 0, end);
813
+ }
814
+ return r;
815
+ }
816
+ function base64Text(buf, i) {
817
+ var n = (buf.length - i) % 3;
818
+ if (n === 0) return buf.toString("base64", i);
819
+ this.lastNeed = 3 - n;
820
+ this.lastTotal = 3;
821
+ if (n === 1) {
822
+ this.lastChar[0] = buf[buf.length - 1];
823
+ } else {
824
+ this.lastChar[0] = buf[buf.length - 2];
825
+ this.lastChar[1] = buf[buf.length - 1];
826
+ }
827
+ return buf.toString("base64", i, buf.length - n);
828
+ }
829
+ function base64End(buf) {
830
+ var r = buf && buf.length ? this.write(buf) : "";
831
+ if (this.lastNeed) return r + this.lastChar.toString("base64", 0, 3 - this.lastNeed);
832
+ return r;
833
+ }
834
+ function simpleWrite(buf) {
835
+ return buf.toString(this.encoding);
836
+ }
837
+ function simpleEnd(buf) {
838
+ return buf && buf.length ? this.write(buf) : "";
839
+ }
840
+ return string_decoder;
841
+ }
842
+ var endOfStream;
843
+ var hasRequiredEndOfStream;
844
+ function requireEndOfStream() {
845
+ if (hasRequiredEndOfStream) return endOfStream;
846
+ hasRequiredEndOfStream = 1;
847
+ var ERR_STREAM_PREMATURE_CLOSE = errorsBrowser.codes.ERR_STREAM_PREMATURE_CLOSE;
848
+ function once(callback) {
849
+ var called = false;
850
+ return function() {
851
+ if (called) return;
852
+ called = true;
853
+ for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
854
+ args[_key] = arguments[_key];
855
+ }
856
+ callback.apply(this, args);
857
+ };
858
+ }
859
+ function noop() {
860
+ }
861
+ function isRequest(stream) {
862
+ return stream.setHeader && typeof stream.abort === "function";
863
+ }
864
+ function eos(stream, opts, callback) {
865
+ if (typeof opts === "function") return eos(stream, null, opts);
866
+ if (!opts) opts = {};
867
+ callback = once(callback || noop);
868
+ var readable = opts.readable || opts.readable !== false && stream.readable;
869
+ var writable = opts.writable || opts.writable !== false && stream.writable;
870
+ var onlegacyfinish = function onlegacyfinish2() {
871
+ if (!stream.writable) onfinish();
872
+ };
873
+ var writableEnded = stream._writableState && stream._writableState.finished;
874
+ var onfinish = function onfinish2() {
875
+ writable = false;
876
+ writableEnded = true;
877
+ if (!readable) callback.call(stream);
878
+ };
879
+ var readableEnded = stream._readableState && stream._readableState.endEmitted;
880
+ var onend = function onend2() {
881
+ readable = false;
882
+ readableEnded = true;
883
+ if (!writable) callback.call(stream);
884
+ };
885
+ var onerror = function onerror2(err) {
886
+ callback.call(stream, err);
887
+ };
888
+ var onclose = function onclose2() {
889
+ var err;
890
+ if (readable && !readableEnded) {
891
+ if (!stream._readableState || !stream._readableState.ended) err = new ERR_STREAM_PREMATURE_CLOSE();
892
+ return callback.call(stream, err);
893
+ }
894
+ if (writable && !writableEnded) {
895
+ if (!stream._writableState || !stream._writableState.ended) err = new ERR_STREAM_PREMATURE_CLOSE();
896
+ return callback.call(stream, err);
897
+ }
898
+ };
899
+ var onrequest = function onrequest2() {
900
+ stream.req.on("finish", onfinish);
901
+ };
902
+ if (isRequest(stream)) {
903
+ stream.on("complete", onfinish);
904
+ stream.on("abort", onclose);
905
+ if (stream.req) onrequest();
906
+ else stream.on("request", onrequest);
907
+ } else if (writable && !stream._writableState) {
908
+ stream.on("end", onlegacyfinish);
909
+ stream.on("close", onlegacyfinish);
910
+ }
911
+ stream.on("end", onend);
912
+ stream.on("finish", onfinish);
913
+ if (opts.error !== false) stream.on("error", onerror);
914
+ stream.on("close", onclose);
915
+ return function() {
916
+ stream.removeListener("complete", onfinish);
917
+ stream.removeListener("abort", onclose);
918
+ stream.removeListener("request", onrequest);
919
+ if (stream.req) stream.req.removeListener("finish", onfinish);
920
+ stream.removeListener("end", onlegacyfinish);
921
+ stream.removeListener("close", onlegacyfinish);
922
+ stream.removeListener("finish", onfinish);
923
+ stream.removeListener("end", onend);
924
+ stream.removeListener("error", onerror);
925
+ stream.removeListener("close", onclose);
926
+ };
927
+ }
928
+ endOfStream = eos;
929
+ return endOfStream;
930
+ }
931
+ var async_iterator;
932
+ var hasRequiredAsync_iterator;
933
+ function requireAsync_iterator() {
934
+ if (hasRequiredAsync_iterator) return async_iterator;
935
+ hasRequiredAsync_iterator = 1;
936
+ var _Object$setPrototypeO;
937
+ function _defineProperty(obj, key, value) {
938
+ key = _toPropertyKey(key);
939
+ if (key in obj) {
940
+ Object.defineProperty(obj, key, { value, enumerable: true, configurable: true, writable: true });
941
+ } else {
942
+ obj[key] = value;
943
+ }
944
+ return obj;
945
+ }
946
+ function _toPropertyKey(arg) {
947
+ var key = _toPrimitive(arg, "string");
948
+ return typeof key === "symbol" ? key : String(key);
949
+ }
950
+ function _toPrimitive(input, hint) {
951
+ if (typeof input !== "object" || input === null) return input;
952
+ var prim = input[Symbol.toPrimitive];
953
+ if (prim !== void 0) {
954
+ var res = prim.call(input, hint);
955
+ if (typeof res !== "object") return res;
956
+ throw new TypeError("@@toPrimitive must return a primitive value.");
957
+ }
958
+ return (hint === "string" ? String : Number)(input);
959
+ }
960
+ var finished = requireEndOfStream();
961
+ var kLastResolve = Symbol("lastResolve");
962
+ var kLastReject = Symbol("lastReject");
963
+ var kError = Symbol("error");
964
+ var kEnded = Symbol("ended");
965
+ var kLastPromise = Symbol("lastPromise");
966
+ var kHandlePromise = Symbol("handlePromise");
967
+ var kStream = Symbol("stream");
968
+ function createIterResult(value, done) {
969
+ return {
970
+ value,
971
+ done
972
+ };
973
+ }
974
+ function readAndResolve(iter) {
975
+ var resolve = iter[kLastResolve];
976
+ if (resolve !== null) {
977
+ var data = iter[kStream].read();
978
+ if (data !== null) {
979
+ iter[kLastPromise] = null;
980
+ iter[kLastResolve] = null;
981
+ iter[kLastReject] = null;
982
+ resolve(createIterResult(data, false));
983
+ }
984
+ }
985
+ }
986
+ function onReadable(iter) {
987
+ process.nextTick(readAndResolve, iter);
988
+ }
989
+ function wrapForNext(lastPromise, iter) {
990
+ return function(resolve, reject) {
991
+ lastPromise.then(function() {
992
+ if (iter[kEnded]) {
993
+ resolve(createIterResult(void 0, true));
994
+ return;
995
+ }
996
+ iter[kHandlePromise](resolve, reject);
997
+ }, reject);
998
+ };
999
+ }
1000
+ var AsyncIteratorPrototype = Object.getPrototypeOf(function() {
1001
+ });
1002
+ var ReadableStreamAsyncIteratorPrototype = Object.setPrototypeOf((_Object$setPrototypeO = {
1003
+ get stream() {
1004
+ return this[kStream];
1005
+ },
1006
+ next: function next() {
1007
+ var _this = this;
1008
+ var error = this[kError];
1009
+ if (error !== null) {
1010
+ return Promise.reject(error);
1011
+ }
1012
+ if (this[kEnded]) {
1013
+ return Promise.resolve(createIterResult(void 0, true));
1014
+ }
1015
+ if (this[kStream].destroyed) {
1016
+ return new Promise(function(resolve, reject) {
1017
+ process.nextTick(function() {
1018
+ if (_this[kError]) {
1019
+ reject(_this[kError]);
1020
+ } else {
1021
+ resolve(createIterResult(void 0, true));
1022
+ }
1023
+ });
1024
+ });
1025
+ }
1026
+ var lastPromise = this[kLastPromise];
1027
+ var promise;
1028
+ if (lastPromise) {
1029
+ promise = new Promise(wrapForNext(lastPromise, this));
1030
+ } else {
1031
+ var data = this[kStream].read();
1032
+ if (data !== null) {
1033
+ return Promise.resolve(createIterResult(data, false));
1034
+ }
1035
+ promise = new Promise(this[kHandlePromise]);
1036
+ }
1037
+ this[kLastPromise] = promise;
1038
+ return promise;
1039
+ }
1040
+ }, _defineProperty(_Object$setPrototypeO, Symbol.asyncIterator, function() {
1041
+ return this;
1042
+ }), _defineProperty(_Object$setPrototypeO, "return", function _return() {
1043
+ var _this2 = this;
1044
+ return new Promise(function(resolve, reject) {
1045
+ _this2[kStream].destroy(null, function(err) {
1046
+ if (err) {
1047
+ reject(err);
1048
+ return;
1049
+ }
1050
+ resolve(createIterResult(void 0, true));
1051
+ });
1052
+ });
1053
+ }), _Object$setPrototypeO), AsyncIteratorPrototype);
1054
+ var createReadableStreamAsyncIterator = function createReadableStreamAsyncIterator2(stream) {
1055
+ var _Object$create;
1056
+ var iterator = Object.create(ReadableStreamAsyncIteratorPrototype, (_Object$create = {}, _defineProperty(_Object$create, kStream, {
1057
+ value: stream,
1058
+ writable: true
1059
+ }), _defineProperty(_Object$create, kLastResolve, {
1060
+ value: null,
1061
+ writable: true
1062
+ }), _defineProperty(_Object$create, kLastReject, {
1063
+ value: null,
1064
+ writable: true
1065
+ }), _defineProperty(_Object$create, kError, {
1066
+ value: null,
1067
+ writable: true
1068
+ }), _defineProperty(_Object$create, kEnded, {
1069
+ value: stream._readableState.endEmitted,
1070
+ writable: true
1071
+ }), _defineProperty(_Object$create, kHandlePromise, {
1072
+ value: function value(resolve, reject) {
1073
+ var data = iterator[kStream].read();
1074
+ if (data) {
1075
+ iterator[kLastPromise] = null;
1076
+ iterator[kLastResolve] = null;
1077
+ iterator[kLastReject] = null;
1078
+ resolve(createIterResult(data, false));
1079
+ } else {
1080
+ iterator[kLastResolve] = resolve;
1081
+ iterator[kLastReject] = reject;
1082
+ }
1083
+ },
1084
+ writable: true
1085
+ }), _Object$create));
1086
+ iterator[kLastPromise] = null;
1087
+ finished(stream, function(err) {
1088
+ if (err && err.code !== "ERR_STREAM_PREMATURE_CLOSE") {
1089
+ var reject = iterator[kLastReject];
1090
+ if (reject !== null) {
1091
+ iterator[kLastPromise] = null;
1092
+ iterator[kLastResolve] = null;
1093
+ iterator[kLastReject] = null;
1094
+ reject(err);
1095
+ }
1096
+ iterator[kError] = err;
1097
+ return;
1098
+ }
1099
+ var resolve = iterator[kLastResolve];
1100
+ if (resolve !== null) {
1101
+ iterator[kLastPromise] = null;
1102
+ iterator[kLastResolve] = null;
1103
+ iterator[kLastReject] = null;
1104
+ resolve(createIterResult(void 0, true));
1105
+ }
1106
+ iterator[kEnded] = true;
1107
+ });
1108
+ stream.on("readable", onReadable.bind(null, iterator));
1109
+ return iterator;
1110
+ };
1111
+ async_iterator = createReadableStreamAsyncIterator;
1112
+ return async_iterator;
1113
+ }
1114
+ var fromBrowser;
1115
+ var hasRequiredFromBrowser;
1116
+ function requireFromBrowser() {
1117
+ if (hasRequiredFromBrowser) return fromBrowser;
1118
+ hasRequiredFromBrowser = 1;
1119
+ fromBrowser = function() {
1120
+ throw new Error("Readable.from is not available in the browser");
1121
+ };
1122
+ return fromBrowser;
1123
+ }
1124
+ var _stream_readable;
1125
+ var hasRequired_stream_readable;
1126
+ function require_stream_readable() {
1127
+ if (hasRequired_stream_readable) return _stream_readable;
1128
+ hasRequired_stream_readable = 1;
1129
+ _stream_readable = Readable;
1130
+ var Duplex;
1131
+ Readable.ReadableState = ReadableState;
1132
+ require$$0.EventEmitter;
1133
+ var EElistenerCount = function EElistenerCount2(emitter, type) {
1134
+ return emitter.listeners(type).length;
1135
+ };
1136
+ var Stream = streamBrowser;
1137
+ var Buffer2 = require$$2.Buffer;
1138
+ var OurUint8Array = (typeof commonjsGlobal !== "undefined" ? commonjsGlobal : typeof window !== "undefined" ? window : typeof self !== "undefined" ? self : {}).Uint8Array || function() {
1139
+ };
1140
+ function _uint8ArrayToBuffer(chunk) {
1141
+ return Buffer2.from(chunk);
1142
+ }
1143
+ function _isUint8Array(obj) {
1144
+ return Buffer2.isBuffer(obj) || obj instanceof OurUint8Array;
1145
+ }
1146
+ var debugUtil = require$$0$1;
1147
+ var debug;
1148
+ if (debugUtil && debugUtil.debuglog) {
1149
+ debug = debugUtil.debuglog("stream");
1150
+ } else {
1151
+ debug = function debug2() {
1152
+ };
1153
+ }
1154
+ var BufferList = requireBuffer_list();
1155
+ var destroyImpl = destroy_1;
1156
+ var _require2 = state, getHighWaterMark2 = _require2.getHighWaterMark;
1157
+ var _require$codes = errorsBrowser.codes, ERR_INVALID_ARG_TYPE = _require$codes.ERR_INVALID_ARG_TYPE, ERR_STREAM_PUSH_AFTER_EOF = _require$codes.ERR_STREAM_PUSH_AFTER_EOF, ERR_METHOD_NOT_IMPLEMENTED = _require$codes.ERR_METHOD_NOT_IMPLEMENTED, ERR_STREAM_UNSHIFT_AFTER_END_EVENT = _require$codes.ERR_STREAM_UNSHIFT_AFTER_END_EVENT;
1158
+ var StringDecoder;
1159
+ var createReadableStreamAsyncIterator;
1160
+ var from;
1161
+ inherits_browserExports(Readable, Stream);
1162
+ var errorOrDestroy2 = destroyImpl.errorOrDestroy;
1163
+ var kProxyEvents = ["error", "close", "destroy", "pause", "resume"];
1164
+ function prependListener(emitter, event, fn) {
1165
+ if (typeof emitter.prependListener === "function") return emitter.prependListener(event, fn);
1166
+ if (!emitter._events || !emitter._events[event]) emitter.on(event, fn);
1167
+ else if (Array.isArray(emitter._events[event])) emitter._events[event].unshift(fn);
1168
+ else emitter._events[event] = [fn, emitter._events[event]];
1169
+ }
1170
+ function ReadableState(options, stream, isDuplex) {
1171
+ Duplex = Duplex || require_stream_duplex();
1172
+ options = options || {};
1173
+ if (typeof isDuplex !== "boolean") isDuplex = stream instanceof Duplex;
1174
+ this.objectMode = !!options.objectMode;
1175
+ if (isDuplex) this.objectMode = this.objectMode || !!options.readableObjectMode;
1176
+ this.highWaterMark = getHighWaterMark2(this, options, "readableHighWaterMark", isDuplex);
1177
+ this.buffer = new BufferList();
1178
+ this.length = 0;
1179
+ this.pipes = null;
1180
+ this.pipesCount = 0;
1181
+ this.flowing = null;
1182
+ this.ended = false;
1183
+ this.endEmitted = false;
1184
+ this.reading = false;
1185
+ this.sync = true;
1186
+ this.needReadable = false;
1187
+ this.emittedReadable = false;
1188
+ this.readableListening = false;
1189
+ this.resumeScheduled = false;
1190
+ this.paused = true;
1191
+ this.emitClose = options.emitClose !== false;
1192
+ this.autoDestroy = !!options.autoDestroy;
1193
+ this.destroyed = false;
1194
+ this.defaultEncoding = options.defaultEncoding || "utf8";
1195
+ this.awaitDrain = 0;
1196
+ this.readingMore = false;
1197
+ this.decoder = null;
1198
+ this.encoding = null;
1199
+ if (options.encoding) {
1200
+ if (!StringDecoder) StringDecoder = requireString_decoder().StringDecoder;
1201
+ this.decoder = new StringDecoder(options.encoding);
1202
+ this.encoding = options.encoding;
1203
+ }
1204
+ }
1205
+ function Readable(options) {
1206
+ Duplex = Duplex || require_stream_duplex();
1207
+ if (!(this instanceof Readable)) return new Readable(options);
1208
+ var isDuplex = this instanceof Duplex;
1209
+ this._readableState = new ReadableState(options, this, isDuplex);
1210
+ this.readable = true;
1211
+ if (options) {
1212
+ if (typeof options.read === "function") this._read = options.read;
1213
+ if (typeof options.destroy === "function") this._destroy = options.destroy;
1214
+ }
1215
+ Stream.call(this);
1216
+ }
1217
+ Object.defineProperty(Readable.prototype, "destroyed", {
1218
+ // making it explicit this property is not enumerable
1219
+ // because otherwise some prototype manipulation in
1220
+ // userland will fail
1221
+ enumerable: false,
1222
+ get: function get() {
1223
+ if (this._readableState === void 0) {
1224
+ return false;
1225
+ }
1226
+ return this._readableState.destroyed;
1227
+ },
1228
+ set: function set(value) {
1229
+ if (!this._readableState) {
1230
+ return;
1231
+ }
1232
+ this._readableState.destroyed = value;
1233
+ }
1234
+ });
1235
+ Readable.prototype.destroy = destroyImpl.destroy;
1236
+ Readable.prototype._undestroy = destroyImpl.undestroy;
1237
+ Readable.prototype._destroy = function(err, cb) {
1238
+ cb(err);
1239
+ };
1240
+ Readable.prototype.push = function(chunk, encoding) {
1241
+ var state2 = this._readableState;
1242
+ var skipChunkCheck;
1243
+ if (!state2.objectMode) {
1244
+ if (typeof chunk === "string") {
1245
+ encoding = encoding || state2.defaultEncoding;
1246
+ if (encoding !== state2.encoding) {
1247
+ chunk = Buffer2.from(chunk, encoding);
1248
+ encoding = "";
1249
+ }
1250
+ skipChunkCheck = true;
1251
+ }
1252
+ } else {
1253
+ skipChunkCheck = true;
1254
+ }
1255
+ return readableAddChunk(this, chunk, encoding, false, skipChunkCheck);
1256
+ };
1257
+ Readable.prototype.unshift = function(chunk) {
1258
+ return readableAddChunk(this, chunk, null, true, false);
1259
+ };
1260
+ function readableAddChunk(stream, chunk, encoding, addToFront, skipChunkCheck) {
1261
+ debug("readableAddChunk", chunk);
1262
+ var state2 = stream._readableState;
1263
+ if (chunk === null) {
1264
+ state2.reading = false;
1265
+ onEofChunk(stream, state2);
1266
+ } else {
1267
+ var er;
1268
+ if (!skipChunkCheck) er = chunkInvalid(state2, chunk);
1269
+ if (er) {
1270
+ errorOrDestroy2(stream, er);
1271
+ } else if (state2.objectMode || chunk && chunk.length > 0) {
1272
+ if (typeof chunk !== "string" && !state2.objectMode && Object.getPrototypeOf(chunk) !== Buffer2.prototype) {
1273
+ chunk = _uint8ArrayToBuffer(chunk);
1274
+ }
1275
+ if (addToFront) {
1276
+ if (state2.endEmitted) errorOrDestroy2(stream, new ERR_STREAM_UNSHIFT_AFTER_END_EVENT());
1277
+ else addChunk(stream, state2, chunk, true);
1278
+ } else if (state2.ended) {
1279
+ errorOrDestroy2(stream, new ERR_STREAM_PUSH_AFTER_EOF());
1280
+ } else if (state2.destroyed) {
1281
+ return false;
1282
+ } else {
1283
+ state2.reading = false;
1284
+ if (state2.decoder && !encoding) {
1285
+ chunk = state2.decoder.write(chunk);
1286
+ if (state2.objectMode || chunk.length !== 0) addChunk(stream, state2, chunk, false);
1287
+ else maybeReadMore(stream, state2);
1288
+ } else {
1289
+ addChunk(stream, state2, chunk, false);
1290
+ }
1291
+ }
1292
+ } else if (!addToFront) {
1293
+ state2.reading = false;
1294
+ maybeReadMore(stream, state2);
1295
+ }
1296
+ }
1297
+ return !state2.ended && (state2.length < state2.highWaterMark || state2.length === 0);
1298
+ }
1299
+ function addChunk(stream, state2, chunk, addToFront) {
1300
+ if (state2.flowing && state2.length === 0 && !state2.sync) {
1301
+ state2.awaitDrain = 0;
1302
+ stream.emit("data", chunk);
1303
+ } else {
1304
+ state2.length += state2.objectMode ? 1 : chunk.length;
1305
+ if (addToFront) state2.buffer.unshift(chunk);
1306
+ else state2.buffer.push(chunk);
1307
+ if (state2.needReadable) emitReadable(stream);
1308
+ }
1309
+ maybeReadMore(stream, state2);
1310
+ }
1311
+ function chunkInvalid(state2, chunk) {
1312
+ var er;
1313
+ if (!_isUint8Array(chunk) && typeof chunk !== "string" && chunk !== void 0 && !state2.objectMode) {
1314
+ er = new ERR_INVALID_ARG_TYPE("chunk", ["string", "Buffer", "Uint8Array"], chunk);
1315
+ }
1316
+ return er;
1317
+ }
1318
+ Readable.prototype.isPaused = function() {
1319
+ return this._readableState.flowing === false;
1320
+ };
1321
+ Readable.prototype.setEncoding = function(enc) {
1322
+ if (!StringDecoder) StringDecoder = requireString_decoder().StringDecoder;
1323
+ var decoder = new StringDecoder(enc);
1324
+ this._readableState.decoder = decoder;
1325
+ this._readableState.encoding = this._readableState.decoder.encoding;
1326
+ var p = this._readableState.buffer.head;
1327
+ var content = "";
1328
+ while (p !== null) {
1329
+ content += decoder.write(p.data);
1330
+ p = p.next;
1331
+ }
1332
+ this._readableState.buffer.clear();
1333
+ if (content !== "") this._readableState.buffer.push(content);
1334
+ this._readableState.length = content.length;
1335
+ return this;
1336
+ };
1337
+ var MAX_HWM = 1073741824;
1338
+ function computeNewHighWaterMark(n) {
1339
+ if (n >= MAX_HWM) {
1340
+ n = MAX_HWM;
1341
+ } else {
1342
+ n--;
1343
+ n |= n >>> 1;
1344
+ n |= n >>> 2;
1345
+ n |= n >>> 4;
1346
+ n |= n >>> 8;
1347
+ n |= n >>> 16;
1348
+ n++;
1349
+ }
1350
+ return n;
1351
+ }
1352
+ function howMuchToRead(n, state2) {
1353
+ if (n <= 0 || state2.length === 0 && state2.ended) return 0;
1354
+ if (state2.objectMode) return 1;
1355
+ if (n !== n) {
1356
+ if (state2.flowing && state2.length) return state2.buffer.head.data.length;
1357
+ else return state2.length;
1358
+ }
1359
+ if (n > state2.highWaterMark) state2.highWaterMark = computeNewHighWaterMark(n);
1360
+ if (n <= state2.length) return n;
1361
+ if (!state2.ended) {
1362
+ state2.needReadable = true;
1363
+ return 0;
1364
+ }
1365
+ return state2.length;
1366
+ }
1367
+ Readable.prototype.read = function(n) {
1368
+ debug("read", n);
1369
+ n = parseInt(n, 10);
1370
+ var state2 = this._readableState;
1371
+ var nOrig = n;
1372
+ if (n !== 0) state2.emittedReadable = false;
1373
+ if (n === 0 && state2.needReadable && ((state2.highWaterMark !== 0 ? state2.length >= state2.highWaterMark : state2.length > 0) || state2.ended)) {
1374
+ debug("read: emitReadable", state2.length, state2.ended);
1375
+ if (state2.length === 0 && state2.ended) endReadable(this);
1376
+ else emitReadable(this);
1377
+ return null;
1378
+ }
1379
+ n = howMuchToRead(n, state2);
1380
+ if (n === 0 && state2.ended) {
1381
+ if (state2.length === 0) endReadable(this);
1382
+ return null;
1383
+ }
1384
+ var doRead = state2.needReadable;
1385
+ debug("need readable", doRead);
1386
+ if (state2.length === 0 || state2.length - n < state2.highWaterMark) {
1387
+ doRead = true;
1388
+ debug("length less than watermark", doRead);
1389
+ }
1390
+ if (state2.ended || state2.reading) {
1391
+ doRead = false;
1392
+ debug("reading or ended", doRead);
1393
+ } else if (doRead) {
1394
+ debug("do read");
1395
+ state2.reading = true;
1396
+ state2.sync = true;
1397
+ if (state2.length === 0) state2.needReadable = true;
1398
+ this._read(state2.highWaterMark);
1399
+ state2.sync = false;
1400
+ if (!state2.reading) n = howMuchToRead(nOrig, state2);
1401
+ }
1402
+ var ret;
1403
+ if (n > 0) ret = fromList(n, state2);
1404
+ else ret = null;
1405
+ if (ret === null) {
1406
+ state2.needReadable = state2.length <= state2.highWaterMark;
1407
+ n = 0;
1408
+ } else {
1409
+ state2.length -= n;
1410
+ state2.awaitDrain = 0;
1411
+ }
1412
+ if (state2.length === 0) {
1413
+ if (!state2.ended) state2.needReadable = true;
1414
+ if (nOrig !== n && state2.ended) endReadable(this);
1415
+ }
1416
+ if (ret !== null) this.emit("data", ret);
1417
+ return ret;
1418
+ };
1419
+ function onEofChunk(stream, state2) {
1420
+ debug("onEofChunk");
1421
+ if (state2.ended) return;
1422
+ if (state2.decoder) {
1423
+ var chunk = state2.decoder.end();
1424
+ if (chunk && chunk.length) {
1425
+ state2.buffer.push(chunk);
1426
+ state2.length += state2.objectMode ? 1 : chunk.length;
1427
+ }
1428
+ }
1429
+ state2.ended = true;
1430
+ if (state2.sync) {
1431
+ emitReadable(stream);
1432
+ } else {
1433
+ state2.needReadable = false;
1434
+ if (!state2.emittedReadable) {
1435
+ state2.emittedReadable = true;
1436
+ emitReadable_(stream);
1437
+ }
1438
+ }
1439
+ }
1440
+ function emitReadable(stream) {
1441
+ var state2 = stream._readableState;
1442
+ debug("emitReadable", state2.needReadable, state2.emittedReadable);
1443
+ state2.needReadable = false;
1444
+ if (!state2.emittedReadable) {
1445
+ debug("emitReadable", state2.flowing);
1446
+ state2.emittedReadable = true;
1447
+ process.nextTick(emitReadable_, stream);
1448
+ }
1449
+ }
1450
+ function emitReadable_(stream) {
1451
+ var state2 = stream._readableState;
1452
+ debug("emitReadable_", state2.destroyed, state2.length, state2.ended);
1453
+ if (!state2.destroyed && (state2.length || state2.ended)) {
1454
+ stream.emit("readable");
1455
+ state2.emittedReadable = false;
1456
+ }
1457
+ state2.needReadable = !state2.flowing && !state2.ended && state2.length <= state2.highWaterMark;
1458
+ flow(stream);
1459
+ }
1460
+ function maybeReadMore(stream, state2) {
1461
+ if (!state2.readingMore) {
1462
+ state2.readingMore = true;
1463
+ process.nextTick(maybeReadMore_, stream, state2);
1464
+ }
1465
+ }
1466
+ function maybeReadMore_(stream, state2) {
1467
+ while (!state2.reading && !state2.ended && (state2.length < state2.highWaterMark || state2.flowing && state2.length === 0)) {
1468
+ var len = state2.length;
1469
+ debug("maybeReadMore read 0");
1470
+ stream.read(0);
1471
+ if (len === state2.length)
1472
+ break;
1473
+ }
1474
+ state2.readingMore = false;
1475
+ }
1476
+ Readable.prototype._read = function(n) {
1477
+ errorOrDestroy2(this, new ERR_METHOD_NOT_IMPLEMENTED("_read()"));
1478
+ };
1479
+ Readable.prototype.pipe = function(dest, pipeOpts) {
1480
+ var src = this;
1481
+ var state2 = this._readableState;
1482
+ switch (state2.pipesCount) {
1483
+ case 0:
1484
+ state2.pipes = dest;
1485
+ break;
1486
+ case 1:
1487
+ state2.pipes = [state2.pipes, dest];
1488
+ break;
1489
+ default:
1490
+ state2.pipes.push(dest);
1491
+ break;
1492
+ }
1493
+ state2.pipesCount += 1;
1494
+ debug("pipe count=%d opts=%j", state2.pipesCount, pipeOpts);
1495
+ var doEnd = (!pipeOpts || pipeOpts.end !== false) && dest !== process.stdout && dest !== process.stderr;
1496
+ var endFn = doEnd ? onend : unpipe;
1497
+ if (state2.endEmitted) process.nextTick(endFn);
1498
+ else src.once("end", endFn);
1499
+ dest.on("unpipe", onunpipe);
1500
+ function onunpipe(readable, unpipeInfo) {
1501
+ debug("onunpipe");
1502
+ if (readable === src) {
1503
+ if (unpipeInfo && unpipeInfo.hasUnpiped === false) {
1504
+ unpipeInfo.hasUnpiped = true;
1505
+ cleanup();
1506
+ }
1507
+ }
1508
+ }
1509
+ function onend() {
1510
+ debug("onend");
1511
+ dest.end();
1512
+ }
1513
+ var ondrain = pipeOnDrain(src);
1514
+ dest.on("drain", ondrain);
1515
+ var cleanedUp = false;
1516
+ function cleanup() {
1517
+ debug("cleanup");
1518
+ dest.removeListener("close", onclose);
1519
+ dest.removeListener("finish", onfinish);
1520
+ dest.removeListener("drain", ondrain);
1521
+ dest.removeListener("error", onerror);
1522
+ dest.removeListener("unpipe", onunpipe);
1523
+ src.removeListener("end", onend);
1524
+ src.removeListener("end", unpipe);
1525
+ src.removeListener("data", ondata);
1526
+ cleanedUp = true;
1527
+ if (state2.awaitDrain && (!dest._writableState || dest._writableState.needDrain)) ondrain();
1528
+ }
1529
+ src.on("data", ondata);
1530
+ function ondata(chunk) {
1531
+ debug("ondata");
1532
+ var ret = dest.write(chunk);
1533
+ debug("dest.write", ret);
1534
+ if (ret === false) {
1535
+ if ((state2.pipesCount === 1 && state2.pipes === dest || state2.pipesCount > 1 && indexOf(state2.pipes, dest) !== -1) && !cleanedUp) {
1536
+ debug("false write response, pause", state2.awaitDrain);
1537
+ state2.awaitDrain++;
1538
+ }
1539
+ src.pause();
1540
+ }
1541
+ }
1542
+ function onerror(er) {
1543
+ debug("onerror", er);
1544
+ unpipe();
1545
+ dest.removeListener("error", onerror);
1546
+ if (EElistenerCount(dest, "error") === 0) errorOrDestroy2(dest, er);
1547
+ }
1548
+ prependListener(dest, "error", onerror);
1549
+ function onclose() {
1550
+ dest.removeListener("finish", onfinish);
1551
+ unpipe();
1552
+ }
1553
+ dest.once("close", onclose);
1554
+ function onfinish() {
1555
+ debug("onfinish");
1556
+ dest.removeListener("close", onclose);
1557
+ unpipe();
1558
+ }
1559
+ dest.once("finish", onfinish);
1560
+ function unpipe() {
1561
+ debug("unpipe");
1562
+ src.unpipe(dest);
1563
+ }
1564
+ dest.emit("pipe", src);
1565
+ if (!state2.flowing) {
1566
+ debug("pipe resume");
1567
+ src.resume();
1568
+ }
1569
+ return dest;
1570
+ };
1571
+ function pipeOnDrain(src) {
1572
+ return function pipeOnDrainFunctionResult() {
1573
+ var state2 = src._readableState;
1574
+ debug("pipeOnDrain", state2.awaitDrain);
1575
+ if (state2.awaitDrain) state2.awaitDrain--;
1576
+ if (state2.awaitDrain === 0 && EElistenerCount(src, "data")) {
1577
+ state2.flowing = true;
1578
+ flow(src);
1579
+ }
1580
+ };
1581
+ }
1582
+ Readable.prototype.unpipe = function(dest) {
1583
+ var state2 = this._readableState;
1584
+ var unpipeInfo = {
1585
+ hasUnpiped: false
1586
+ };
1587
+ if (state2.pipesCount === 0) return this;
1588
+ if (state2.pipesCount === 1) {
1589
+ if (dest && dest !== state2.pipes) return this;
1590
+ if (!dest) dest = state2.pipes;
1591
+ state2.pipes = null;
1592
+ state2.pipesCount = 0;
1593
+ state2.flowing = false;
1594
+ if (dest) dest.emit("unpipe", this, unpipeInfo);
1595
+ return this;
1596
+ }
1597
+ if (!dest) {
1598
+ var dests = state2.pipes;
1599
+ var len = state2.pipesCount;
1600
+ state2.pipes = null;
1601
+ state2.pipesCount = 0;
1602
+ state2.flowing = false;
1603
+ for (var i = 0; i < len; i++) dests[i].emit("unpipe", this, {
1604
+ hasUnpiped: false
1605
+ });
1606
+ return this;
1607
+ }
1608
+ var index = indexOf(state2.pipes, dest);
1609
+ if (index === -1) return this;
1610
+ state2.pipes.splice(index, 1);
1611
+ state2.pipesCount -= 1;
1612
+ if (state2.pipesCount === 1) state2.pipes = state2.pipes[0];
1613
+ dest.emit("unpipe", this, unpipeInfo);
1614
+ return this;
1615
+ };
1616
+ Readable.prototype.on = function(ev, fn) {
1617
+ var res = Stream.prototype.on.call(this, ev, fn);
1618
+ var state2 = this._readableState;
1619
+ if (ev === "data") {
1620
+ state2.readableListening = this.listenerCount("readable") > 0;
1621
+ if (state2.flowing !== false) this.resume();
1622
+ } else if (ev === "readable") {
1623
+ if (!state2.endEmitted && !state2.readableListening) {
1624
+ state2.readableListening = state2.needReadable = true;
1625
+ state2.flowing = false;
1626
+ state2.emittedReadable = false;
1627
+ debug("on readable", state2.length, state2.reading);
1628
+ if (state2.length) {
1629
+ emitReadable(this);
1630
+ } else if (!state2.reading) {
1631
+ process.nextTick(nReadingNextTick, this);
1632
+ }
1633
+ }
1634
+ }
1635
+ return res;
1636
+ };
1637
+ Readable.prototype.addListener = Readable.prototype.on;
1638
+ Readable.prototype.removeListener = function(ev, fn) {
1639
+ var res = Stream.prototype.removeListener.call(this, ev, fn);
1640
+ if (ev === "readable") {
1641
+ process.nextTick(updateReadableListening, this);
1642
+ }
1643
+ return res;
1644
+ };
1645
+ Readable.prototype.removeAllListeners = function(ev) {
1646
+ var res = Stream.prototype.removeAllListeners.apply(this, arguments);
1647
+ if (ev === "readable" || ev === void 0) {
1648
+ process.nextTick(updateReadableListening, this);
1649
+ }
1650
+ return res;
1651
+ };
1652
+ function updateReadableListening(self2) {
1653
+ var state2 = self2._readableState;
1654
+ state2.readableListening = self2.listenerCount("readable") > 0;
1655
+ if (state2.resumeScheduled && !state2.paused) {
1656
+ state2.flowing = true;
1657
+ } else if (self2.listenerCount("data") > 0) {
1658
+ self2.resume();
1659
+ }
1660
+ }
1661
+ function nReadingNextTick(self2) {
1662
+ debug("readable nexttick read 0");
1663
+ self2.read(0);
1664
+ }
1665
+ Readable.prototype.resume = function() {
1666
+ var state2 = this._readableState;
1667
+ if (!state2.flowing) {
1668
+ debug("resume");
1669
+ state2.flowing = !state2.readableListening;
1670
+ resume(this, state2);
1671
+ }
1672
+ state2.paused = false;
1673
+ return this;
1674
+ };
1675
+ function resume(stream, state2) {
1676
+ if (!state2.resumeScheduled) {
1677
+ state2.resumeScheduled = true;
1678
+ process.nextTick(resume_, stream, state2);
1679
+ }
1680
+ }
1681
+ function resume_(stream, state2) {
1682
+ debug("resume", state2.reading);
1683
+ if (!state2.reading) {
1684
+ stream.read(0);
1685
+ }
1686
+ state2.resumeScheduled = false;
1687
+ stream.emit("resume");
1688
+ flow(stream);
1689
+ if (state2.flowing && !state2.reading) stream.read(0);
1690
+ }
1691
+ Readable.prototype.pause = function() {
1692
+ debug("call pause flowing=%j", this._readableState.flowing);
1693
+ if (this._readableState.flowing !== false) {
1694
+ debug("pause");
1695
+ this._readableState.flowing = false;
1696
+ this.emit("pause");
1697
+ }
1698
+ this._readableState.paused = true;
1699
+ return this;
1700
+ };
1701
+ function flow(stream) {
1702
+ var state2 = stream._readableState;
1703
+ debug("flow", state2.flowing);
1704
+ while (state2.flowing && stream.read() !== null) ;
1705
+ }
1706
+ Readable.prototype.wrap = function(stream) {
1707
+ var _this = this;
1708
+ var state2 = this._readableState;
1709
+ var paused = false;
1710
+ stream.on("end", function() {
1711
+ debug("wrapped end");
1712
+ if (state2.decoder && !state2.ended) {
1713
+ var chunk = state2.decoder.end();
1714
+ if (chunk && chunk.length) _this.push(chunk);
1715
+ }
1716
+ _this.push(null);
1717
+ });
1718
+ stream.on("data", function(chunk) {
1719
+ debug("wrapped data");
1720
+ if (state2.decoder) chunk = state2.decoder.write(chunk);
1721
+ if (state2.objectMode && (chunk === null || chunk === void 0)) return;
1722
+ else if (!state2.objectMode && (!chunk || !chunk.length)) return;
1723
+ var ret = _this.push(chunk);
1724
+ if (!ret) {
1725
+ paused = true;
1726
+ stream.pause();
1727
+ }
1728
+ });
1729
+ for (var i in stream) {
1730
+ if (this[i] === void 0 && typeof stream[i] === "function") {
1731
+ this[i] = /* @__PURE__ */ function methodWrap(method) {
1732
+ return function methodWrapReturnFunction() {
1733
+ return stream[method].apply(stream, arguments);
1734
+ };
1735
+ }(i);
1736
+ }
1737
+ }
1738
+ for (var n = 0; n < kProxyEvents.length; n++) {
1739
+ stream.on(kProxyEvents[n], this.emit.bind(this, kProxyEvents[n]));
1740
+ }
1741
+ this._read = function(n2) {
1742
+ debug("wrapped _read", n2);
1743
+ if (paused) {
1744
+ paused = false;
1745
+ stream.resume();
1746
+ }
1747
+ };
1748
+ return this;
1749
+ };
1750
+ if (typeof Symbol === "function") {
1751
+ Readable.prototype[Symbol.asyncIterator] = function() {
1752
+ if (createReadableStreamAsyncIterator === void 0) {
1753
+ createReadableStreamAsyncIterator = requireAsync_iterator();
1754
+ }
1755
+ return createReadableStreamAsyncIterator(this);
1756
+ };
1757
+ }
1758
+ Object.defineProperty(Readable.prototype, "readableHighWaterMark", {
1759
+ // making it explicit this property is not enumerable
1760
+ // because otherwise some prototype manipulation in
1761
+ // userland will fail
1762
+ enumerable: false,
1763
+ get: function get() {
1764
+ return this._readableState.highWaterMark;
1765
+ }
1766
+ });
1767
+ Object.defineProperty(Readable.prototype, "readableBuffer", {
1768
+ // making it explicit this property is not enumerable
1769
+ // because otherwise some prototype manipulation in
1770
+ // userland will fail
1771
+ enumerable: false,
1772
+ get: function get() {
1773
+ return this._readableState && this._readableState.buffer;
1774
+ }
1775
+ });
1776
+ Object.defineProperty(Readable.prototype, "readableFlowing", {
1777
+ // making it explicit this property is not enumerable
1778
+ // because otherwise some prototype manipulation in
1779
+ // userland will fail
1780
+ enumerable: false,
1781
+ get: function get() {
1782
+ return this._readableState.flowing;
1783
+ },
1784
+ set: function set(state2) {
1785
+ if (this._readableState) {
1786
+ this._readableState.flowing = state2;
1787
+ }
1788
+ }
1789
+ });
1790
+ Readable._fromList = fromList;
1791
+ Object.defineProperty(Readable.prototype, "readableLength", {
1792
+ // making it explicit this property is not enumerable
1793
+ // because otherwise some prototype manipulation in
1794
+ // userland will fail
1795
+ enumerable: false,
1796
+ get: function get() {
1797
+ return this._readableState.length;
1798
+ }
1799
+ });
1800
+ function fromList(n, state2) {
1801
+ if (state2.length === 0) return null;
1802
+ var ret;
1803
+ if (state2.objectMode) ret = state2.buffer.shift();
1804
+ else if (!n || n >= state2.length) {
1805
+ if (state2.decoder) ret = state2.buffer.join("");
1806
+ else if (state2.buffer.length === 1) ret = state2.buffer.first();
1807
+ else ret = state2.buffer.concat(state2.length);
1808
+ state2.buffer.clear();
1809
+ } else {
1810
+ ret = state2.buffer.consume(n, state2.decoder);
1811
+ }
1812
+ return ret;
1813
+ }
1814
+ function endReadable(stream) {
1815
+ var state2 = stream._readableState;
1816
+ debug("endReadable", state2.endEmitted);
1817
+ if (!state2.endEmitted) {
1818
+ state2.ended = true;
1819
+ process.nextTick(endReadableNT, state2, stream);
1820
+ }
1821
+ }
1822
+ function endReadableNT(state2, stream) {
1823
+ debug("endReadableNT", state2.endEmitted, state2.length);
1824
+ if (!state2.endEmitted && state2.length === 0) {
1825
+ state2.endEmitted = true;
1826
+ stream.readable = false;
1827
+ stream.emit("end");
1828
+ if (state2.autoDestroy) {
1829
+ var wState = stream._writableState;
1830
+ if (!wState || wState.autoDestroy && wState.finished) {
1831
+ stream.destroy();
1832
+ }
1833
+ }
1834
+ }
1835
+ }
1836
+ if (typeof Symbol === "function") {
1837
+ Readable.from = function(iterable, opts) {
1838
+ if (from === void 0) {
1839
+ from = requireFromBrowser();
1840
+ }
1841
+ return from(Readable, iterable, opts);
1842
+ };
1843
+ }
1844
+ function indexOf(xs, x) {
1845
+ for (var i = 0, l = xs.length; i < l; i++) {
1846
+ if (xs[i] === x) return i;
1847
+ }
1848
+ return -1;
1849
+ }
1850
+ return _stream_readable;
1851
+ }
1852
+ var _stream_duplex;
1853
+ var hasRequired_stream_duplex;
1854
+ function require_stream_duplex() {
1855
+ if (hasRequired_stream_duplex) return _stream_duplex;
1856
+ hasRequired_stream_duplex = 1;
1857
+ var objectKeys = Object.keys || function(obj) {
1858
+ var keys2 = [];
1859
+ for (var key in obj) keys2.push(key);
1860
+ return keys2;
1861
+ };
1862
+ _stream_duplex = Duplex;
1863
+ var Readable = require_stream_readable();
1864
+ var Writable2 = require_stream_writable();
1865
+ inherits_browserExports(Duplex, Readable);
1866
+ {
1867
+ var keys = objectKeys(Writable2.prototype);
1868
+ for (var v = 0; v < keys.length; v++) {
1869
+ var method = keys[v];
1870
+ if (!Duplex.prototype[method]) Duplex.prototype[method] = Writable2.prototype[method];
1871
+ }
1872
+ }
1873
+ function Duplex(options) {
1874
+ if (!(this instanceof Duplex)) return new Duplex(options);
1875
+ Readable.call(this, options);
1876
+ Writable2.call(this, options);
1877
+ this.allowHalfOpen = true;
1878
+ if (options) {
1879
+ if (options.readable === false) this.readable = false;
1880
+ if (options.writable === false) this.writable = false;
1881
+ if (options.allowHalfOpen === false) {
1882
+ this.allowHalfOpen = false;
1883
+ this.once("end", onend);
1884
+ }
1885
+ }
1886
+ }
1887
+ Object.defineProperty(Duplex.prototype, "writableHighWaterMark", {
1888
+ // making it explicit this property is not enumerable
1889
+ // because otherwise some prototype manipulation in
1890
+ // userland will fail
1891
+ enumerable: false,
1892
+ get: function get() {
1893
+ return this._writableState.highWaterMark;
1894
+ }
1895
+ });
1896
+ Object.defineProperty(Duplex.prototype, "writableBuffer", {
1897
+ // making it explicit this property is not enumerable
1898
+ // because otherwise some prototype manipulation in
1899
+ // userland will fail
1900
+ enumerable: false,
1901
+ get: function get() {
1902
+ return this._writableState && this._writableState.getBuffer();
1903
+ }
1904
+ });
1905
+ Object.defineProperty(Duplex.prototype, "writableLength", {
1906
+ // making it explicit this property is not enumerable
1907
+ // because otherwise some prototype manipulation in
1908
+ // userland will fail
1909
+ enumerable: false,
1910
+ get: function get() {
1911
+ return this._writableState.length;
1912
+ }
1913
+ });
1914
+ function onend() {
1915
+ if (this._writableState.ended) return;
1916
+ process.nextTick(onEndNT, this);
1917
+ }
1918
+ function onEndNT(self2) {
1919
+ self2.end();
1920
+ }
1921
+ Object.defineProperty(Duplex.prototype, "destroyed", {
1922
+ // making it explicit this property is not enumerable
1923
+ // because otherwise some prototype manipulation in
1924
+ // userland will fail
1925
+ enumerable: false,
1926
+ get: function get() {
1927
+ if (this._readableState === void 0 || this._writableState === void 0) {
1928
+ return false;
1929
+ }
1930
+ return this._readableState.destroyed && this._writableState.destroyed;
1931
+ },
1932
+ set: function set(value) {
1933
+ if (this._readableState === void 0 || this._writableState === void 0) {
1934
+ return;
1935
+ }
1936
+ this._readableState.destroyed = value;
1937
+ this._writableState.destroyed = value;
1938
+ }
1939
+ });
1940
+ return _stream_duplex;
1941
+ }
1942
+ var _stream_writable;
1943
+ var hasRequired_stream_writable;
1944
+ function require_stream_writable() {
1945
+ if (hasRequired_stream_writable) return _stream_writable;
1946
+ hasRequired_stream_writable = 1;
1947
+ _stream_writable = Writable2;
1948
+ function CorkedRequest(state2) {
1949
+ var _this = this;
1950
+ this.next = null;
1951
+ this.entry = null;
1952
+ this.finish = function() {
1953
+ onCorkedFinish(_this, state2);
1954
+ };
1955
+ }
1956
+ var Duplex;
1957
+ Writable2.WritableState = WritableState;
1958
+ var internalUtil = {
1959
+ deprecate: browser
1960
+ };
1961
+ var Stream = streamBrowser;
1962
+ var Buffer2 = require$$2.Buffer;
1963
+ var OurUint8Array = (typeof commonjsGlobal !== "undefined" ? commonjsGlobal : typeof window !== "undefined" ? window : typeof self !== "undefined" ? self : {}).Uint8Array || function() {
1964
+ };
1965
+ function _uint8ArrayToBuffer(chunk) {
1966
+ return Buffer2.from(chunk);
1967
+ }
1968
+ function _isUint8Array(obj) {
1969
+ return Buffer2.isBuffer(obj) || obj instanceof OurUint8Array;
1970
+ }
1971
+ var destroyImpl = destroy_1;
1972
+ var _require2 = state, getHighWaterMark2 = _require2.getHighWaterMark;
1973
+ var _require$codes = errorsBrowser.codes, ERR_INVALID_ARG_TYPE = _require$codes.ERR_INVALID_ARG_TYPE, ERR_METHOD_NOT_IMPLEMENTED = _require$codes.ERR_METHOD_NOT_IMPLEMENTED, ERR_MULTIPLE_CALLBACK = _require$codes.ERR_MULTIPLE_CALLBACK, ERR_STREAM_CANNOT_PIPE = _require$codes.ERR_STREAM_CANNOT_PIPE, ERR_STREAM_DESTROYED = _require$codes.ERR_STREAM_DESTROYED, ERR_STREAM_NULL_VALUES = _require$codes.ERR_STREAM_NULL_VALUES, ERR_STREAM_WRITE_AFTER_END = _require$codes.ERR_STREAM_WRITE_AFTER_END, ERR_UNKNOWN_ENCODING = _require$codes.ERR_UNKNOWN_ENCODING;
1974
+ var errorOrDestroy2 = destroyImpl.errorOrDestroy;
1975
+ inherits_browserExports(Writable2, Stream);
1976
+ function nop() {
1977
+ }
1978
+ function WritableState(options, stream, isDuplex) {
1979
+ Duplex = Duplex || require_stream_duplex();
1980
+ options = options || {};
1981
+ if (typeof isDuplex !== "boolean") isDuplex = stream instanceof Duplex;
1982
+ this.objectMode = !!options.objectMode;
1983
+ if (isDuplex) this.objectMode = this.objectMode || !!options.writableObjectMode;
1984
+ this.highWaterMark = getHighWaterMark2(this, options, "writableHighWaterMark", isDuplex);
1985
+ this.finalCalled = false;
1986
+ this.needDrain = false;
1987
+ this.ending = false;
1988
+ this.ended = false;
1989
+ this.finished = false;
1990
+ this.destroyed = false;
1991
+ var noDecode = options.decodeStrings === false;
1992
+ this.decodeStrings = !noDecode;
1993
+ this.defaultEncoding = options.defaultEncoding || "utf8";
1994
+ this.length = 0;
1995
+ this.writing = false;
1996
+ this.corked = 0;
1997
+ this.sync = true;
1998
+ this.bufferProcessing = false;
1999
+ this.onwrite = function(er) {
2000
+ onwrite(stream, er);
2001
+ };
2002
+ this.writecb = null;
2003
+ this.writelen = 0;
2004
+ this.bufferedRequest = null;
2005
+ this.lastBufferedRequest = null;
2006
+ this.pendingcb = 0;
2007
+ this.prefinished = false;
2008
+ this.errorEmitted = false;
2009
+ this.emitClose = options.emitClose !== false;
2010
+ this.autoDestroy = !!options.autoDestroy;
2011
+ this.bufferedRequestCount = 0;
2012
+ this.corkedRequestsFree = new CorkedRequest(this);
2013
+ }
2014
+ WritableState.prototype.getBuffer = function getBuffer() {
2015
+ var current = this.bufferedRequest;
2016
+ var out = [];
2017
+ while (current) {
2018
+ out.push(current);
2019
+ current = current.next;
2020
+ }
2021
+ return out;
2022
+ };
2023
+ (function() {
2024
+ try {
2025
+ Object.defineProperty(WritableState.prototype, "buffer", {
2026
+ get: internalUtil.deprecate(function writableStateBufferGetter() {
2027
+ return this.getBuffer();
2028
+ }, "_writableState.buffer is deprecated. Use _writableState.getBuffer instead.", "DEP0003")
2029
+ });
2030
+ } catch (_) {
2031
+ }
2032
+ })();
2033
+ var realHasInstance;
2034
+ if (typeof Symbol === "function" && Symbol.hasInstance && typeof Function.prototype[Symbol.hasInstance] === "function") {
2035
+ realHasInstance = Function.prototype[Symbol.hasInstance];
2036
+ Object.defineProperty(Writable2, Symbol.hasInstance, {
2037
+ value: function value(object2) {
2038
+ if (realHasInstance.call(this, object2)) return true;
2039
+ if (this !== Writable2) return false;
2040
+ return object2 && object2._writableState instanceof WritableState;
2041
+ }
2042
+ });
2043
+ } else {
2044
+ realHasInstance = function realHasInstance2(object2) {
2045
+ return object2 instanceof this;
2046
+ };
2047
+ }
2048
+ function Writable2(options) {
2049
+ Duplex = Duplex || require_stream_duplex();
2050
+ var isDuplex = this instanceof Duplex;
2051
+ if (!isDuplex && !realHasInstance.call(Writable2, this)) return new Writable2(options);
2052
+ this._writableState = new WritableState(options, this, isDuplex);
2053
+ this.writable = true;
2054
+ if (options) {
2055
+ if (typeof options.write === "function") this._write = options.write;
2056
+ if (typeof options.writev === "function") this._writev = options.writev;
2057
+ if (typeof options.destroy === "function") this._destroy = options.destroy;
2058
+ if (typeof options.final === "function") this._final = options.final;
2059
+ }
2060
+ Stream.call(this);
2061
+ }
2062
+ Writable2.prototype.pipe = function() {
2063
+ errorOrDestroy2(this, new ERR_STREAM_CANNOT_PIPE());
2064
+ };
2065
+ function writeAfterEnd(stream, cb) {
2066
+ var er = new ERR_STREAM_WRITE_AFTER_END();
2067
+ errorOrDestroy2(stream, er);
2068
+ process.nextTick(cb, er);
2069
+ }
2070
+ function validChunk(stream, state2, chunk, cb) {
2071
+ var er;
2072
+ if (chunk === null) {
2073
+ er = new ERR_STREAM_NULL_VALUES();
2074
+ } else if (typeof chunk !== "string" && !state2.objectMode) {
2075
+ er = new ERR_INVALID_ARG_TYPE("chunk", ["string", "Buffer"], chunk);
2076
+ }
2077
+ if (er) {
2078
+ errorOrDestroy2(stream, er);
2079
+ process.nextTick(cb, er);
2080
+ return false;
2081
+ }
2082
+ return true;
2083
+ }
2084
+ Writable2.prototype.write = function(chunk, encoding, cb) {
2085
+ var state2 = this._writableState;
2086
+ var ret = false;
2087
+ var isBuf = !state2.objectMode && _isUint8Array(chunk);
2088
+ if (isBuf && !Buffer2.isBuffer(chunk)) {
2089
+ chunk = _uint8ArrayToBuffer(chunk);
2090
+ }
2091
+ if (typeof encoding === "function") {
2092
+ cb = encoding;
2093
+ encoding = null;
2094
+ }
2095
+ if (isBuf) encoding = "buffer";
2096
+ else if (!encoding) encoding = state2.defaultEncoding;
2097
+ if (typeof cb !== "function") cb = nop;
2098
+ if (state2.ending) writeAfterEnd(this, cb);
2099
+ else if (isBuf || validChunk(this, state2, chunk, cb)) {
2100
+ state2.pendingcb++;
2101
+ ret = writeOrBuffer(this, state2, isBuf, chunk, encoding, cb);
2102
+ }
2103
+ return ret;
2104
+ };
2105
+ Writable2.prototype.cork = function() {
2106
+ this._writableState.corked++;
2107
+ };
2108
+ Writable2.prototype.uncork = function() {
2109
+ var state2 = this._writableState;
2110
+ if (state2.corked) {
2111
+ state2.corked--;
2112
+ if (!state2.writing && !state2.corked && !state2.bufferProcessing && state2.bufferedRequest) clearBuffer(this, state2);
2113
+ }
2114
+ };
2115
+ Writable2.prototype.setDefaultEncoding = function setDefaultEncoding(encoding) {
2116
+ if (typeof encoding === "string") encoding = encoding.toLowerCase();
2117
+ if (!(["hex", "utf8", "utf-8", "ascii", "binary", "base64", "ucs2", "ucs-2", "utf16le", "utf-16le", "raw"].indexOf((encoding + "").toLowerCase()) > -1)) throw new ERR_UNKNOWN_ENCODING(encoding);
2118
+ this._writableState.defaultEncoding = encoding;
2119
+ return this;
2120
+ };
2121
+ Object.defineProperty(Writable2.prototype, "writableBuffer", {
2122
+ // making it explicit this property is not enumerable
2123
+ // because otherwise some prototype manipulation in
2124
+ // userland will fail
2125
+ enumerable: false,
2126
+ get: function get() {
2127
+ return this._writableState && this._writableState.getBuffer();
2128
+ }
2129
+ });
2130
+ function decodeChunk(state2, chunk, encoding) {
2131
+ if (!state2.objectMode && state2.decodeStrings !== false && typeof chunk === "string") {
2132
+ chunk = Buffer2.from(chunk, encoding);
2133
+ }
2134
+ return chunk;
2135
+ }
2136
+ Object.defineProperty(Writable2.prototype, "writableHighWaterMark", {
2137
+ // making it explicit this property is not enumerable
2138
+ // because otherwise some prototype manipulation in
2139
+ // userland will fail
2140
+ enumerable: false,
2141
+ get: function get() {
2142
+ return this._writableState.highWaterMark;
2143
+ }
2144
+ });
2145
+ function writeOrBuffer(stream, state2, isBuf, chunk, encoding, cb) {
2146
+ if (!isBuf) {
2147
+ var newChunk = decodeChunk(state2, chunk, encoding);
2148
+ if (chunk !== newChunk) {
2149
+ isBuf = true;
2150
+ encoding = "buffer";
2151
+ chunk = newChunk;
2152
+ }
2153
+ }
2154
+ var len = state2.objectMode ? 1 : chunk.length;
2155
+ state2.length += len;
2156
+ var ret = state2.length < state2.highWaterMark;
2157
+ if (!ret) state2.needDrain = true;
2158
+ if (state2.writing || state2.corked) {
2159
+ var last = state2.lastBufferedRequest;
2160
+ state2.lastBufferedRequest = {
2161
+ chunk,
2162
+ encoding,
2163
+ isBuf,
2164
+ callback: cb,
2165
+ next: null
2166
+ };
2167
+ if (last) {
2168
+ last.next = state2.lastBufferedRequest;
2169
+ } else {
2170
+ state2.bufferedRequest = state2.lastBufferedRequest;
2171
+ }
2172
+ state2.bufferedRequestCount += 1;
2173
+ } else {
2174
+ doWrite(stream, state2, false, len, chunk, encoding, cb);
2175
+ }
2176
+ return ret;
2177
+ }
2178
+ function doWrite(stream, state2, writev, len, chunk, encoding, cb) {
2179
+ state2.writelen = len;
2180
+ state2.writecb = cb;
2181
+ state2.writing = true;
2182
+ state2.sync = true;
2183
+ if (state2.destroyed) state2.onwrite(new ERR_STREAM_DESTROYED("write"));
2184
+ else if (writev) stream._writev(chunk, state2.onwrite);
2185
+ else stream._write(chunk, encoding, state2.onwrite);
2186
+ state2.sync = false;
2187
+ }
2188
+ function onwriteError(stream, state2, sync, er, cb) {
2189
+ --state2.pendingcb;
2190
+ if (sync) {
2191
+ process.nextTick(cb, er);
2192
+ process.nextTick(finishMaybe, stream, state2);
2193
+ stream._writableState.errorEmitted = true;
2194
+ errorOrDestroy2(stream, er);
2195
+ } else {
2196
+ cb(er);
2197
+ stream._writableState.errorEmitted = true;
2198
+ errorOrDestroy2(stream, er);
2199
+ finishMaybe(stream, state2);
2200
+ }
2201
+ }
2202
+ function onwriteStateUpdate(state2) {
2203
+ state2.writing = false;
2204
+ state2.writecb = null;
2205
+ state2.length -= state2.writelen;
2206
+ state2.writelen = 0;
2207
+ }
2208
+ function onwrite(stream, er) {
2209
+ var state2 = stream._writableState;
2210
+ var sync = state2.sync;
2211
+ var cb = state2.writecb;
2212
+ if (typeof cb !== "function") throw new ERR_MULTIPLE_CALLBACK();
2213
+ onwriteStateUpdate(state2);
2214
+ if (er) onwriteError(stream, state2, sync, er, cb);
2215
+ else {
2216
+ var finished = needFinish(state2) || stream.destroyed;
2217
+ if (!finished && !state2.corked && !state2.bufferProcessing && state2.bufferedRequest) {
2218
+ clearBuffer(stream, state2);
2219
+ }
2220
+ if (sync) {
2221
+ process.nextTick(afterWrite, stream, state2, finished, cb);
2222
+ } else {
2223
+ afterWrite(stream, state2, finished, cb);
2224
+ }
2225
+ }
2226
+ }
2227
+ function afterWrite(stream, state2, finished, cb) {
2228
+ if (!finished) onwriteDrain(stream, state2);
2229
+ state2.pendingcb--;
2230
+ cb();
2231
+ finishMaybe(stream, state2);
2232
+ }
2233
+ function onwriteDrain(stream, state2) {
2234
+ if (state2.length === 0 && state2.needDrain) {
2235
+ state2.needDrain = false;
2236
+ stream.emit("drain");
2237
+ }
2238
+ }
2239
+ function clearBuffer(stream, state2) {
2240
+ state2.bufferProcessing = true;
2241
+ var entry = state2.bufferedRequest;
2242
+ if (stream._writev && entry && entry.next) {
2243
+ var l = state2.bufferedRequestCount;
2244
+ var buffer = new Array(l);
2245
+ var holder = state2.corkedRequestsFree;
2246
+ holder.entry = entry;
2247
+ var count = 0;
2248
+ var allBuffers = true;
2249
+ while (entry) {
2250
+ buffer[count] = entry;
2251
+ if (!entry.isBuf) allBuffers = false;
2252
+ entry = entry.next;
2253
+ count += 1;
2254
+ }
2255
+ buffer.allBuffers = allBuffers;
2256
+ doWrite(stream, state2, true, state2.length, buffer, "", holder.finish);
2257
+ state2.pendingcb++;
2258
+ state2.lastBufferedRequest = null;
2259
+ if (holder.next) {
2260
+ state2.corkedRequestsFree = holder.next;
2261
+ holder.next = null;
2262
+ } else {
2263
+ state2.corkedRequestsFree = new CorkedRequest(state2);
2264
+ }
2265
+ state2.bufferedRequestCount = 0;
2266
+ } else {
2267
+ while (entry) {
2268
+ var chunk = entry.chunk;
2269
+ var encoding = entry.encoding;
2270
+ var cb = entry.callback;
2271
+ var len = state2.objectMode ? 1 : chunk.length;
2272
+ doWrite(stream, state2, false, len, chunk, encoding, cb);
2273
+ entry = entry.next;
2274
+ state2.bufferedRequestCount--;
2275
+ if (state2.writing) {
2276
+ break;
2277
+ }
2278
+ }
2279
+ if (entry === null) state2.lastBufferedRequest = null;
2280
+ }
2281
+ state2.bufferedRequest = entry;
2282
+ state2.bufferProcessing = false;
2283
+ }
2284
+ Writable2.prototype._write = function(chunk, encoding, cb) {
2285
+ cb(new ERR_METHOD_NOT_IMPLEMENTED("_write()"));
2286
+ };
2287
+ Writable2.prototype._writev = null;
2288
+ Writable2.prototype.end = function(chunk, encoding, cb) {
2289
+ var state2 = this._writableState;
2290
+ if (typeof chunk === "function") {
2291
+ cb = chunk;
2292
+ chunk = null;
2293
+ encoding = null;
2294
+ } else if (typeof encoding === "function") {
2295
+ cb = encoding;
2296
+ encoding = null;
2297
+ }
2298
+ if (chunk !== null && chunk !== void 0) this.write(chunk, encoding);
2299
+ if (state2.corked) {
2300
+ state2.corked = 1;
2301
+ this.uncork();
2302
+ }
2303
+ if (!state2.ending) endWritable(this, state2, cb);
2304
+ return this;
2305
+ };
2306
+ Object.defineProperty(Writable2.prototype, "writableLength", {
2307
+ // making it explicit this property is not enumerable
2308
+ // because otherwise some prototype manipulation in
2309
+ // userland will fail
2310
+ enumerable: false,
2311
+ get: function get() {
2312
+ return this._writableState.length;
2313
+ }
2314
+ });
2315
+ function needFinish(state2) {
2316
+ return state2.ending && state2.length === 0 && state2.bufferedRequest === null && !state2.finished && !state2.writing;
2317
+ }
2318
+ function callFinal(stream, state2) {
2319
+ stream._final(function(err) {
2320
+ state2.pendingcb--;
2321
+ if (err) {
2322
+ errorOrDestroy2(stream, err);
2323
+ }
2324
+ state2.prefinished = true;
2325
+ stream.emit("prefinish");
2326
+ finishMaybe(stream, state2);
2327
+ });
2328
+ }
2329
+ function prefinish(stream, state2) {
2330
+ if (!state2.prefinished && !state2.finalCalled) {
2331
+ if (typeof stream._final === "function" && !state2.destroyed) {
2332
+ state2.pendingcb++;
2333
+ state2.finalCalled = true;
2334
+ process.nextTick(callFinal, stream, state2);
2335
+ } else {
2336
+ state2.prefinished = true;
2337
+ stream.emit("prefinish");
2338
+ }
2339
+ }
2340
+ }
2341
+ function finishMaybe(stream, state2) {
2342
+ var need = needFinish(state2);
2343
+ if (need) {
2344
+ prefinish(stream, state2);
2345
+ if (state2.pendingcb === 0) {
2346
+ state2.finished = true;
2347
+ stream.emit("finish");
2348
+ if (state2.autoDestroy) {
2349
+ var rState = stream._readableState;
2350
+ if (!rState || rState.autoDestroy && rState.endEmitted) {
2351
+ stream.destroy();
2352
+ }
2353
+ }
2354
+ }
2355
+ }
2356
+ return need;
2357
+ }
2358
+ function endWritable(stream, state2, cb) {
2359
+ state2.ending = true;
2360
+ finishMaybe(stream, state2);
2361
+ if (cb) {
2362
+ if (state2.finished) process.nextTick(cb);
2363
+ else stream.once("finish", cb);
2364
+ }
2365
+ state2.ended = true;
2366
+ stream.writable = false;
2367
+ }
2368
+ function onCorkedFinish(corkReq, state2, err) {
2369
+ var entry = corkReq.entry;
2370
+ corkReq.entry = null;
2371
+ while (entry) {
2372
+ var cb = entry.callback;
2373
+ state2.pendingcb--;
2374
+ cb(err);
2375
+ entry = entry.next;
2376
+ }
2377
+ state2.corkedRequestsFree.next = corkReq;
2378
+ }
2379
+ Object.defineProperty(Writable2.prototype, "destroyed", {
2380
+ // making it explicit this property is not enumerable
2381
+ // because otherwise some prototype manipulation in
2382
+ // userland will fail
2383
+ enumerable: false,
2384
+ get: function get() {
2385
+ if (this._writableState === void 0) {
2386
+ return false;
2387
+ }
2388
+ return this._writableState.destroyed;
2389
+ },
2390
+ set: function set(value) {
2391
+ if (!this._writableState) {
2392
+ return;
2393
+ }
2394
+ this._writableState.destroyed = value;
2395
+ }
2396
+ });
2397
+ Writable2.prototype.destroy = destroyImpl.destroy;
2398
+ Writable2.prototype._undestroy = destroyImpl.undestroy;
2399
+ Writable2.prototype._destroy = function(err, cb) {
2400
+ cb(err);
2401
+ };
2402
+ return _stream_writable;
2403
+ }
2404
+ var tripleBeam = {};
2405
+ var config = {};
2406
+ var cli = {};
2407
+ cli.levels = {
2408
+ error: 0,
2409
+ warn: 1,
2410
+ help: 2,
2411
+ data: 3,
2412
+ info: 4,
2413
+ debug: 5,
2414
+ prompt: 6,
2415
+ verbose: 7,
2416
+ input: 8,
2417
+ silly: 9
2418
+ };
2419
+ cli.colors = {
2420
+ error: "red",
2421
+ warn: "yellow",
2422
+ help: "cyan",
2423
+ data: "grey",
2424
+ info: "green",
2425
+ debug: "blue",
2426
+ prompt: "grey",
2427
+ verbose: "cyan",
2428
+ input: "grey",
2429
+ silly: "magenta"
2430
+ };
2431
+ var npm = {};
2432
+ npm.levels = {
2433
+ error: 0,
2434
+ warn: 1,
2435
+ info: 2,
2436
+ http: 3,
2437
+ verbose: 4,
2438
+ debug: 5,
2439
+ silly: 6
2440
+ };
2441
+ npm.colors = {
2442
+ error: "red",
2443
+ warn: "yellow",
2444
+ info: "green",
2445
+ http: "green",
2446
+ verbose: "cyan",
2447
+ debug: "blue",
2448
+ silly: "magenta"
2449
+ };
2450
+ var syslog = {};
2451
+ syslog.levels = {
2452
+ emerg: 0,
2453
+ alert: 1,
2454
+ crit: 2,
2455
+ error: 3,
2456
+ warning: 4,
2457
+ notice: 5,
2458
+ info: 6,
2459
+ debug: 7
2460
+ };
2461
+ syslog.colors = {
2462
+ emerg: "red",
2463
+ alert: "yellow",
2464
+ crit: "red",
2465
+ error: "red",
2466
+ warning: "red",
2467
+ notice: "yellow",
2468
+ info: "green",
2469
+ debug: "blue"
2470
+ };
2471
+ (function(exports) {
2472
+ Object.defineProperty(exports, "cli", {
2473
+ value: cli
2474
+ });
2475
+ Object.defineProperty(exports, "npm", {
2476
+ value: npm
2477
+ });
2478
+ Object.defineProperty(exports, "syslog", {
2479
+ value: syslog
2480
+ });
2481
+ })(config);
2482
+ (function(exports) {
2483
+ Object.defineProperty(exports, "LEVEL", {
2484
+ value: Symbol.for("level")
2485
+ });
2486
+ Object.defineProperty(exports, "MESSAGE", {
2487
+ value: Symbol.for("message")
2488
+ });
2489
+ Object.defineProperty(exports, "SPLAT", {
2490
+ value: Symbol.for("splat")
2491
+ });
2492
+ Object.defineProperty(exports, "configs", {
2493
+ value: config
2494
+ });
2495
+ })(tripleBeam);
2496
+ var util$1 = require$$0$1;
2497
+ var Writable = require_stream_writable();
2498
+ var _require$1 = tripleBeam, LEVEL$1 = _require$1.LEVEL;
2499
+ var TransportStream$1 = modern.exports = function TransportStream() {
2500
+ var _this = this;
2501
+ var options = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : {};
2502
+ Writable.call(this, { objectMode: true, highWaterMark: options.highWaterMark });
2503
+ this.format = options.format;
2504
+ this.level = options.level;
2505
+ this.handleExceptions = options.handleExceptions;
2506
+ this.handleRejections = options.handleRejections;
2507
+ this.silent = options.silent;
2508
+ if (options.log) this.log = options.log;
2509
+ if (options.logv) this.logv = options.logv;
2510
+ if (options.close) this.close = options.close;
2511
+ this.once("pipe", function(logger) {
2512
+ _this.levels = logger.levels;
2513
+ _this.parent = logger;
2514
+ });
2515
+ this.once("unpipe", function(src) {
2516
+ if (src === _this.parent) {
2517
+ _this.parent = null;
2518
+ if (_this.close) {
2519
+ _this.close();
2520
+ }
2521
+ }
2522
+ });
2523
+ };
2524
+ util$1.inherits(TransportStream$1, Writable);
2525
+ TransportStream$1.prototype._write = function _write(info, enc, callback) {
2526
+ if (this.silent || info.exception === true && !this.handleExceptions) {
2527
+ return callback(null);
2528
+ }
2529
+ var level = this.level || this.parent && this.parent.level;
2530
+ if (!level || this.levels[level] >= this.levels[info[LEVEL$1]]) {
2531
+ if (info && !this.format) {
2532
+ return this.log(info, callback);
2533
+ }
2534
+ var errState = void 0;
2535
+ var transformed = void 0;
2536
+ try {
2537
+ transformed = this.format.transform(Object.assign({}, info), this.format.options);
2538
+ } catch (err) {
2539
+ errState = err;
2540
+ }
2541
+ if (errState || !transformed) {
2542
+ callback();
2543
+ if (errState) throw errState;
2544
+ return;
2545
+ }
2546
+ return this.log(transformed, callback);
2547
+ }
2548
+ this._writableState.sync = false;
2549
+ return callback(null);
2550
+ };
2551
+ TransportStream$1.prototype._writev = function _writev(chunks, callback) {
2552
+ if (this.logv) {
2553
+ var infos = chunks.filter(this._accept, this);
2554
+ if (!infos.length) {
2555
+ return callback(null);
2556
+ }
2557
+ return this.logv(infos, callback);
2558
+ }
2559
+ for (var i = 0; i < chunks.length; i++) {
2560
+ if (!this._accept(chunks[i])) continue;
2561
+ if (chunks[i].chunk && !this.format) {
2562
+ this.log(chunks[i].chunk, chunks[i].callback);
2563
+ continue;
2564
+ }
2565
+ var errState = void 0;
2566
+ var transformed = void 0;
2567
+ try {
2568
+ transformed = this.format.transform(Object.assign({}, chunks[i].chunk), this.format.options);
2569
+ } catch (err) {
2570
+ errState = err;
2571
+ }
2572
+ if (errState || !transformed) {
2573
+ chunks[i].callback();
2574
+ if (errState) {
2575
+ callback(null);
2576
+ throw errState;
2577
+ }
2578
+ } else {
2579
+ this.log(transformed, chunks[i].callback);
2580
+ }
2581
+ }
2582
+ return callback(null);
2583
+ };
2584
+ TransportStream$1.prototype._accept = function _accept(write) {
2585
+ var info = write.chunk;
2586
+ if (this.silent) {
2587
+ return false;
2588
+ }
2589
+ var level = this.level || this.parent && this.parent.level;
2590
+ if (info.exception === true || !level || this.levels[level] >= this.levels[info[LEVEL$1]]) {
2591
+ if (this.handleExceptions || info.exception !== true) {
2592
+ return true;
2593
+ }
2594
+ }
2595
+ return false;
2596
+ };
2597
+ TransportStream$1.prototype._nop = function _nop() {
2598
+ return void 0;
2599
+ };
2600
+ var modernExports = modern.exports;
2601
+ var legacy = { exports: {} };
2602
+ var util = require$$0$1;
2603
+ var _require = tripleBeam, LEVEL = _require.LEVEL;
2604
+ var TransportStream2 = modernExports;
2605
+ var LegacyTransportStream = legacy.exports = function LegacyTransportStream2() {
2606
+ var options = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : {};
2607
+ TransportStream2.call(this, options);
2608
+ if (!options.transport || typeof options.transport.log !== "function") {
2609
+ throw new Error("Invalid transport, must be an object with a log method.");
2610
+ }
2611
+ this.transport = options.transport;
2612
+ this.level = this.level || options.transport.level;
2613
+ this.handleExceptions = this.handleExceptions || options.transport.handleExceptions;
2614
+ this._deprecated();
2615
+ function transportError(err) {
2616
+ this.emit("error", err, this.transport);
2617
+ }
2618
+ if (!this.transport.__winstonError) {
2619
+ this.transport.__winstonError = transportError.bind(this);
2620
+ this.transport.on("error", this.transport.__winstonError);
2621
+ }
2622
+ };
2623
+ util.inherits(LegacyTransportStream, TransportStream2);
2624
+ LegacyTransportStream.prototype._write = function _write2(info, enc, callback) {
2625
+ if (this.silent || info.exception === true && !this.handleExceptions) {
2626
+ return callback(null);
2627
+ }
2628
+ if (!this.level || this.levels[this.level] >= this.levels[info[LEVEL]]) {
2629
+ this.transport.log(info[LEVEL], info.message, info, this._nop);
2630
+ }
2631
+ callback(null);
2632
+ };
2633
+ LegacyTransportStream.prototype._writev = function _writev2(chunks, callback) {
2634
+ for (var i = 0; i < chunks.length; i++) {
2635
+ if (this._accept(chunks[i])) {
2636
+ this.transport.log(chunks[i].chunk[LEVEL], chunks[i].chunk.message, chunks[i].chunk, this._nop);
2637
+ chunks[i].callback();
2638
+ }
2639
+ }
2640
+ return callback(null);
2641
+ };
2642
+ LegacyTransportStream.prototype._deprecated = function _deprecated() {
2643
+ console.error([this.transport.name + " is a legacy winston transport. Consider upgrading: ", "- Upgrade docs: https://github.com/winstonjs/winston/blob/master/UPGRADE-3.0.md"].join("\n"));
2644
+ };
2645
+ LegacyTransportStream.prototype.close = function close() {
2646
+ if (this.transport.close) {
2647
+ this.transport.close();
2648
+ }
2649
+ if (this.transport.__winstonError) {
2650
+ this.transport.removeListener("error", this.transport.__winstonError);
2651
+ this.transport.__winstonError = null;
2652
+ }
2653
+ };
2654
+ var legacyExports = legacy.exports;
2655
+ dist.exports = modernExports;
2656
+ dist.exports.LegacyTransportStream = legacyExports;
2657
+ var distExports = dist.exports;
2658
+ const Transport = /* @__PURE__ */ getDefaultExportFromCjs(distExports);
2659
+ const SEVERITY = { error: 5, warn: 4, info: 3, http: 2, debug: 1 };
2660
+ const SENSITIVE_KEYS = /* @__PURE__ */ new Set([
2661
+ "authorization",
2662
+ "cookie",
2663
+ "password",
2664
+ "pwd",
2665
+ "token",
2666
+ "access_token",
2667
+ "refresh_token",
2668
+ "id_token",
2669
+ "secret",
2670
+ "client_secret",
2671
+ "api_key",
2672
+ "apikey",
2673
+ "x-api-key",
2674
+ "private_key",
2675
+ "bearer",
2676
+ "credentials",
2677
+ "auth"
2678
+ ]);
2679
+ const JWT_RE = /\beyJ[A-Za-z0-9_-]+\.[A-Za-z0-9_-]+(?:\.[A-Za-z0-9_-]+)?\b/g;
2680
+ const TOKEN_STRING_RE = /"(access_token|refresh_token|id_token|bearer|authorization|password|secret|api_key|apikey|token)"\s*:\s*"[^"]*"/gi;
2681
+ function redactString(str) {
2682
+ return str.replace(JWT_RE, "*****").replace(TOKEN_STRING_RE, (_, key) => `"${key}":"*****"`);
2683
+ }
2684
+ function redact$3(value) {
2685
+ if (value === null || value === void 0) return value;
2686
+ if (typeof value === "string") return redactString(value);
2687
+ if (Array.isArray(value)) return value.map(redact$3);
2688
+ if (typeof value === "object") {
2689
+ const out = {};
2690
+ for (const k of Object.keys(value)) {
2691
+ out[k] = SENSITIVE_KEYS.has(k.toLowerCase()) ? "*****" : redact$3(value[k]);
2692
+ }
2693
+ return out;
2694
+ }
2695
+ return value;
2696
+ }
2697
+ const transportCache = /* @__PURE__ */ new Map();
2698
+ class CoralogixTransport extends Transport {
2699
+ static getOrCreate(opts = {}) {
2700
+ const key = `${opts.applicationName}|${opts.subsystemName}|${opts.apiKey}|${opts.domain || "us2.coralogix.com"}`;
2701
+ let instance = transportCache.get(key);
2702
+ if (!instance) {
2703
+ instance = new CoralogixTransport(opts);
2704
+ transportCache.set(key, instance);
2705
+ }
2706
+ return instance;
2707
+ }
2708
+ constructor(opts = {}) {
2709
+ super(opts);
2710
+ this.applicationName = opts.applicationName;
2711
+ this.subsystemName = opts.subsystemName;
2712
+ this.apiKey = opts.apiKey;
2713
+ this.cxDomain = opts.domain || "us2.coralogix.com";
2714
+ this.host = `ingress.${this.cxDomain}`;
2715
+ this.path = opts.path || "/logs/v1/bulk";
2716
+ this.batchCount = opts.batchCount || 100;
2717
+ this.batchInterval = opts.batchInterval || 5e3;
2718
+ this.queue = [];
2719
+ this.agent = new https.Agent({ family: 4, keepAlive: true });
2720
+ this.timer = setInterval(() => this.flush(), this.batchInterval);
2721
+ if (this.timer.unref) this.timer.unref();
2722
+ this.setMaxListeners(Infinity);
2723
+ }
2724
+ log(info, callback) {
2725
+ setImmediate(() => this.emit("logged", info));
2726
+ const sanitized = redact$3(info);
2727
+ this.queue.push({
2728
+ severity: SEVERITY[info.level] || SEVERITY.info,
2729
+ timestamp: Date.now(),
2730
+ text: JSON.stringify(sanitized)
2731
+ });
2732
+ if (this.queue.length >= this.batchCount) this.flush();
2733
+ if (callback) callback();
2734
+ }
2735
+ flush() {
2736
+ if (this.queue.length === 0) return;
2737
+ const batch = this.queue.splice(0);
2738
+ const body = JSON.stringify({
2739
+ applicationName: this.applicationName,
2740
+ subsystemName: this.subsystemName,
2741
+ logEntries: batch
2742
+ });
2743
+ const req = https.request({
2744
+ host: this.host,
2745
+ path: this.path,
2746
+ method: "POST",
2747
+ agent: this.agent,
2748
+ headers: {
2749
+ "Authorization": `Bearer ${this.apiKey}`,
2750
+ "Content-Type": "application/json",
2751
+ "Content-Length": Buffer.byteLength(body)
2752
+ },
2753
+ timeout: 5e3
2754
+ });
2755
+ req.on("error", () => {
2756
+ });
2757
+ req.on("timeout", () => req.destroy());
2758
+ req.end(body);
2759
+ }
2760
+ close() {
2761
+ if (this.timer) clearInterval(this.timer);
2762
+ this.flush();
2763
+ }
2764
+ }
1
2765
  require("winston-daily-rotate-file");
2
2766
  const { format: format$1, createLogger, transports, addColors } = require("winston");
3
2767
  const { inspect } = require("util");
@@ -99,11 +2863,37 @@ function createTransport(options) {
99
2863
  }
100
2864
  return new transports.DailyRotateFile(options);
101
2865
  }
2866
+ const loggerCache = /* @__PURE__ */ new Map();
2867
+ function transportCacheKey(o) {
2868
+ return JSON.stringify({
2869
+ dirname: o.dirname,
2870
+ filename: o.filename,
2871
+ errorFilename: o.errorFilename,
2872
+ level: o.level,
2873
+ levels: o.levels,
2874
+ maxFiles: o.maxFiles,
2875
+ maxFileSize: o.maxFileSize,
2876
+ zippedArchive: o.zippedArchive,
2877
+ dateFormat: o.dateFormat,
2878
+ createSymlink: o.createSymlink,
2879
+ symlinkName: o.symlinkName,
2880
+ file: !!o.file,
2881
+ console: !!o.console,
2882
+ consoleJSON: !!o.consoleJSON,
2883
+ http: o.http || null
2884
+ });
2885
+ }
102
2886
  class Logger {
103
2887
  constructor(options = {}) {
104
2888
  this.options = { ...OPTIONS$1, ...options };
105
2889
  if (!this.options.filename.includes(".")) this.options.filename += ".log";
106
2890
  if (!this.options.errorFilename.includes(".")) this.options.errorFilename += ".log";
2891
+ const cacheKey = transportCacheKey(this.options);
2892
+ const cachedLogger = loggerCache.get(cacheKey);
2893
+ if (cachedLogger) {
2894
+ this.logger = cachedLogger;
2895
+ return;
2896
+ }
107
2897
  let trans = [];
108
2898
  let exceptionHandlers = [new transports.Console({
109
2899
  format: getFormatter("console", this.options)
@@ -151,6 +2941,9 @@ class Logger {
151
2941
  });
152
2942
  trans.push(httpTransport);
153
2943
  }
2944
+ if (this.options.coralogix) {
2945
+ trans.push(CoralogixTransport.getOrCreate(this.options.coralogix));
2946
+ }
154
2947
  this.logger = createLogger({
155
2948
  level: this.options.level,
156
2949
  levels: this.options.levels,
@@ -159,6 +2952,7 @@ class Logger {
159
2952
  transports: trans
160
2953
  // exceptionHandlers
161
2954
  });
2955
+ loggerCache.set(cacheKey, this.logger);
162
2956
  }
163
2957
  }
164
2958
  const redact$2 = (data, ...sensitiveKeysList) => {
@@ -316,7 +3110,7 @@ class Throttle {
316
3110
  }
317
3111
  }
318
3112
  class BaseLogger {
319
- constructor(component, options) {
3113
+ constructor(component, options = {}) {
320
3114
  this.options = options;
321
3115
  this.logger = new Logger(options).logger.child({ component });
322
3116
  this.ctx = {};
@@ -506,10 +3300,11 @@ class HTTPLogger extends BaseLogger {
506
3300
  query: redact$1(req == null ? void 0 : req.query, "password"),
507
3301
  clientIP: ((_a = req == null ? void 0 : req.headers["x-forwarded-for"]) == null ? void 0 : _a.split(",")[0]) ?? (req == null ? void 0 : req.socket.remoteAddress)
508
3302
  };
3303
+ const redactedBody = redact$1(body, "password");
509
3304
  this.ctx.response = {
510
3305
  headers: omit$1(res.getHeaders(), "set-cookie", "x-powered-by"),
511
3306
  statusCode: res.statusCode,
512
- body: this.options.maxBodyLength <= 0 ? body : trim$1(body, this.options.maxBodyLength || MAX_BODY_LENGTH$1)
3307
+ body: this.options.maxBodyLength <= 0 ? redactedBody : trim$1(redactedBody, this.options.maxBodyLength || MAX_BODY_LENGTH$1)
513
3308
  };
514
3309
  this.ctx.responseTimeMs = Date.now() - this.startTime;
515
3310
  this.ctx.responseSizeBytes = this.data ? JSON.stringify(this.data).length : 0;
@@ -794,6 +3589,7 @@ class StaticLogger extends BaseLogger {
794
3589
  const staticLogger = new StaticLogger();
795
3590
  export {
796
3591
  BaseLogger,
3592
+ CoralogixTransport,
797
3593
  FastifyLogger,
798
3594
  HTTPLogger as HttpLogger,
799
3595
  plugin as MongooseLoggerPlugin,