@vouchfor/libs 1.0.0

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