@pensar/apex 0.0.111 → 0.0.112

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (64) hide show
  1. package/README.md +2 -3
  2. package/bin/pensar.js +31 -276
  3. package/build/agent-5qdmmchx.js +206 -0
  4. package/build/agent-s2z0dasf.js +16 -0
  5. package/build/auth-jvq72ekc.js +263 -0
  6. package/build/authentication-nya4td5k.js +310 -0
  7. package/build/blackboxAgent-qa9ze2hn.js +17 -0
  8. package/build/blackboxPentest-85hwznet.js +41 -0
  9. package/build/cli-15vxn9zj.js +1358 -0
  10. package/build/cli-2ckm5es2.js +50 -0
  11. package/build/cli-49cd9yfk.js +4475 -0
  12. package/build/cli-5d6cs4dq.js +53 -0
  13. package/build/cli-6gtnyaqf.js +109 -0
  14. package/build/cli-7ckctq7a.js +45 -0
  15. package/build/cli-8rxa073f.js +104 -0
  16. package/build/cli-bp6d08sg.js +110 -0
  17. package/build/cli-e20q3hqz.js +307 -0
  18. package/build/cli-f9shhcxf.js +1498 -0
  19. package/build/cli-hmrzx8am.js +507 -0
  20. package/build/cli-j66pect7.js +202 -0
  21. package/build/cli-jb0gcnrs.js +60 -0
  22. package/build/cli-jh38b6zv.js +1074 -0
  23. package/build/cli-kqtgcdzn.js +54784 -0
  24. package/build/cli-r8r90gka.js +96700 -0
  25. package/build/cli-va4y0089.js +395 -0
  26. package/build/cli-w04ggbe4.js +104 -0
  27. package/build/cli-x1msjf55.js +103 -0
  28. package/build/cli-yj3dy0vg.js +180 -0
  29. package/build/cli.js +509 -0
  30. package/build/doctor-b7612pzw.js +117 -0
  31. package/build/fixes-1r6v7kh2.js +49 -0
  32. package/build/index-5ke2yd32.js +17 -0
  33. package/build/index-9ze42wn7.js +68412 -0
  34. package/build/index-rd11fk7h.js +1257 -0
  35. package/build/index-tke6896d.js +1097 -0
  36. package/build/index-vwvh1rdw.js +535 -0
  37. package/build/issues-kx721wja.js +94 -0
  38. package/build/logs-hav7d0nm.js +77 -0
  39. package/build/main-2483qzbq.js +397 -0
  40. package/build/multipart-parser-r38qdp5v.js +350 -0
  41. package/build/pentest-zzebnfa0.js +25 -0
  42. package/build/pentests-s9fwd71b.js +70 -0
  43. package/build/projects-tr719twv.js +35 -0
  44. package/build/targetedPentest-w2c85whf.js +32 -0
  45. package/build/token-6x6aavpc.js +58 -0
  46. package/build/token-util-na95bqjj.js +6 -0
  47. package/build/uninstall-2j0pymb0.js +231 -0
  48. package/build/utils-jky0th19.js +107 -0
  49. package/package.json +3 -4
  50. package/build/auth.js +0 -625
  51. package/build/highlights-eq9cgrbb.scm +0 -604
  52. package/build/highlights-ghv9g403.scm +0 -205
  53. package/build/highlights-hk7bwhj4.scm +0 -284
  54. package/build/highlights-r812a2qc.scm +0 -150
  55. package/build/highlights-x6tmsnaa.scm +0 -115
  56. package/build/index.js +0 -292069
  57. package/build/injections-73j83es3.scm +0 -27
  58. package/build/tree-sitter-javascript-nd0q4pe9.wasm +0 -0
  59. package/build/tree-sitter-markdown-411r6y9b.wasm +0 -0
  60. package/build/tree-sitter-markdown_inline-j5349f42.wasm +0 -0
  61. package/build/tree-sitter-typescript-zxjzwt75.wasm +0 -0
  62. package/build/tree-sitter-zig-e78zbjpm.wasm +0 -0
  63. package/src/core/installation/index.ts +0 -223
  64. package/src/core/installation/installation.test.ts +0 -454
@@ -0,0 +1,4475 @@
1
+ import {
2
+ __commonJS,
3
+ __esm,
4
+ __require,
5
+ __toESM
6
+ } from "./cli-8rxa073f.js";
7
+
8
+ // node_modules/web-streams-polyfill/dist/ponyfill.es2018.js
9
+ var require_ponyfill_es2018 = __commonJS((exports, module) => {
10
+ (function(global2, factory) {
11
+ typeof exports === "object" && typeof module !== "undefined" ? factory(exports) : typeof define === "function" && define.amd ? define(["exports"], factory) : (global2 = typeof globalThis !== "undefined" ? globalThis : global2 || self, factory(global2.WebStreamsPolyfill = {}));
12
+ })(exports, function(exports2) {
13
+ function noop() {
14
+ return;
15
+ }
16
+ function typeIsObject(x) {
17
+ return typeof x === "object" && x !== null || typeof x === "function";
18
+ }
19
+ const rethrowAssertionErrorRejection = noop;
20
+ function setFunctionName(fn, name) {
21
+ try {
22
+ Object.defineProperty(fn, "name", {
23
+ value: name,
24
+ configurable: true
25
+ });
26
+ } catch (_a2) {}
27
+ }
28
+ const originalPromise = Promise;
29
+ const originalPromiseThen = Promise.prototype.then;
30
+ const originalPromiseReject = Promise.reject.bind(originalPromise);
31
+ function newPromise(executor) {
32
+ return new originalPromise(executor);
33
+ }
34
+ function promiseResolvedWith(value) {
35
+ return newPromise((resolve) => resolve(value));
36
+ }
37
+ function promiseRejectedWith(reason) {
38
+ return originalPromiseReject(reason);
39
+ }
40
+ function PerformPromiseThen(promise, onFulfilled, onRejected) {
41
+ return originalPromiseThen.call(promise, onFulfilled, onRejected);
42
+ }
43
+ function uponPromise(promise, onFulfilled, onRejected) {
44
+ PerformPromiseThen(PerformPromiseThen(promise, onFulfilled, onRejected), undefined, rethrowAssertionErrorRejection);
45
+ }
46
+ function uponFulfillment(promise, onFulfilled) {
47
+ uponPromise(promise, onFulfilled);
48
+ }
49
+ function uponRejection(promise, onRejected) {
50
+ uponPromise(promise, undefined, onRejected);
51
+ }
52
+ function transformPromiseWith(promise, fulfillmentHandler, rejectionHandler) {
53
+ return PerformPromiseThen(promise, fulfillmentHandler, rejectionHandler);
54
+ }
55
+ function setPromiseIsHandledToTrue(promise) {
56
+ PerformPromiseThen(promise, undefined, rethrowAssertionErrorRejection);
57
+ }
58
+ let _queueMicrotask = (callback) => {
59
+ if (typeof queueMicrotask === "function") {
60
+ _queueMicrotask = queueMicrotask;
61
+ } else {
62
+ const resolvedPromise = promiseResolvedWith(undefined);
63
+ _queueMicrotask = (cb) => PerformPromiseThen(resolvedPromise, cb);
64
+ }
65
+ return _queueMicrotask(callback);
66
+ };
67
+ function reflectCall(F, V, args) {
68
+ if (typeof F !== "function") {
69
+ throw new TypeError("Argument is not a function");
70
+ }
71
+ return Function.prototype.apply.call(F, V, args);
72
+ }
73
+ function promiseCall(F, V, args) {
74
+ try {
75
+ return promiseResolvedWith(reflectCall(F, V, args));
76
+ } catch (value) {
77
+ return promiseRejectedWith(value);
78
+ }
79
+ }
80
+ const QUEUE_MAX_ARRAY_SIZE = 16384;
81
+
82
+ class SimpleQueue {
83
+ constructor() {
84
+ this._cursor = 0;
85
+ this._size = 0;
86
+ this._front = {
87
+ _elements: [],
88
+ _next: undefined
89
+ };
90
+ this._back = this._front;
91
+ this._cursor = 0;
92
+ this._size = 0;
93
+ }
94
+ get length() {
95
+ return this._size;
96
+ }
97
+ push(element) {
98
+ const oldBack = this._back;
99
+ let newBack = oldBack;
100
+ if (oldBack._elements.length === QUEUE_MAX_ARRAY_SIZE - 1) {
101
+ newBack = {
102
+ _elements: [],
103
+ _next: undefined
104
+ };
105
+ }
106
+ oldBack._elements.push(element);
107
+ if (newBack !== oldBack) {
108
+ this._back = newBack;
109
+ oldBack._next = newBack;
110
+ }
111
+ ++this._size;
112
+ }
113
+ shift() {
114
+ const oldFront = this._front;
115
+ let newFront = oldFront;
116
+ const oldCursor = this._cursor;
117
+ let newCursor = oldCursor + 1;
118
+ const elements = oldFront._elements;
119
+ const element = elements[oldCursor];
120
+ if (newCursor === QUEUE_MAX_ARRAY_SIZE) {
121
+ newFront = oldFront._next;
122
+ newCursor = 0;
123
+ }
124
+ --this._size;
125
+ this._cursor = newCursor;
126
+ if (oldFront !== newFront) {
127
+ this._front = newFront;
128
+ }
129
+ elements[oldCursor] = undefined;
130
+ return element;
131
+ }
132
+ forEach(callback) {
133
+ let i = this._cursor;
134
+ let node = this._front;
135
+ let elements = node._elements;
136
+ while (i !== elements.length || node._next !== undefined) {
137
+ if (i === elements.length) {
138
+ node = node._next;
139
+ elements = node._elements;
140
+ i = 0;
141
+ if (elements.length === 0) {
142
+ break;
143
+ }
144
+ }
145
+ callback(elements[i]);
146
+ ++i;
147
+ }
148
+ }
149
+ peek() {
150
+ const front = this._front;
151
+ const cursor = this._cursor;
152
+ return front._elements[cursor];
153
+ }
154
+ }
155
+ const AbortSteps = Symbol("[[AbortSteps]]");
156
+ const ErrorSteps = Symbol("[[ErrorSteps]]");
157
+ const CancelSteps = Symbol("[[CancelSteps]]");
158
+ const PullSteps = Symbol("[[PullSteps]]");
159
+ const ReleaseSteps = Symbol("[[ReleaseSteps]]");
160
+ function ReadableStreamReaderGenericInitialize(reader, stream) {
161
+ reader._ownerReadableStream = stream;
162
+ stream._reader = reader;
163
+ if (stream._state === "readable") {
164
+ defaultReaderClosedPromiseInitialize(reader);
165
+ } else if (stream._state === "closed") {
166
+ defaultReaderClosedPromiseInitializeAsResolved(reader);
167
+ } else {
168
+ defaultReaderClosedPromiseInitializeAsRejected(reader, stream._storedError);
169
+ }
170
+ }
171
+ function ReadableStreamReaderGenericCancel(reader, reason) {
172
+ const stream = reader._ownerReadableStream;
173
+ return ReadableStreamCancel(stream, reason);
174
+ }
175
+ function ReadableStreamReaderGenericRelease(reader) {
176
+ const stream = reader._ownerReadableStream;
177
+ if (stream._state === "readable") {
178
+ defaultReaderClosedPromiseReject(reader, new TypeError(`Reader was released and can no longer be used to monitor the stream's closedness`));
179
+ } else {
180
+ defaultReaderClosedPromiseResetToRejected(reader, new TypeError(`Reader was released and can no longer be used to monitor the stream's closedness`));
181
+ }
182
+ stream._readableStreamController[ReleaseSteps]();
183
+ stream._reader = undefined;
184
+ reader._ownerReadableStream = undefined;
185
+ }
186
+ function readerLockException(name) {
187
+ return new TypeError("Cannot " + name + " a stream using a released reader");
188
+ }
189
+ function defaultReaderClosedPromiseInitialize(reader) {
190
+ reader._closedPromise = newPromise((resolve, reject) => {
191
+ reader._closedPromise_resolve = resolve;
192
+ reader._closedPromise_reject = reject;
193
+ });
194
+ }
195
+ function defaultReaderClosedPromiseInitializeAsRejected(reader, reason) {
196
+ defaultReaderClosedPromiseInitialize(reader);
197
+ defaultReaderClosedPromiseReject(reader, reason);
198
+ }
199
+ function defaultReaderClosedPromiseInitializeAsResolved(reader) {
200
+ defaultReaderClosedPromiseInitialize(reader);
201
+ defaultReaderClosedPromiseResolve(reader);
202
+ }
203
+ function defaultReaderClosedPromiseReject(reader, reason) {
204
+ if (reader._closedPromise_reject === undefined) {
205
+ return;
206
+ }
207
+ setPromiseIsHandledToTrue(reader._closedPromise);
208
+ reader._closedPromise_reject(reason);
209
+ reader._closedPromise_resolve = undefined;
210
+ reader._closedPromise_reject = undefined;
211
+ }
212
+ function defaultReaderClosedPromiseResetToRejected(reader, reason) {
213
+ defaultReaderClosedPromiseInitializeAsRejected(reader, reason);
214
+ }
215
+ function defaultReaderClosedPromiseResolve(reader) {
216
+ if (reader._closedPromise_resolve === undefined) {
217
+ return;
218
+ }
219
+ reader._closedPromise_resolve(undefined);
220
+ reader._closedPromise_resolve = undefined;
221
+ reader._closedPromise_reject = undefined;
222
+ }
223
+ const NumberIsFinite = Number.isFinite || function(x) {
224
+ return typeof x === "number" && isFinite(x);
225
+ };
226
+ const MathTrunc = Math.trunc || function(v) {
227
+ return v < 0 ? Math.ceil(v) : Math.floor(v);
228
+ };
229
+ function isDictionary(x) {
230
+ return typeof x === "object" || typeof x === "function";
231
+ }
232
+ function assertDictionary(obj, context) {
233
+ if (obj !== undefined && !isDictionary(obj)) {
234
+ throw new TypeError(`${context} is not an object.`);
235
+ }
236
+ }
237
+ function assertFunction(x, context) {
238
+ if (typeof x !== "function") {
239
+ throw new TypeError(`${context} is not a function.`);
240
+ }
241
+ }
242
+ function isObject(x) {
243
+ return typeof x === "object" && x !== null || typeof x === "function";
244
+ }
245
+ function assertObject(x, context) {
246
+ if (!isObject(x)) {
247
+ throw new TypeError(`${context} is not an object.`);
248
+ }
249
+ }
250
+ function assertRequiredArgument(x, position, context) {
251
+ if (x === undefined) {
252
+ throw new TypeError(`Parameter ${position} is required in '${context}'.`);
253
+ }
254
+ }
255
+ function assertRequiredField(x, field, context) {
256
+ if (x === undefined) {
257
+ throw new TypeError(`${field} is required in '${context}'.`);
258
+ }
259
+ }
260
+ function convertUnrestrictedDouble(value) {
261
+ return Number(value);
262
+ }
263
+ function censorNegativeZero(x) {
264
+ return x === 0 ? 0 : x;
265
+ }
266
+ function integerPart(x) {
267
+ return censorNegativeZero(MathTrunc(x));
268
+ }
269
+ function convertUnsignedLongLongWithEnforceRange(value, context) {
270
+ const lowerBound = 0;
271
+ const upperBound = Number.MAX_SAFE_INTEGER;
272
+ let x = Number(value);
273
+ x = censorNegativeZero(x);
274
+ if (!NumberIsFinite(x)) {
275
+ throw new TypeError(`${context} is not a finite number`);
276
+ }
277
+ x = integerPart(x);
278
+ if (x < lowerBound || x > upperBound) {
279
+ throw new TypeError(`${context} is outside the accepted range of ${lowerBound} to ${upperBound}, inclusive`);
280
+ }
281
+ if (!NumberIsFinite(x) || x === 0) {
282
+ return 0;
283
+ }
284
+ return x;
285
+ }
286
+ function assertReadableStream(x, context) {
287
+ if (!IsReadableStream(x)) {
288
+ throw new TypeError(`${context} is not a ReadableStream.`);
289
+ }
290
+ }
291
+ function AcquireReadableStreamDefaultReader(stream) {
292
+ return new ReadableStreamDefaultReader(stream);
293
+ }
294
+ function ReadableStreamAddReadRequest(stream, readRequest) {
295
+ stream._reader._readRequests.push(readRequest);
296
+ }
297
+ function ReadableStreamFulfillReadRequest(stream, chunk, done) {
298
+ const reader = stream._reader;
299
+ const readRequest = reader._readRequests.shift();
300
+ if (done) {
301
+ readRequest._closeSteps();
302
+ } else {
303
+ readRequest._chunkSteps(chunk);
304
+ }
305
+ }
306
+ function ReadableStreamGetNumReadRequests(stream) {
307
+ return stream._reader._readRequests.length;
308
+ }
309
+ function ReadableStreamHasDefaultReader(stream) {
310
+ const reader = stream._reader;
311
+ if (reader === undefined) {
312
+ return false;
313
+ }
314
+ if (!IsReadableStreamDefaultReader(reader)) {
315
+ return false;
316
+ }
317
+ return true;
318
+ }
319
+
320
+ class ReadableStreamDefaultReader {
321
+ constructor(stream) {
322
+ assertRequiredArgument(stream, 1, "ReadableStreamDefaultReader");
323
+ assertReadableStream(stream, "First parameter");
324
+ if (IsReadableStreamLocked(stream)) {
325
+ throw new TypeError("This stream has already been locked for exclusive reading by another reader");
326
+ }
327
+ ReadableStreamReaderGenericInitialize(this, stream);
328
+ this._readRequests = new SimpleQueue;
329
+ }
330
+ get closed() {
331
+ if (!IsReadableStreamDefaultReader(this)) {
332
+ return promiseRejectedWith(defaultReaderBrandCheckException("closed"));
333
+ }
334
+ return this._closedPromise;
335
+ }
336
+ cancel(reason = undefined) {
337
+ if (!IsReadableStreamDefaultReader(this)) {
338
+ return promiseRejectedWith(defaultReaderBrandCheckException("cancel"));
339
+ }
340
+ if (this._ownerReadableStream === undefined) {
341
+ return promiseRejectedWith(readerLockException("cancel"));
342
+ }
343
+ return ReadableStreamReaderGenericCancel(this, reason);
344
+ }
345
+ read() {
346
+ if (!IsReadableStreamDefaultReader(this)) {
347
+ return promiseRejectedWith(defaultReaderBrandCheckException("read"));
348
+ }
349
+ if (this._ownerReadableStream === undefined) {
350
+ return promiseRejectedWith(readerLockException("read from"));
351
+ }
352
+ let resolvePromise;
353
+ let rejectPromise;
354
+ const promise = newPromise((resolve, reject) => {
355
+ resolvePromise = resolve;
356
+ rejectPromise = reject;
357
+ });
358
+ const readRequest = {
359
+ _chunkSteps: (chunk) => resolvePromise({ value: chunk, done: false }),
360
+ _closeSteps: () => resolvePromise({ value: undefined, done: true }),
361
+ _errorSteps: (e) => rejectPromise(e)
362
+ };
363
+ ReadableStreamDefaultReaderRead(this, readRequest);
364
+ return promise;
365
+ }
366
+ releaseLock() {
367
+ if (!IsReadableStreamDefaultReader(this)) {
368
+ throw defaultReaderBrandCheckException("releaseLock");
369
+ }
370
+ if (this._ownerReadableStream === undefined) {
371
+ return;
372
+ }
373
+ ReadableStreamDefaultReaderRelease(this);
374
+ }
375
+ }
376
+ Object.defineProperties(ReadableStreamDefaultReader.prototype, {
377
+ cancel: { enumerable: true },
378
+ read: { enumerable: true },
379
+ releaseLock: { enumerable: true },
380
+ closed: { enumerable: true }
381
+ });
382
+ setFunctionName(ReadableStreamDefaultReader.prototype.cancel, "cancel");
383
+ setFunctionName(ReadableStreamDefaultReader.prototype.read, "read");
384
+ setFunctionName(ReadableStreamDefaultReader.prototype.releaseLock, "releaseLock");
385
+ if (typeof Symbol.toStringTag === "symbol") {
386
+ Object.defineProperty(ReadableStreamDefaultReader.prototype, Symbol.toStringTag, {
387
+ value: "ReadableStreamDefaultReader",
388
+ configurable: true
389
+ });
390
+ }
391
+ function IsReadableStreamDefaultReader(x) {
392
+ if (!typeIsObject(x)) {
393
+ return false;
394
+ }
395
+ if (!Object.prototype.hasOwnProperty.call(x, "_readRequests")) {
396
+ return false;
397
+ }
398
+ return x instanceof ReadableStreamDefaultReader;
399
+ }
400
+ function ReadableStreamDefaultReaderRead(reader, readRequest) {
401
+ const stream = reader._ownerReadableStream;
402
+ stream._disturbed = true;
403
+ if (stream._state === "closed") {
404
+ readRequest._closeSteps();
405
+ } else if (stream._state === "errored") {
406
+ readRequest._errorSteps(stream._storedError);
407
+ } else {
408
+ stream._readableStreamController[PullSteps](readRequest);
409
+ }
410
+ }
411
+ function ReadableStreamDefaultReaderRelease(reader) {
412
+ ReadableStreamReaderGenericRelease(reader);
413
+ const e = new TypeError("Reader was released");
414
+ ReadableStreamDefaultReaderErrorReadRequests(reader, e);
415
+ }
416
+ function ReadableStreamDefaultReaderErrorReadRequests(reader, e) {
417
+ const readRequests = reader._readRequests;
418
+ reader._readRequests = new SimpleQueue;
419
+ readRequests.forEach((readRequest) => {
420
+ readRequest._errorSteps(e);
421
+ });
422
+ }
423
+ function defaultReaderBrandCheckException(name) {
424
+ return new TypeError(`ReadableStreamDefaultReader.prototype.${name} can only be used on a ReadableStreamDefaultReader`);
425
+ }
426
+ const AsyncIteratorPrototype = Object.getPrototypeOf(Object.getPrototypeOf(async function* () {}).prototype);
427
+
428
+ class ReadableStreamAsyncIteratorImpl {
429
+ constructor(reader, preventCancel) {
430
+ this._ongoingPromise = undefined;
431
+ this._isFinished = false;
432
+ this._reader = reader;
433
+ this._preventCancel = preventCancel;
434
+ }
435
+ next() {
436
+ const nextSteps = () => this._nextSteps();
437
+ this._ongoingPromise = this._ongoingPromise ? transformPromiseWith(this._ongoingPromise, nextSteps, nextSteps) : nextSteps();
438
+ return this._ongoingPromise;
439
+ }
440
+ return(value) {
441
+ const returnSteps = () => this._returnSteps(value);
442
+ return this._ongoingPromise ? transformPromiseWith(this._ongoingPromise, returnSteps, returnSteps) : returnSteps();
443
+ }
444
+ _nextSteps() {
445
+ if (this._isFinished) {
446
+ return Promise.resolve({ value: undefined, done: true });
447
+ }
448
+ const reader = this._reader;
449
+ let resolvePromise;
450
+ let rejectPromise;
451
+ const promise = newPromise((resolve, reject) => {
452
+ resolvePromise = resolve;
453
+ rejectPromise = reject;
454
+ });
455
+ const readRequest = {
456
+ _chunkSteps: (chunk) => {
457
+ this._ongoingPromise = undefined;
458
+ _queueMicrotask(() => resolvePromise({ value: chunk, done: false }));
459
+ },
460
+ _closeSteps: () => {
461
+ this._ongoingPromise = undefined;
462
+ this._isFinished = true;
463
+ ReadableStreamReaderGenericRelease(reader);
464
+ resolvePromise({ value: undefined, done: true });
465
+ },
466
+ _errorSteps: (reason) => {
467
+ this._ongoingPromise = undefined;
468
+ this._isFinished = true;
469
+ ReadableStreamReaderGenericRelease(reader);
470
+ rejectPromise(reason);
471
+ }
472
+ };
473
+ ReadableStreamDefaultReaderRead(reader, readRequest);
474
+ return promise;
475
+ }
476
+ _returnSteps(value) {
477
+ if (this._isFinished) {
478
+ return Promise.resolve({ value, done: true });
479
+ }
480
+ this._isFinished = true;
481
+ const reader = this._reader;
482
+ if (!this._preventCancel) {
483
+ const result = ReadableStreamReaderGenericCancel(reader, value);
484
+ ReadableStreamReaderGenericRelease(reader);
485
+ return transformPromiseWith(result, () => ({ value, done: true }));
486
+ }
487
+ ReadableStreamReaderGenericRelease(reader);
488
+ return promiseResolvedWith({ value, done: true });
489
+ }
490
+ }
491
+ const ReadableStreamAsyncIteratorPrototype = {
492
+ next() {
493
+ if (!IsReadableStreamAsyncIterator(this)) {
494
+ return promiseRejectedWith(streamAsyncIteratorBrandCheckException("next"));
495
+ }
496
+ return this._asyncIteratorImpl.next();
497
+ },
498
+ return(value) {
499
+ if (!IsReadableStreamAsyncIterator(this)) {
500
+ return promiseRejectedWith(streamAsyncIteratorBrandCheckException("return"));
501
+ }
502
+ return this._asyncIteratorImpl.return(value);
503
+ }
504
+ };
505
+ Object.setPrototypeOf(ReadableStreamAsyncIteratorPrototype, AsyncIteratorPrototype);
506
+ function AcquireReadableStreamAsyncIterator(stream, preventCancel) {
507
+ const reader = AcquireReadableStreamDefaultReader(stream);
508
+ const impl = new ReadableStreamAsyncIteratorImpl(reader, preventCancel);
509
+ const iterator = Object.create(ReadableStreamAsyncIteratorPrototype);
510
+ iterator._asyncIteratorImpl = impl;
511
+ return iterator;
512
+ }
513
+ function IsReadableStreamAsyncIterator(x) {
514
+ if (!typeIsObject(x)) {
515
+ return false;
516
+ }
517
+ if (!Object.prototype.hasOwnProperty.call(x, "_asyncIteratorImpl")) {
518
+ return false;
519
+ }
520
+ try {
521
+ return x._asyncIteratorImpl instanceof ReadableStreamAsyncIteratorImpl;
522
+ } catch (_a2) {
523
+ return false;
524
+ }
525
+ }
526
+ function streamAsyncIteratorBrandCheckException(name) {
527
+ return new TypeError(`ReadableStreamAsyncIterator.${name} can only be used on a ReadableSteamAsyncIterator`);
528
+ }
529
+ const NumberIsNaN = Number.isNaN || function(x) {
530
+ return x !== x;
531
+ };
532
+ var _a, _b, _c;
533
+ function CreateArrayFromList(elements) {
534
+ return elements.slice();
535
+ }
536
+ function CopyDataBlockBytes(dest, destOffset, src, srcOffset, n) {
537
+ new Uint8Array(dest).set(new Uint8Array(src, srcOffset, n), destOffset);
538
+ }
539
+ let TransferArrayBuffer = (O) => {
540
+ if (typeof O.transfer === "function") {
541
+ TransferArrayBuffer = (buffer) => buffer.transfer();
542
+ } else if (typeof structuredClone === "function") {
543
+ TransferArrayBuffer = (buffer) => structuredClone(buffer, { transfer: [buffer] });
544
+ } else {
545
+ TransferArrayBuffer = (buffer) => buffer;
546
+ }
547
+ return TransferArrayBuffer(O);
548
+ };
549
+ let IsDetachedBuffer = (O) => {
550
+ if (typeof O.detached === "boolean") {
551
+ IsDetachedBuffer = (buffer) => buffer.detached;
552
+ } else {
553
+ IsDetachedBuffer = (buffer) => buffer.byteLength === 0;
554
+ }
555
+ return IsDetachedBuffer(O);
556
+ };
557
+ function ArrayBufferSlice(buffer, begin, end) {
558
+ if (buffer.slice) {
559
+ return buffer.slice(begin, end);
560
+ }
561
+ const length = end - begin;
562
+ const slice = new ArrayBuffer(length);
563
+ CopyDataBlockBytes(slice, 0, buffer, begin, length);
564
+ return slice;
565
+ }
566
+ function GetMethod(receiver, prop) {
567
+ const func = receiver[prop];
568
+ if (func === undefined || func === null) {
569
+ return;
570
+ }
571
+ if (typeof func !== "function") {
572
+ throw new TypeError(`${String(prop)} is not a function`);
573
+ }
574
+ return func;
575
+ }
576
+ function CreateAsyncFromSyncIterator(syncIteratorRecord) {
577
+ const syncIterable = {
578
+ [Symbol.iterator]: () => syncIteratorRecord.iterator
579
+ };
580
+ const asyncIterator = async function* () {
581
+ return yield* syncIterable;
582
+ }();
583
+ const nextMethod = asyncIterator.next;
584
+ return { iterator: asyncIterator, nextMethod, done: false };
585
+ }
586
+ const SymbolAsyncIterator = (_c = (_a = Symbol.asyncIterator) !== null && _a !== undefined ? _a : (_b = Symbol.for) === null || _b === undefined ? undefined : _b.call(Symbol, "Symbol.asyncIterator")) !== null && _c !== undefined ? _c : "@@asyncIterator";
587
+ function GetIterator(obj, hint = "sync", method) {
588
+ if (method === undefined) {
589
+ if (hint === "async") {
590
+ method = GetMethod(obj, SymbolAsyncIterator);
591
+ if (method === undefined) {
592
+ const syncMethod = GetMethod(obj, Symbol.iterator);
593
+ const syncIteratorRecord = GetIterator(obj, "sync", syncMethod);
594
+ return CreateAsyncFromSyncIterator(syncIteratorRecord);
595
+ }
596
+ } else {
597
+ method = GetMethod(obj, Symbol.iterator);
598
+ }
599
+ }
600
+ if (method === undefined) {
601
+ throw new TypeError("The object is not iterable");
602
+ }
603
+ const iterator = reflectCall(method, obj, []);
604
+ if (!typeIsObject(iterator)) {
605
+ throw new TypeError("The iterator method must return an object");
606
+ }
607
+ const nextMethod = iterator.next;
608
+ return { iterator, nextMethod, done: false };
609
+ }
610
+ function IteratorNext(iteratorRecord) {
611
+ const result = reflectCall(iteratorRecord.nextMethod, iteratorRecord.iterator, []);
612
+ if (!typeIsObject(result)) {
613
+ throw new TypeError("The iterator.next() method must return an object");
614
+ }
615
+ return result;
616
+ }
617
+ function IteratorComplete(iterResult) {
618
+ return Boolean(iterResult.done);
619
+ }
620
+ function IteratorValue(iterResult) {
621
+ return iterResult.value;
622
+ }
623
+ function IsNonNegativeNumber(v) {
624
+ if (typeof v !== "number") {
625
+ return false;
626
+ }
627
+ if (NumberIsNaN(v)) {
628
+ return false;
629
+ }
630
+ if (v < 0) {
631
+ return false;
632
+ }
633
+ return true;
634
+ }
635
+ function CloneAsUint8Array(O) {
636
+ const buffer = ArrayBufferSlice(O.buffer, O.byteOffset, O.byteOffset + O.byteLength);
637
+ return new Uint8Array(buffer);
638
+ }
639
+ function DequeueValue(container) {
640
+ const pair = container._queue.shift();
641
+ container._queueTotalSize -= pair.size;
642
+ if (container._queueTotalSize < 0) {
643
+ container._queueTotalSize = 0;
644
+ }
645
+ return pair.value;
646
+ }
647
+ function EnqueueValueWithSize(container, value, size) {
648
+ if (!IsNonNegativeNumber(size) || size === Infinity) {
649
+ throw new RangeError("Size must be a finite, non-NaN, non-negative number.");
650
+ }
651
+ container._queue.push({ value, size });
652
+ container._queueTotalSize += size;
653
+ }
654
+ function PeekQueueValue(container) {
655
+ const pair = container._queue.peek();
656
+ return pair.value;
657
+ }
658
+ function ResetQueue(container) {
659
+ container._queue = new SimpleQueue;
660
+ container._queueTotalSize = 0;
661
+ }
662
+ function isDataViewConstructor(ctor) {
663
+ return ctor === DataView;
664
+ }
665
+ function isDataView(view) {
666
+ return isDataViewConstructor(view.constructor);
667
+ }
668
+ function arrayBufferViewElementSize(ctor) {
669
+ if (isDataViewConstructor(ctor)) {
670
+ return 1;
671
+ }
672
+ return ctor.BYTES_PER_ELEMENT;
673
+ }
674
+
675
+ class ReadableStreamBYOBRequest {
676
+ constructor() {
677
+ throw new TypeError("Illegal constructor");
678
+ }
679
+ get view() {
680
+ if (!IsReadableStreamBYOBRequest(this)) {
681
+ throw byobRequestBrandCheckException("view");
682
+ }
683
+ return this._view;
684
+ }
685
+ respond(bytesWritten) {
686
+ if (!IsReadableStreamBYOBRequest(this)) {
687
+ throw byobRequestBrandCheckException("respond");
688
+ }
689
+ assertRequiredArgument(bytesWritten, 1, "respond");
690
+ bytesWritten = convertUnsignedLongLongWithEnforceRange(bytesWritten, "First parameter");
691
+ if (this._associatedReadableByteStreamController === undefined) {
692
+ throw new TypeError("This BYOB request has been invalidated");
693
+ }
694
+ if (IsDetachedBuffer(this._view.buffer)) {
695
+ throw new TypeError(`The BYOB request's buffer has been detached and so cannot be used as a response`);
696
+ }
697
+ ReadableByteStreamControllerRespond(this._associatedReadableByteStreamController, bytesWritten);
698
+ }
699
+ respondWithNewView(view) {
700
+ if (!IsReadableStreamBYOBRequest(this)) {
701
+ throw byobRequestBrandCheckException("respondWithNewView");
702
+ }
703
+ assertRequiredArgument(view, 1, "respondWithNewView");
704
+ if (!ArrayBuffer.isView(view)) {
705
+ throw new TypeError("You can only respond with array buffer views");
706
+ }
707
+ if (this._associatedReadableByteStreamController === undefined) {
708
+ throw new TypeError("This BYOB request has been invalidated");
709
+ }
710
+ if (IsDetachedBuffer(view.buffer)) {
711
+ throw new TypeError("The given view's buffer has been detached and so cannot be used as a response");
712
+ }
713
+ ReadableByteStreamControllerRespondWithNewView(this._associatedReadableByteStreamController, view);
714
+ }
715
+ }
716
+ Object.defineProperties(ReadableStreamBYOBRequest.prototype, {
717
+ respond: { enumerable: true },
718
+ respondWithNewView: { enumerable: true },
719
+ view: { enumerable: true }
720
+ });
721
+ setFunctionName(ReadableStreamBYOBRequest.prototype.respond, "respond");
722
+ setFunctionName(ReadableStreamBYOBRequest.prototype.respondWithNewView, "respondWithNewView");
723
+ if (typeof Symbol.toStringTag === "symbol") {
724
+ Object.defineProperty(ReadableStreamBYOBRequest.prototype, Symbol.toStringTag, {
725
+ value: "ReadableStreamBYOBRequest",
726
+ configurable: true
727
+ });
728
+ }
729
+
730
+ class ReadableByteStreamController {
731
+ constructor() {
732
+ throw new TypeError("Illegal constructor");
733
+ }
734
+ get byobRequest() {
735
+ if (!IsReadableByteStreamController(this)) {
736
+ throw byteStreamControllerBrandCheckException("byobRequest");
737
+ }
738
+ return ReadableByteStreamControllerGetBYOBRequest(this);
739
+ }
740
+ get desiredSize() {
741
+ if (!IsReadableByteStreamController(this)) {
742
+ throw byteStreamControllerBrandCheckException("desiredSize");
743
+ }
744
+ return ReadableByteStreamControllerGetDesiredSize(this);
745
+ }
746
+ close() {
747
+ if (!IsReadableByteStreamController(this)) {
748
+ throw byteStreamControllerBrandCheckException("close");
749
+ }
750
+ if (this._closeRequested) {
751
+ throw new TypeError("The stream has already been closed; do not close it again!");
752
+ }
753
+ const state = this._controlledReadableByteStream._state;
754
+ if (state !== "readable") {
755
+ throw new TypeError(`The stream (in ${state} state) is not in the readable state and cannot be closed`);
756
+ }
757
+ ReadableByteStreamControllerClose(this);
758
+ }
759
+ enqueue(chunk) {
760
+ if (!IsReadableByteStreamController(this)) {
761
+ throw byteStreamControllerBrandCheckException("enqueue");
762
+ }
763
+ assertRequiredArgument(chunk, 1, "enqueue");
764
+ if (!ArrayBuffer.isView(chunk)) {
765
+ throw new TypeError("chunk must be an array buffer view");
766
+ }
767
+ if (chunk.byteLength === 0) {
768
+ throw new TypeError("chunk must have non-zero byteLength");
769
+ }
770
+ if (chunk.buffer.byteLength === 0) {
771
+ throw new TypeError(`chunk's buffer must have non-zero byteLength`);
772
+ }
773
+ if (this._closeRequested) {
774
+ throw new TypeError("stream is closed or draining");
775
+ }
776
+ const state = this._controlledReadableByteStream._state;
777
+ if (state !== "readable") {
778
+ throw new TypeError(`The stream (in ${state} state) is not in the readable state and cannot be enqueued to`);
779
+ }
780
+ ReadableByteStreamControllerEnqueue(this, chunk);
781
+ }
782
+ error(e = undefined) {
783
+ if (!IsReadableByteStreamController(this)) {
784
+ throw byteStreamControllerBrandCheckException("error");
785
+ }
786
+ ReadableByteStreamControllerError(this, e);
787
+ }
788
+ [CancelSteps](reason) {
789
+ ReadableByteStreamControllerClearPendingPullIntos(this);
790
+ ResetQueue(this);
791
+ const result = this._cancelAlgorithm(reason);
792
+ ReadableByteStreamControllerClearAlgorithms(this);
793
+ return result;
794
+ }
795
+ [PullSteps](readRequest) {
796
+ const stream = this._controlledReadableByteStream;
797
+ if (this._queueTotalSize > 0) {
798
+ ReadableByteStreamControllerFillReadRequestFromQueue(this, readRequest);
799
+ return;
800
+ }
801
+ const autoAllocateChunkSize = this._autoAllocateChunkSize;
802
+ if (autoAllocateChunkSize !== undefined) {
803
+ let buffer;
804
+ try {
805
+ buffer = new ArrayBuffer(autoAllocateChunkSize);
806
+ } catch (bufferE) {
807
+ readRequest._errorSteps(bufferE);
808
+ return;
809
+ }
810
+ const pullIntoDescriptor = {
811
+ buffer,
812
+ bufferByteLength: autoAllocateChunkSize,
813
+ byteOffset: 0,
814
+ byteLength: autoAllocateChunkSize,
815
+ bytesFilled: 0,
816
+ minimumFill: 1,
817
+ elementSize: 1,
818
+ viewConstructor: Uint8Array,
819
+ readerType: "default"
820
+ };
821
+ this._pendingPullIntos.push(pullIntoDescriptor);
822
+ }
823
+ ReadableStreamAddReadRequest(stream, readRequest);
824
+ ReadableByteStreamControllerCallPullIfNeeded(this);
825
+ }
826
+ [ReleaseSteps]() {
827
+ if (this._pendingPullIntos.length > 0) {
828
+ const firstPullInto = this._pendingPullIntos.peek();
829
+ firstPullInto.readerType = "none";
830
+ this._pendingPullIntos = new SimpleQueue;
831
+ this._pendingPullIntos.push(firstPullInto);
832
+ }
833
+ }
834
+ }
835
+ Object.defineProperties(ReadableByteStreamController.prototype, {
836
+ close: { enumerable: true },
837
+ enqueue: { enumerable: true },
838
+ error: { enumerable: true },
839
+ byobRequest: { enumerable: true },
840
+ desiredSize: { enumerable: true }
841
+ });
842
+ setFunctionName(ReadableByteStreamController.prototype.close, "close");
843
+ setFunctionName(ReadableByteStreamController.prototype.enqueue, "enqueue");
844
+ setFunctionName(ReadableByteStreamController.prototype.error, "error");
845
+ if (typeof Symbol.toStringTag === "symbol") {
846
+ Object.defineProperty(ReadableByteStreamController.prototype, Symbol.toStringTag, {
847
+ value: "ReadableByteStreamController",
848
+ configurable: true
849
+ });
850
+ }
851
+ function IsReadableByteStreamController(x) {
852
+ if (!typeIsObject(x)) {
853
+ return false;
854
+ }
855
+ if (!Object.prototype.hasOwnProperty.call(x, "_controlledReadableByteStream")) {
856
+ return false;
857
+ }
858
+ return x instanceof ReadableByteStreamController;
859
+ }
860
+ function IsReadableStreamBYOBRequest(x) {
861
+ if (!typeIsObject(x)) {
862
+ return false;
863
+ }
864
+ if (!Object.prototype.hasOwnProperty.call(x, "_associatedReadableByteStreamController")) {
865
+ return false;
866
+ }
867
+ return x instanceof ReadableStreamBYOBRequest;
868
+ }
869
+ function ReadableByteStreamControllerCallPullIfNeeded(controller) {
870
+ const shouldPull = ReadableByteStreamControllerShouldCallPull(controller);
871
+ if (!shouldPull) {
872
+ return;
873
+ }
874
+ if (controller._pulling) {
875
+ controller._pullAgain = true;
876
+ return;
877
+ }
878
+ controller._pulling = true;
879
+ const pullPromise = controller._pullAlgorithm();
880
+ uponPromise(pullPromise, () => {
881
+ controller._pulling = false;
882
+ if (controller._pullAgain) {
883
+ controller._pullAgain = false;
884
+ ReadableByteStreamControllerCallPullIfNeeded(controller);
885
+ }
886
+ return null;
887
+ }, (e) => {
888
+ ReadableByteStreamControllerError(controller, e);
889
+ return null;
890
+ });
891
+ }
892
+ function ReadableByteStreamControllerClearPendingPullIntos(controller) {
893
+ ReadableByteStreamControllerInvalidateBYOBRequest(controller);
894
+ controller._pendingPullIntos = new SimpleQueue;
895
+ }
896
+ function ReadableByteStreamControllerCommitPullIntoDescriptor(stream, pullIntoDescriptor) {
897
+ let done = false;
898
+ if (stream._state === "closed") {
899
+ done = true;
900
+ }
901
+ const filledView = ReadableByteStreamControllerConvertPullIntoDescriptor(pullIntoDescriptor);
902
+ if (pullIntoDescriptor.readerType === "default") {
903
+ ReadableStreamFulfillReadRequest(stream, filledView, done);
904
+ } else {
905
+ ReadableStreamFulfillReadIntoRequest(stream, filledView, done);
906
+ }
907
+ }
908
+ function ReadableByteStreamControllerConvertPullIntoDescriptor(pullIntoDescriptor) {
909
+ const bytesFilled = pullIntoDescriptor.bytesFilled;
910
+ const elementSize = pullIntoDescriptor.elementSize;
911
+ return new pullIntoDescriptor.viewConstructor(pullIntoDescriptor.buffer, pullIntoDescriptor.byteOffset, bytesFilled / elementSize);
912
+ }
913
+ function ReadableByteStreamControllerEnqueueChunkToQueue(controller, buffer, byteOffset, byteLength) {
914
+ controller._queue.push({ buffer, byteOffset, byteLength });
915
+ controller._queueTotalSize += byteLength;
916
+ }
917
+ function ReadableByteStreamControllerEnqueueClonedChunkToQueue(controller, buffer, byteOffset, byteLength) {
918
+ let clonedChunk;
919
+ try {
920
+ clonedChunk = ArrayBufferSlice(buffer, byteOffset, byteOffset + byteLength);
921
+ } catch (cloneE) {
922
+ ReadableByteStreamControllerError(controller, cloneE);
923
+ throw cloneE;
924
+ }
925
+ ReadableByteStreamControllerEnqueueChunkToQueue(controller, clonedChunk, 0, byteLength);
926
+ }
927
+ function ReadableByteStreamControllerEnqueueDetachedPullIntoToQueue(controller, firstDescriptor) {
928
+ if (firstDescriptor.bytesFilled > 0) {
929
+ ReadableByteStreamControllerEnqueueClonedChunkToQueue(controller, firstDescriptor.buffer, firstDescriptor.byteOffset, firstDescriptor.bytesFilled);
930
+ }
931
+ ReadableByteStreamControllerShiftPendingPullInto(controller);
932
+ }
933
+ function ReadableByteStreamControllerFillPullIntoDescriptorFromQueue(controller, pullIntoDescriptor) {
934
+ const maxBytesToCopy = Math.min(controller._queueTotalSize, pullIntoDescriptor.byteLength - pullIntoDescriptor.bytesFilled);
935
+ const maxBytesFilled = pullIntoDescriptor.bytesFilled + maxBytesToCopy;
936
+ let totalBytesToCopyRemaining = maxBytesToCopy;
937
+ let ready = false;
938
+ const remainderBytes = maxBytesFilled % pullIntoDescriptor.elementSize;
939
+ const maxAlignedBytes = maxBytesFilled - remainderBytes;
940
+ if (maxAlignedBytes >= pullIntoDescriptor.minimumFill) {
941
+ totalBytesToCopyRemaining = maxAlignedBytes - pullIntoDescriptor.bytesFilled;
942
+ ready = true;
943
+ }
944
+ const queue = controller._queue;
945
+ while (totalBytesToCopyRemaining > 0) {
946
+ const headOfQueue = queue.peek();
947
+ const bytesToCopy = Math.min(totalBytesToCopyRemaining, headOfQueue.byteLength);
948
+ const destStart = pullIntoDescriptor.byteOffset + pullIntoDescriptor.bytesFilled;
949
+ CopyDataBlockBytes(pullIntoDescriptor.buffer, destStart, headOfQueue.buffer, headOfQueue.byteOffset, bytesToCopy);
950
+ if (headOfQueue.byteLength === bytesToCopy) {
951
+ queue.shift();
952
+ } else {
953
+ headOfQueue.byteOffset += bytesToCopy;
954
+ headOfQueue.byteLength -= bytesToCopy;
955
+ }
956
+ controller._queueTotalSize -= bytesToCopy;
957
+ ReadableByteStreamControllerFillHeadPullIntoDescriptor(controller, bytesToCopy, pullIntoDescriptor);
958
+ totalBytesToCopyRemaining -= bytesToCopy;
959
+ }
960
+ return ready;
961
+ }
962
+ function ReadableByteStreamControllerFillHeadPullIntoDescriptor(controller, size, pullIntoDescriptor) {
963
+ pullIntoDescriptor.bytesFilled += size;
964
+ }
965
+ function ReadableByteStreamControllerHandleQueueDrain(controller) {
966
+ if (controller._queueTotalSize === 0 && controller._closeRequested) {
967
+ ReadableByteStreamControllerClearAlgorithms(controller);
968
+ ReadableStreamClose(controller._controlledReadableByteStream);
969
+ } else {
970
+ ReadableByteStreamControllerCallPullIfNeeded(controller);
971
+ }
972
+ }
973
+ function ReadableByteStreamControllerInvalidateBYOBRequest(controller) {
974
+ if (controller._byobRequest === null) {
975
+ return;
976
+ }
977
+ controller._byobRequest._associatedReadableByteStreamController = undefined;
978
+ controller._byobRequest._view = null;
979
+ controller._byobRequest = null;
980
+ }
981
+ function ReadableByteStreamControllerProcessPullIntoDescriptorsUsingQueue(controller) {
982
+ while (controller._pendingPullIntos.length > 0) {
983
+ if (controller._queueTotalSize === 0) {
984
+ return;
985
+ }
986
+ const pullIntoDescriptor = controller._pendingPullIntos.peek();
987
+ if (ReadableByteStreamControllerFillPullIntoDescriptorFromQueue(controller, pullIntoDescriptor)) {
988
+ ReadableByteStreamControllerShiftPendingPullInto(controller);
989
+ ReadableByteStreamControllerCommitPullIntoDescriptor(controller._controlledReadableByteStream, pullIntoDescriptor);
990
+ }
991
+ }
992
+ }
993
+ function ReadableByteStreamControllerProcessReadRequestsUsingQueue(controller) {
994
+ const reader = controller._controlledReadableByteStream._reader;
995
+ while (reader._readRequests.length > 0) {
996
+ if (controller._queueTotalSize === 0) {
997
+ return;
998
+ }
999
+ const readRequest = reader._readRequests.shift();
1000
+ ReadableByteStreamControllerFillReadRequestFromQueue(controller, readRequest);
1001
+ }
1002
+ }
1003
+ function ReadableByteStreamControllerPullInto(controller, view, min, readIntoRequest) {
1004
+ const stream = controller._controlledReadableByteStream;
1005
+ const ctor = view.constructor;
1006
+ const elementSize = arrayBufferViewElementSize(ctor);
1007
+ const { byteOffset, byteLength } = view;
1008
+ const minimumFill = min * elementSize;
1009
+ let buffer;
1010
+ try {
1011
+ buffer = TransferArrayBuffer(view.buffer);
1012
+ } catch (e) {
1013
+ readIntoRequest._errorSteps(e);
1014
+ return;
1015
+ }
1016
+ const pullIntoDescriptor = {
1017
+ buffer,
1018
+ bufferByteLength: buffer.byteLength,
1019
+ byteOffset,
1020
+ byteLength,
1021
+ bytesFilled: 0,
1022
+ minimumFill,
1023
+ elementSize,
1024
+ viewConstructor: ctor,
1025
+ readerType: "byob"
1026
+ };
1027
+ if (controller._pendingPullIntos.length > 0) {
1028
+ controller._pendingPullIntos.push(pullIntoDescriptor);
1029
+ ReadableStreamAddReadIntoRequest(stream, readIntoRequest);
1030
+ return;
1031
+ }
1032
+ if (stream._state === "closed") {
1033
+ const emptyView = new ctor(pullIntoDescriptor.buffer, pullIntoDescriptor.byteOffset, 0);
1034
+ readIntoRequest._closeSteps(emptyView);
1035
+ return;
1036
+ }
1037
+ if (controller._queueTotalSize > 0) {
1038
+ if (ReadableByteStreamControllerFillPullIntoDescriptorFromQueue(controller, pullIntoDescriptor)) {
1039
+ const filledView = ReadableByteStreamControllerConvertPullIntoDescriptor(pullIntoDescriptor);
1040
+ ReadableByteStreamControllerHandleQueueDrain(controller);
1041
+ readIntoRequest._chunkSteps(filledView);
1042
+ return;
1043
+ }
1044
+ if (controller._closeRequested) {
1045
+ const e = new TypeError("Insufficient bytes to fill elements in the given buffer");
1046
+ ReadableByteStreamControllerError(controller, e);
1047
+ readIntoRequest._errorSteps(e);
1048
+ return;
1049
+ }
1050
+ }
1051
+ controller._pendingPullIntos.push(pullIntoDescriptor);
1052
+ ReadableStreamAddReadIntoRequest(stream, readIntoRequest);
1053
+ ReadableByteStreamControllerCallPullIfNeeded(controller);
1054
+ }
1055
+ function ReadableByteStreamControllerRespondInClosedState(controller, firstDescriptor) {
1056
+ if (firstDescriptor.readerType === "none") {
1057
+ ReadableByteStreamControllerShiftPendingPullInto(controller);
1058
+ }
1059
+ const stream = controller._controlledReadableByteStream;
1060
+ if (ReadableStreamHasBYOBReader(stream)) {
1061
+ while (ReadableStreamGetNumReadIntoRequests(stream) > 0) {
1062
+ const pullIntoDescriptor = ReadableByteStreamControllerShiftPendingPullInto(controller);
1063
+ ReadableByteStreamControllerCommitPullIntoDescriptor(stream, pullIntoDescriptor);
1064
+ }
1065
+ }
1066
+ }
1067
+ function ReadableByteStreamControllerRespondInReadableState(controller, bytesWritten, pullIntoDescriptor) {
1068
+ ReadableByteStreamControllerFillHeadPullIntoDescriptor(controller, bytesWritten, pullIntoDescriptor);
1069
+ if (pullIntoDescriptor.readerType === "none") {
1070
+ ReadableByteStreamControllerEnqueueDetachedPullIntoToQueue(controller, pullIntoDescriptor);
1071
+ ReadableByteStreamControllerProcessPullIntoDescriptorsUsingQueue(controller);
1072
+ return;
1073
+ }
1074
+ if (pullIntoDescriptor.bytesFilled < pullIntoDescriptor.minimumFill) {
1075
+ return;
1076
+ }
1077
+ ReadableByteStreamControllerShiftPendingPullInto(controller);
1078
+ const remainderSize = pullIntoDescriptor.bytesFilled % pullIntoDescriptor.elementSize;
1079
+ if (remainderSize > 0) {
1080
+ const end = pullIntoDescriptor.byteOffset + pullIntoDescriptor.bytesFilled;
1081
+ ReadableByteStreamControllerEnqueueClonedChunkToQueue(controller, pullIntoDescriptor.buffer, end - remainderSize, remainderSize);
1082
+ }
1083
+ pullIntoDescriptor.bytesFilled -= remainderSize;
1084
+ ReadableByteStreamControllerCommitPullIntoDescriptor(controller._controlledReadableByteStream, pullIntoDescriptor);
1085
+ ReadableByteStreamControllerProcessPullIntoDescriptorsUsingQueue(controller);
1086
+ }
1087
+ function ReadableByteStreamControllerRespondInternal(controller, bytesWritten) {
1088
+ const firstDescriptor = controller._pendingPullIntos.peek();
1089
+ ReadableByteStreamControllerInvalidateBYOBRequest(controller);
1090
+ const state = controller._controlledReadableByteStream._state;
1091
+ if (state === "closed") {
1092
+ ReadableByteStreamControllerRespondInClosedState(controller, firstDescriptor);
1093
+ } else {
1094
+ ReadableByteStreamControllerRespondInReadableState(controller, bytesWritten, firstDescriptor);
1095
+ }
1096
+ ReadableByteStreamControllerCallPullIfNeeded(controller);
1097
+ }
1098
+ function ReadableByteStreamControllerShiftPendingPullInto(controller) {
1099
+ const descriptor = controller._pendingPullIntos.shift();
1100
+ return descriptor;
1101
+ }
1102
+ function ReadableByteStreamControllerShouldCallPull(controller) {
1103
+ const stream = controller._controlledReadableByteStream;
1104
+ if (stream._state !== "readable") {
1105
+ return false;
1106
+ }
1107
+ if (controller._closeRequested) {
1108
+ return false;
1109
+ }
1110
+ if (!controller._started) {
1111
+ return false;
1112
+ }
1113
+ if (ReadableStreamHasDefaultReader(stream) && ReadableStreamGetNumReadRequests(stream) > 0) {
1114
+ return true;
1115
+ }
1116
+ if (ReadableStreamHasBYOBReader(stream) && ReadableStreamGetNumReadIntoRequests(stream) > 0) {
1117
+ return true;
1118
+ }
1119
+ const desiredSize = ReadableByteStreamControllerGetDesiredSize(controller);
1120
+ if (desiredSize > 0) {
1121
+ return true;
1122
+ }
1123
+ return false;
1124
+ }
1125
+ function ReadableByteStreamControllerClearAlgorithms(controller) {
1126
+ controller._pullAlgorithm = undefined;
1127
+ controller._cancelAlgorithm = undefined;
1128
+ }
1129
+ function ReadableByteStreamControllerClose(controller) {
1130
+ const stream = controller._controlledReadableByteStream;
1131
+ if (controller._closeRequested || stream._state !== "readable") {
1132
+ return;
1133
+ }
1134
+ if (controller._queueTotalSize > 0) {
1135
+ controller._closeRequested = true;
1136
+ return;
1137
+ }
1138
+ if (controller._pendingPullIntos.length > 0) {
1139
+ const firstPendingPullInto = controller._pendingPullIntos.peek();
1140
+ if (firstPendingPullInto.bytesFilled % firstPendingPullInto.elementSize !== 0) {
1141
+ const e = new TypeError("Insufficient bytes to fill elements in the given buffer");
1142
+ ReadableByteStreamControllerError(controller, e);
1143
+ throw e;
1144
+ }
1145
+ }
1146
+ ReadableByteStreamControllerClearAlgorithms(controller);
1147
+ ReadableStreamClose(stream);
1148
+ }
1149
+ function ReadableByteStreamControllerEnqueue(controller, chunk) {
1150
+ const stream = controller._controlledReadableByteStream;
1151
+ if (controller._closeRequested || stream._state !== "readable") {
1152
+ return;
1153
+ }
1154
+ const { buffer, byteOffset, byteLength } = chunk;
1155
+ if (IsDetachedBuffer(buffer)) {
1156
+ throw new TypeError("chunk's buffer is detached and so cannot be enqueued");
1157
+ }
1158
+ const transferredBuffer = TransferArrayBuffer(buffer);
1159
+ if (controller._pendingPullIntos.length > 0) {
1160
+ const firstPendingPullInto = controller._pendingPullIntos.peek();
1161
+ if (IsDetachedBuffer(firstPendingPullInto.buffer)) {
1162
+ throw new TypeError("The BYOB request's buffer has been detached and so cannot be filled with an enqueued chunk");
1163
+ }
1164
+ ReadableByteStreamControllerInvalidateBYOBRequest(controller);
1165
+ firstPendingPullInto.buffer = TransferArrayBuffer(firstPendingPullInto.buffer);
1166
+ if (firstPendingPullInto.readerType === "none") {
1167
+ ReadableByteStreamControllerEnqueueDetachedPullIntoToQueue(controller, firstPendingPullInto);
1168
+ }
1169
+ }
1170
+ if (ReadableStreamHasDefaultReader(stream)) {
1171
+ ReadableByteStreamControllerProcessReadRequestsUsingQueue(controller);
1172
+ if (ReadableStreamGetNumReadRequests(stream) === 0) {
1173
+ ReadableByteStreamControllerEnqueueChunkToQueue(controller, transferredBuffer, byteOffset, byteLength);
1174
+ } else {
1175
+ if (controller._pendingPullIntos.length > 0) {
1176
+ ReadableByteStreamControllerShiftPendingPullInto(controller);
1177
+ }
1178
+ const transferredView = new Uint8Array(transferredBuffer, byteOffset, byteLength);
1179
+ ReadableStreamFulfillReadRequest(stream, transferredView, false);
1180
+ }
1181
+ } else if (ReadableStreamHasBYOBReader(stream)) {
1182
+ ReadableByteStreamControllerEnqueueChunkToQueue(controller, transferredBuffer, byteOffset, byteLength);
1183
+ ReadableByteStreamControllerProcessPullIntoDescriptorsUsingQueue(controller);
1184
+ } else {
1185
+ ReadableByteStreamControllerEnqueueChunkToQueue(controller, transferredBuffer, byteOffset, byteLength);
1186
+ }
1187
+ ReadableByteStreamControllerCallPullIfNeeded(controller);
1188
+ }
1189
+ function ReadableByteStreamControllerError(controller, e) {
1190
+ const stream = controller._controlledReadableByteStream;
1191
+ if (stream._state !== "readable") {
1192
+ return;
1193
+ }
1194
+ ReadableByteStreamControllerClearPendingPullIntos(controller);
1195
+ ResetQueue(controller);
1196
+ ReadableByteStreamControllerClearAlgorithms(controller);
1197
+ ReadableStreamError(stream, e);
1198
+ }
1199
+ function ReadableByteStreamControllerFillReadRequestFromQueue(controller, readRequest) {
1200
+ const entry = controller._queue.shift();
1201
+ controller._queueTotalSize -= entry.byteLength;
1202
+ ReadableByteStreamControllerHandleQueueDrain(controller);
1203
+ const view = new Uint8Array(entry.buffer, entry.byteOffset, entry.byteLength);
1204
+ readRequest._chunkSteps(view);
1205
+ }
1206
+ function ReadableByteStreamControllerGetBYOBRequest(controller) {
1207
+ if (controller._byobRequest === null && controller._pendingPullIntos.length > 0) {
1208
+ const firstDescriptor = controller._pendingPullIntos.peek();
1209
+ const view = new Uint8Array(firstDescriptor.buffer, firstDescriptor.byteOffset + firstDescriptor.bytesFilled, firstDescriptor.byteLength - firstDescriptor.bytesFilled);
1210
+ const byobRequest = Object.create(ReadableStreamBYOBRequest.prototype);
1211
+ SetUpReadableStreamBYOBRequest(byobRequest, controller, view);
1212
+ controller._byobRequest = byobRequest;
1213
+ }
1214
+ return controller._byobRequest;
1215
+ }
1216
+ function ReadableByteStreamControllerGetDesiredSize(controller) {
1217
+ const state = controller._controlledReadableByteStream._state;
1218
+ if (state === "errored") {
1219
+ return null;
1220
+ }
1221
+ if (state === "closed") {
1222
+ return 0;
1223
+ }
1224
+ return controller._strategyHWM - controller._queueTotalSize;
1225
+ }
1226
+ function ReadableByteStreamControllerRespond(controller, bytesWritten) {
1227
+ const firstDescriptor = controller._pendingPullIntos.peek();
1228
+ const state = controller._controlledReadableByteStream._state;
1229
+ if (state === "closed") {
1230
+ if (bytesWritten !== 0) {
1231
+ throw new TypeError("bytesWritten must be 0 when calling respond() on a closed stream");
1232
+ }
1233
+ } else {
1234
+ if (bytesWritten === 0) {
1235
+ throw new TypeError("bytesWritten must be greater than 0 when calling respond() on a readable stream");
1236
+ }
1237
+ if (firstDescriptor.bytesFilled + bytesWritten > firstDescriptor.byteLength) {
1238
+ throw new RangeError("bytesWritten out of range");
1239
+ }
1240
+ }
1241
+ firstDescriptor.buffer = TransferArrayBuffer(firstDescriptor.buffer);
1242
+ ReadableByteStreamControllerRespondInternal(controller, bytesWritten);
1243
+ }
1244
+ function ReadableByteStreamControllerRespondWithNewView(controller, view) {
1245
+ const firstDescriptor = controller._pendingPullIntos.peek();
1246
+ const state = controller._controlledReadableByteStream._state;
1247
+ if (state === "closed") {
1248
+ if (view.byteLength !== 0) {
1249
+ throw new TypeError("The view's length must be 0 when calling respondWithNewView() on a closed stream");
1250
+ }
1251
+ } else {
1252
+ if (view.byteLength === 0) {
1253
+ throw new TypeError("The view's length must be greater than 0 when calling respondWithNewView() on a readable stream");
1254
+ }
1255
+ }
1256
+ if (firstDescriptor.byteOffset + firstDescriptor.bytesFilled !== view.byteOffset) {
1257
+ throw new RangeError("The region specified by view does not match byobRequest");
1258
+ }
1259
+ if (firstDescriptor.bufferByteLength !== view.buffer.byteLength) {
1260
+ throw new RangeError("The buffer of view has different capacity than byobRequest");
1261
+ }
1262
+ if (firstDescriptor.bytesFilled + view.byteLength > firstDescriptor.byteLength) {
1263
+ throw new RangeError("The region specified by view is larger than byobRequest");
1264
+ }
1265
+ const viewByteLength = view.byteLength;
1266
+ firstDescriptor.buffer = TransferArrayBuffer(view.buffer);
1267
+ ReadableByteStreamControllerRespondInternal(controller, viewByteLength);
1268
+ }
1269
+ function SetUpReadableByteStreamController(stream, controller, startAlgorithm, pullAlgorithm, cancelAlgorithm, highWaterMark, autoAllocateChunkSize) {
1270
+ controller._controlledReadableByteStream = stream;
1271
+ controller._pullAgain = false;
1272
+ controller._pulling = false;
1273
+ controller._byobRequest = null;
1274
+ controller._queue = controller._queueTotalSize = undefined;
1275
+ ResetQueue(controller);
1276
+ controller._closeRequested = false;
1277
+ controller._started = false;
1278
+ controller._strategyHWM = highWaterMark;
1279
+ controller._pullAlgorithm = pullAlgorithm;
1280
+ controller._cancelAlgorithm = cancelAlgorithm;
1281
+ controller._autoAllocateChunkSize = autoAllocateChunkSize;
1282
+ controller._pendingPullIntos = new SimpleQueue;
1283
+ stream._readableStreamController = controller;
1284
+ const startResult = startAlgorithm();
1285
+ uponPromise(promiseResolvedWith(startResult), () => {
1286
+ controller._started = true;
1287
+ ReadableByteStreamControllerCallPullIfNeeded(controller);
1288
+ return null;
1289
+ }, (r) => {
1290
+ ReadableByteStreamControllerError(controller, r);
1291
+ return null;
1292
+ });
1293
+ }
1294
+ function SetUpReadableByteStreamControllerFromUnderlyingSource(stream, underlyingByteSource, highWaterMark) {
1295
+ const controller = Object.create(ReadableByteStreamController.prototype);
1296
+ let startAlgorithm;
1297
+ let pullAlgorithm;
1298
+ let cancelAlgorithm;
1299
+ if (underlyingByteSource.start !== undefined) {
1300
+ startAlgorithm = () => underlyingByteSource.start(controller);
1301
+ } else {
1302
+ startAlgorithm = () => {
1303
+ return;
1304
+ };
1305
+ }
1306
+ if (underlyingByteSource.pull !== undefined) {
1307
+ pullAlgorithm = () => underlyingByteSource.pull(controller);
1308
+ } else {
1309
+ pullAlgorithm = () => promiseResolvedWith(undefined);
1310
+ }
1311
+ if (underlyingByteSource.cancel !== undefined) {
1312
+ cancelAlgorithm = (reason) => underlyingByteSource.cancel(reason);
1313
+ } else {
1314
+ cancelAlgorithm = () => promiseResolvedWith(undefined);
1315
+ }
1316
+ const autoAllocateChunkSize = underlyingByteSource.autoAllocateChunkSize;
1317
+ if (autoAllocateChunkSize === 0) {
1318
+ throw new TypeError("autoAllocateChunkSize must be greater than 0");
1319
+ }
1320
+ SetUpReadableByteStreamController(stream, controller, startAlgorithm, pullAlgorithm, cancelAlgorithm, highWaterMark, autoAllocateChunkSize);
1321
+ }
1322
+ function SetUpReadableStreamBYOBRequest(request, controller, view) {
1323
+ request._associatedReadableByteStreamController = controller;
1324
+ request._view = view;
1325
+ }
1326
+ function byobRequestBrandCheckException(name) {
1327
+ return new TypeError(`ReadableStreamBYOBRequest.prototype.${name} can only be used on a ReadableStreamBYOBRequest`);
1328
+ }
1329
+ function byteStreamControllerBrandCheckException(name) {
1330
+ return new TypeError(`ReadableByteStreamController.prototype.${name} can only be used on a ReadableByteStreamController`);
1331
+ }
1332
+ function convertReaderOptions(options, context) {
1333
+ assertDictionary(options, context);
1334
+ const mode = options === null || options === undefined ? undefined : options.mode;
1335
+ return {
1336
+ mode: mode === undefined ? undefined : convertReadableStreamReaderMode(mode, `${context} has member 'mode' that`)
1337
+ };
1338
+ }
1339
+ function convertReadableStreamReaderMode(mode, context) {
1340
+ mode = `${mode}`;
1341
+ if (mode !== "byob") {
1342
+ throw new TypeError(`${context} '${mode}' is not a valid enumeration value for ReadableStreamReaderMode`);
1343
+ }
1344
+ return mode;
1345
+ }
1346
+ function convertByobReadOptions(options, context) {
1347
+ var _a2;
1348
+ assertDictionary(options, context);
1349
+ const min = (_a2 = options === null || options === undefined ? undefined : options.min) !== null && _a2 !== undefined ? _a2 : 1;
1350
+ return {
1351
+ min: convertUnsignedLongLongWithEnforceRange(min, `${context} has member 'min' that`)
1352
+ };
1353
+ }
1354
+ function AcquireReadableStreamBYOBReader(stream) {
1355
+ return new ReadableStreamBYOBReader(stream);
1356
+ }
1357
+ function ReadableStreamAddReadIntoRequest(stream, readIntoRequest) {
1358
+ stream._reader._readIntoRequests.push(readIntoRequest);
1359
+ }
1360
+ function ReadableStreamFulfillReadIntoRequest(stream, chunk, done) {
1361
+ const reader = stream._reader;
1362
+ const readIntoRequest = reader._readIntoRequests.shift();
1363
+ if (done) {
1364
+ readIntoRequest._closeSteps(chunk);
1365
+ } else {
1366
+ readIntoRequest._chunkSteps(chunk);
1367
+ }
1368
+ }
1369
+ function ReadableStreamGetNumReadIntoRequests(stream) {
1370
+ return stream._reader._readIntoRequests.length;
1371
+ }
1372
+ function ReadableStreamHasBYOBReader(stream) {
1373
+ const reader = stream._reader;
1374
+ if (reader === undefined) {
1375
+ return false;
1376
+ }
1377
+ if (!IsReadableStreamBYOBReader(reader)) {
1378
+ return false;
1379
+ }
1380
+ return true;
1381
+ }
1382
+
1383
+ class ReadableStreamBYOBReader {
1384
+ constructor(stream) {
1385
+ assertRequiredArgument(stream, 1, "ReadableStreamBYOBReader");
1386
+ assertReadableStream(stream, "First parameter");
1387
+ if (IsReadableStreamLocked(stream)) {
1388
+ throw new TypeError("This stream has already been locked for exclusive reading by another reader");
1389
+ }
1390
+ if (!IsReadableByteStreamController(stream._readableStreamController)) {
1391
+ throw new TypeError("Cannot construct a ReadableStreamBYOBReader for a stream not constructed with a byte " + "source");
1392
+ }
1393
+ ReadableStreamReaderGenericInitialize(this, stream);
1394
+ this._readIntoRequests = new SimpleQueue;
1395
+ }
1396
+ get closed() {
1397
+ if (!IsReadableStreamBYOBReader(this)) {
1398
+ return promiseRejectedWith(byobReaderBrandCheckException("closed"));
1399
+ }
1400
+ return this._closedPromise;
1401
+ }
1402
+ cancel(reason = undefined) {
1403
+ if (!IsReadableStreamBYOBReader(this)) {
1404
+ return promiseRejectedWith(byobReaderBrandCheckException("cancel"));
1405
+ }
1406
+ if (this._ownerReadableStream === undefined) {
1407
+ return promiseRejectedWith(readerLockException("cancel"));
1408
+ }
1409
+ return ReadableStreamReaderGenericCancel(this, reason);
1410
+ }
1411
+ read(view, rawOptions = {}) {
1412
+ if (!IsReadableStreamBYOBReader(this)) {
1413
+ return promiseRejectedWith(byobReaderBrandCheckException("read"));
1414
+ }
1415
+ if (!ArrayBuffer.isView(view)) {
1416
+ return promiseRejectedWith(new TypeError("view must be an array buffer view"));
1417
+ }
1418
+ if (view.byteLength === 0) {
1419
+ return promiseRejectedWith(new TypeError("view must have non-zero byteLength"));
1420
+ }
1421
+ if (view.buffer.byteLength === 0) {
1422
+ return promiseRejectedWith(new TypeError(`view's buffer must have non-zero byteLength`));
1423
+ }
1424
+ if (IsDetachedBuffer(view.buffer)) {
1425
+ return promiseRejectedWith(new TypeError("view's buffer has been detached"));
1426
+ }
1427
+ let options;
1428
+ try {
1429
+ options = convertByobReadOptions(rawOptions, "options");
1430
+ } catch (e) {
1431
+ return promiseRejectedWith(e);
1432
+ }
1433
+ const min = options.min;
1434
+ if (min === 0) {
1435
+ return promiseRejectedWith(new TypeError("options.min must be greater than 0"));
1436
+ }
1437
+ if (!isDataView(view)) {
1438
+ if (min > view.length) {
1439
+ return promiseRejectedWith(new RangeError("options.min must be less than or equal to view's length"));
1440
+ }
1441
+ } else if (min > view.byteLength) {
1442
+ return promiseRejectedWith(new RangeError("options.min must be less than or equal to view's byteLength"));
1443
+ }
1444
+ if (this._ownerReadableStream === undefined) {
1445
+ return promiseRejectedWith(readerLockException("read from"));
1446
+ }
1447
+ let resolvePromise;
1448
+ let rejectPromise;
1449
+ const promise = newPromise((resolve, reject) => {
1450
+ resolvePromise = resolve;
1451
+ rejectPromise = reject;
1452
+ });
1453
+ const readIntoRequest = {
1454
+ _chunkSteps: (chunk) => resolvePromise({ value: chunk, done: false }),
1455
+ _closeSteps: (chunk) => resolvePromise({ value: chunk, done: true }),
1456
+ _errorSteps: (e) => rejectPromise(e)
1457
+ };
1458
+ ReadableStreamBYOBReaderRead(this, view, min, readIntoRequest);
1459
+ return promise;
1460
+ }
1461
+ releaseLock() {
1462
+ if (!IsReadableStreamBYOBReader(this)) {
1463
+ throw byobReaderBrandCheckException("releaseLock");
1464
+ }
1465
+ if (this._ownerReadableStream === undefined) {
1466
+ return;
1467
+ }
1468
+ ReadableStreamBYOBReaderRelease(this);
1469
+ }
1470
+ }
1471
+ Object.defineProperties(ReadableStreamBYOBReader.prototype, {
1472
+ cancel: { enumerable: true },
1473
+ read: { enumerable: true },
1474
+ releaseLock: { enumerable: true },
1475
+ closed: { enumerable: true }
1476
+ });
1477
+ setFunctionName(ReadableStreamBYOBReader.prototype.cancel, "cancel");
1478
+ setFunctionName(ReadableStreamBYOBReader.prototype.read, "read");
1479
+ setFunctionName(ReadableStreamBYOBReader.prototype.releaseLock, "releaseLock");
1480
+ if (typeof Symbol.toStringTag === "symbol") {
1481
+ Object.defineProperty(ReadableStreamBYOBReader.prototype, Symbol.toStringTag, {
1482
+ value: "ReadableStreamBYOBReader",
1483
+ configurable: true
1484
+ });
1485
+ }
1486
+ function IsReadableStreamBYOBReader(x) {
1487
+ if (!typeIsObject(x)) {
1488
+ return false;
1489
+ }
1490
+ if (!Object.prototype.hasOwnProperty.call(x, "_readIntoRequests")) {
1491
+ return false;
1492
+ }
1493
+ return x instanceof ReadableStreamBYOBReader;
1494
+ }
1495
+ function ReadableStreamBYOBReaderRead(reader, view, min, readIntoRequest) {
1496
+ const stream = reader._ownerReadableStream;
1497
+ stream._disturbed = true;
1498
+ if (stream._state === "errored") {
1499
+ readIntoRequest._errorSteps(stream._storedError);
1500
+ } else {
1501
+ ReadableByteStreamControllerPullInto(stream._readableStreamController, view, min, readIntoRequest);
1502
+ }
1503
+ }
1504
+ function ReadableStreamBYOBReaderRelease(reader) {
1505
+ ReadableStreamReaderGenericRelease(reader);
1506
+ const e = new TypeError("Reader was released");
1507
+ ReadableStreamBYOBReaderErrorReadIntoRequests(reader, e);
1508
+ }
1509
+ function ReadableStreamBYOBReaderErrorReadIntoRequests(reader, e) {
1510
+ const readIntoRequests = reader._readIntoRequests;
1511
+ reader._readIntoRequests = new SimpleQueue;
1512
+ readIntoRequests.forEach((readIntoRequest) => {
1513
+ readIntoRequest._errorSteps(e);
1514
+ });
1515
+ }
1516
+ function byobReaderBrandCheckException(name) {
1517
+ return new TypeError(`ReadableStreamBYOBReader.prototype.${name} can only be used on a ReadableStreamBYOBReader`);
1518
+ }
1519
+ function ExtractHighWaterMark(strategy, defaultHWM) {
1520
+ const { highWaterMark } = strategy;
1521
+ if (highWaterMark === undefined) {
1522
+ return defaultHWM;
1523
+ }
1524
+ if (NumberIsNaN(highWaterMark) || highWaterMark < 0) {
1525
+ throw new RangeError("Invalid highWaterMark");
1526
+ }
1527
+ return highWaterMark;
1528
+ }
1529
+ function ExtractSizeAlgorithm(strategy) {
1530
+ const { size } = strategy;
1531
+ if (!size) {
1532
+ return () => 1;
1533
+ }
1534
+ return size;
1535
+ }
1536
+ function convertQueuingStrategy(init, context) {
1537
+ assertDictionary(init, context);
1538
+ const highWaterMark = init === null || init === undefined ? undefined : init.highWaterMark;
1539
+ const size = init === null || init === undefined ? undefined : init.size;
1540
+ return {
1541
+ highWaterMark: highWaterMark === undefined ? undefined : convertUnrestrictedDouble(highWaterMark),
1542
+ size: size === undefined ? undefined : convertQueuingStrategySize(size, `${context} has member 'size' that`)
1543
+ };
1544
+ }
1545
+ function convertQueuingStrategySize(fn, context) {
1546
+ assertFunction(fn, context);
1547
+ return (chunk) => convertUnrestrictedDouble(fn(chunk));
1548
+ }
1549
+ function convertUnderlyingSink(original, context) {
1550
+ assertDictionary(original, context);
1551
+ const abort = original === null || original === undefined ? undefined : original.abort;
1552
+ const close = original === null || original === undefined ? undefined : original.close;
1553
+ const start = original === null || original === undefined ? undefined : original.start;
1554
+ const type = original === null || original === undefined ? undefined : original.type;
1555
+ const write = original === null || original === undefined ? undefined : original.write;
1556
+ return {
1557
+ abort: abort === undefined ? undefined : convertUnderlyingSinkAbortCallback(abort, original, `${context} has member 'abort' that`),
1558
+ close: close === undefined ? undefined : convertUnderlyingSinkCloseCallback(close, original, `${context} has member 'close' that`),
1559
+ start: start === undefined ? undefined : convertUnderlyingSinkStartCallback(start, original, `${context} has member 'start' that`),
1560
+ write: write === undefined ? undefined : convertUnderlyingSinkWriteCallback(write, original, `${context} has member 'write' that`),
1561
+ type
1562
+ };
1563
+ }
1564
+ function convertUnderlyingSinkAbortCallback(fn, original, context) {
1565
+ assertFunction(fn, context);
1566
+ return (reason) => promiseCall(fn, original, [reason]);
1567
+ }
1568
+ function convertUnderlyingSinkCloseCallback(fn, original, context) {
1569
+ assertFunction(fn, context);
1570
+ return () => promiseCall(fn, original, []);
1571
+ }
1572
+ function convertUnderlyingSinkStartCallback(fn, original, context) {
1573
+ assertFunction(fn, context);
1574
+ return (controller) => reflectCall(fn, original, [controller]);
1575
+ }
1576
+ function convertUnderlyingSinkWriteCallback(fn, original, context) {
1577
+ assertFunction(fn, context);
1578
+ return (chunk, controller) => promiseCall(fn, original, [chunk, controller]);
1579
+ }
1580
+ function assertWritableStream(x, context) {
1581
+ if (!IsWritableStream(x)) {
1582
+ throw new TypeError(`${context} is not a WritableStream.`);
1583
+ }
1584
+ }
1585
+ function isAbortSignal(value) {
1586
+ if (typeof value !== "object" || value === null) {
1587
+ return false;
1588
+ }
1589
+ try {
1590
+ return typeof value.aborted === "boolean";
1591
+ } catch (_a2) {
1592
+ return false;
1593
+ }
1594
+ }
1595
+ const supportsAbortController = typeof AbortController === "function";
1596
+ function createAbortController() {
1597
+ if (supportsAbortController) {
1598
+ return new AbortController;
1599
+ }
1600
+ return;
1601
+ }
1602
+
1603
+ class WritableStream {
1604
+ constructor(rawUnderlyingSink = {}, rawStrategy = {}) {
1605
+ if (rawUnderlyingSink === undefined) {
1606
+ rawUnderlyingSink = null;
1607
+ } else {
1608
+ assertObject(rawUnderlyingSink, "First parameter");
1609
+ }
1610
+ const strategy = convertQueuingStrategy(rawStrategy, "Second parameter");
1611
+ const underlyingSink = convertUnderlyingSink(rawUnderlyingSink, "First parameter");
1612
+ InitializeWritableStream(this);
1613
+ const type = underlyingSink.type;
1614
+ if (type !== undefined) {
1615
+ throw new RangeError("Invalid type is specified");
1616
+ }
1617
+ const sizeAlgorithm = ExtractSizeAlgorithm(strategy);
1618
+ const highWaterMark = ExtractHighWaterMark(strategy, 1);
1619
+ SetUpWritableStreamDefaultControllerFromUnderlyingSink(this, underlyingSink, highWaterMark, sizeAlgorithm);
1620
+ }
1621
+ get locked() {
1622
+ if (!IsWritableStream(this)) {
1623
+ throw streamBrandCheckException$2("locked");
1624
+ }
1625
+ return IsWritableStreamLocked(this);
1626
+ }
1627
+ abort(reason = undefined) {
1628
+ if (!IsWritableStream(this)) {
1629
+ return promiseRejectedWith(streamBrandCheckException$2("abort"));
1630
+ }
1631
+ if (IsWritableStreamLocked(this)) {
1632
+ return promiseRejectedWith(new TypeError("Cannot abort a stream that already has a writer"));
1633
+ }
1634
+ return WritableStreamAbort(this, reason);
1635
+ }
1636
+ close() {
1637
+ if (!IsWritableStream(this)) {
1638
+ return promiseRejectedWith(streamBrandCheckException$2("close"));
1639
+ }
1640
+ if (IsWritableStreamLocked(this)) {
1641
+ return promiseRejectedWith(new TypeError("Cannot close a stream that already has a writer"));
1642
+ }
1643
+ if (WritableStreamCloseQueuedOrInFlight(this)) {
1644
+ return promiseRejectedWith(new TypeError("Cannot close an already-closing stream"));
1645
+ }
1646
+ return WritableStreamClose(this);
1647
+ }
1648
+ getWriter() {
1649
+ if (!IsWritableStream(this)) {
1650
+ throw streamBrandCheckException$2("getWriter");
1651
+ }
1652
+ return AcquireWritableStreamDefaultWriter(this);
1653
+ }
1654
+ }
1655
+ Object.defineProperties(WritableStream.prototype, {
1656
+ abort: { enumerable: true },
1657
+ close: { enumerable: true },
1658
+ getWriter: { enumerable: true },
1659
+ locked: { enumerable: true }
1660
+ });
1661
+ setFunctionName(WritableStream.prototype.abort, "abort");
1662
+ setFunctionName(WritableStream.prototype.close, "close");
1663
+ setFunctionName(WritableStream.prototype.getWriter, "getWriter");
1664
+ if (typeof Symbol.toStringTag === "symbol") {
1665
+ Object.defineProperty(WritableStream.prototype, Symbol.toStringTag, {
1666
+ value: "WritableStream",
1667
+ configurable: true
1668
+ });
1669
+ }
1670
+ function AcquireWritableStreamDefaultWriter(stream) {
1671
+ return new WritableStreamDefaultWriter(stream);
1672
+ }
1673
+ function CreateWritableStream(startAlgorithm, writeAlgorithm, closeAlgorithm, abortAlgorithm, highWaterMark = 1, sizeAlgorithm = () => 1) {
1674
+ const stream = Object.create(WritableStream.prototype);
1675
+ InitializeWritableStream(stream);
1676
+ const controller = Object.create(WritableStreamDefaultController.prototype);
1677
+ SetUpWritableStreamDefaultController(stream, controller, startAlgorithm, writeAlgorithm, closeAlgorithm, abortAlgorithm, highWaterMark, sizeAlgorithm);
1678
+ return stream;
1679
+ }
1680
+ function InitializeWritableStream(stream) {
1681
+ stream._state = "writable";
1682
+ stream._storedError = undefined;
1683
+ stream._writer = undefined;
1684
+ stream._writableStreamController = undefined;
1685
+ stream._writeRequests = new SimpleQueue;
1686
+ stream._inFlightWriteRequest = undefined;
1687
+ stream._closeRequest = undefined;
1688
+ stream._inFlightCloseRequest = undefined;
1689
+ stream._pendingAbortRequest = undefined;
1690
+ stream._backpressure = false;
1691
+ }
1692
+ function IsWritableStream(x) {
1693
+ if (!typeIsObject(x)) {
1694
+ return false;
1695
+ }
1696
+ if (!Object.prototype.hasOwnProperty.call(x, "_writableStreamController")) {
1697
+ return false;
1698
+ }
1699
+ return x instanceof WritableStream;
1700
+ }
1701
+ function IsWritableStreamLocked(stream) {
1702
+ if (stream._writer === undefined) {
1703
+ return false;
1704
+ }
1705
+ return true;
1706
+ }
1707
+ function WritableStreamAbort(stream, reason) {
1708
+ var _a2;
1709
+ if (stream._state === "closed" || stream._state === "errored") {
1710
+ return promiseResolvedWith(undefined);
1711
+ }
1712
+ stream._writableStreamController._abortReason = reason;
1713
+ (_a2 = stream._writableStreamController._abortController) === null || _a2 === undefined || _a2.abort(reason);
1714
+ const state = stream._state;
1715
+ if (state === "closed" || state === "errored") {
1716
+ return promiseResolvedWith(undefined);
1717
+ }
1718
+ if (stream._pendingAbortRequest !== undefined) {
1719
+ return stream._pendingAbortRequest._promise;
1720
+ }
1721
+ let wasAlreadyErroring = false;
1722
+ if (state === "erroring") {
1723
+ wasAlreadyErroring = true;
1724
+ reason = undefined;
1725
+ }
1726
+ const promise = newPromise((resolve, reject) => {
1727
+ stream._pendingAbortRequest = {
1728
+ _promise: undefined,
1729
+ _resolve: resolve,
1730
+ _reject: reject,
1731
+ _reason: reason,
1732
+ _wasAlreadyErroring: wasAlreadyErroring
1733
+ };
1734
+ });
1735
+ stream._pendingAbortRequest._promise = promise;
1736
+ if (!wasAlreadyErroring) {
1737
+ WritableStreamStartErroring(stream, reason);
1738
+ }
1739
+ return promise;
1740
+ }
1741
+ function WritableStreamClose(stream) {
1742
+ const state = stream._state;
1743
+ if (state === "closed" || state === "errored") {
1744
+ return promiseRejectedWith(new TypeError(`The stream (in ${state} state) is not in the writable state and cannot be closed`));
1745
+ }
1746
+ const promise = newPromise((resolve, reject) => {
1747
+ const closeRequest = {
1748
+ _resolve: resolve,
1749
+ _reject: reject
1750
+ };
1751
+ stream._closeRequest = closeRequest;
1752
+ });
1753
+ const writer = stream._writer;
1754
+ if (writer !== undefined && stream._backpressure && state === "writable") {
1755
+ defaultWriterReadyPromiseResolve(writer);
1756
+ }
1757
+ WritableStreamDefaultControllerClose(stream._writableStreamController);
1758
+ return promise;
1759
+ }
1760
+ function WritableStreamAddWriteRequest(stream) {
1761
+ const promise = newPromise((resolve, reject) => {
1762
+ const writeRequest = {
1763
+ _resolve: resolve,
1764
+ _reject: reject
1765
+ };
1766
+ stream._writeRequests.push(writeRequest);
1767
+ });
1768
+ return promise;
1769
+ }
1770
+ function WritableStreamDealWithRejection(stream, error) {
1771
+ const state = stream._state;
1772
+ if (state === "writable") {
1773
+ WritableStreamStartErroring(stream, error);
1774
+ return;
1775
+ }
1776
+ WritableStreamFinishErroring(stream);
1777
+ }
1778
+ function WritableStreamStartErroring(stream, reason) {
1779
+ const controller = stream._writableStreamController;
1780
+ stream._state = "erroring";
1781
+ stream._storedError = reason;
1782
+ const writer = stream._writer;
1783
+ if (writer !== undefined) {
1784
+ WritableStreamDefaultWriterEnsureReadyPromiseRejected(writer, reason);
1785
+ }
1786
+ if (!WritableStreamHasOperationMarkedInFlight(stream) && controller._started) {
1787
+ WritableStreamFinishErroring(stream);
1788
+ }
1789
+ }
1790
+ function WritableStreamFinishErroring(stream) {
1791
+ stream._state = "errored";
1792
+ stream._writableStreamController[ErrorSteps]();
1793
+ const storedError = stream._storedError;
1794
+ stream._writeRequests.forEach((writeRequest) => {
1795
+ writeRequest._reject(storedError);
1796
+ });
1797
+ stream._writeRequests = new SimpleQueue;
1798
+ if (stream._pendingAbortRequest === undefined) {
1799
+ WritableStreamRejectCloseAndClosedPromiseIfNeeded(stream);
1800
+ return;
1801
+ }
1802
+ const abortRequest = stream._pendingAbortRequest;
1803
+ stream._pendingAbortRequest = undefined;
1804
+ if (abortRequest._wasAlreadyErroring) {
1805
+ abortRequest._reject(storedError);
1806
+ WritableStreamRejectCloseAndClosedPromiseIfNeeded(stream);
1807
+ return;
1808
+ }
1809
+ const promise = stream._writableStreamController[AbortSteps](abortRequest._reason);
1810
+ uponPromise(promise, () => {
1811
+ abortRequest._resolve();
1812
+ WritableStreamRejectCloseAndClosedPromiseIfNeeded(stream);
1813
+ return null;
1814
+ }, (reason) => {
1815
+ abortRequest._reject(reason);
1816
+ WritableStreamRejectCloseAndClosedPromiseIfNeeded(stream);
1817
+ return null;
1818
+ });
1819
+ }
1820
+ function WritableStreamFinishInFlightWrite(stream) {
1821
+ stream._inFlightWriteRequest._resolve(undefined);
1822
+ stream._inFlightWriteRequest = undefined;
1823
+ }
1824
+ function WritableStreamFinishInFlightWriteWithError(stream, error) {
1825
+ stream._inFlightWriteRequest._reject(error);
1826
+ stream._inFlightWriteRequest = undefined;
1827
+ WritableStreamDealWithRejection(stream, error);
1828
+ }
1829
+ function WritableStreamFinishInFlightClose(stream) {
1830
+ stream._inFlightCloseRequest._resolve(undefined);
1831
+ stream._inFlightCloseRequest = undefined;
1832
+ const state = stream._state;
1833
+ if (state === "erroring") {
1834
+ stream._storedError = undefined;
1835
+ if (stream._pendingAbortRequest !== undefined) {
1836
+ stream._pendingAbortRequest._resolve();
1837
+ stream._pendingAbortRequest = undefined;
1838
+ }
1839
+ }
1840
+ stream._state = "closed";
1841
+ const writer = stream._writer;
1842
+ if (writer !== undefined) {
1843
+ defaultWriterClosedPromiseResolve(writer);
1844
+ }
1845
+ }
1846
+ function WritableStreamFinishInFlightCloseWithError(stream, error) {
1847
+ stream._inFlightCloseRequest._reject(error);
1848
+ stream._inFlightCloseRequest = undefined;
1849
+ if (stream._pendingAbortRequest !== undefined) {
1850
+ stream._pendingAbortRequest._reject(error);
1851
+ stream._pendingAbortRequest = undefined;
1852
+ }
1853
+ WritableStreamDealWithRejection(stream, error);
1854
+ }
1855
+ function WritableStreamCloseQueuedOrInFlight(stream) {
1856
+ if (stream._closeRequest === undefined && stream._inFlightCloseRequest === undefined) {
1857
+ return false;
1858
+ }
1859
+ return true;
1860
+ }
1861
+ function WritableStreamHasOperationMarkedInFlight(stream) {
1862
+ if (stream._inFlightWriteRequest === undefined && stream._inFlightCloseRequest === undefined) {
1863
+ return false;
1864
+ }
1865
+ return true;
1866
+ }
1867
+ function WritableStreamMarkCloseRequestInFlight(stream) {
1868
+ stream._inFlightCloseRequest = stream._closeRequest;
1869
+ stream._closeRequest = undefined;
1870
+ }
1871
+ function WritableStreamMarkFirstWriteRequestInFlight(stream) {
1872
+ stream._inFlightWriteRequest = stream._writeRequests.shift();
1873
+ }
1874
+ function WritableStreamRejectCloseAndClosedPromiseIfNeeded(stream) {
1875
+ if (stream._closeRequest !== undefined) {
1876
+ stream._closeRequest._reject(stream._storedError);
1877
+ stream._closeRequest = undefined;
1878
+ }
1879
+ const writer = stream._writer;
1880
+ if (writer !== undefined) {
1881
+ defaultWriterClosedPromiseReject(writer, stream._storedError);
1882
+ }
1883
+ }
1884
+ function WritableStreamUpdateBackpressure(stream, backpressure) {
1885
+ const writer = stream._writer;
1886
+ if (writer !== undefined && backpressure !== stream._backpressure) {
1887
+ if (backpressure) {
1888
+ defaultWriterReadyPromiseReset(writer);
1889
+ } else {
1890
+ defaultWriterReadyPromiseResolve(writer);
1891
+ }
1892
+ }
1893
+ stream._backpressure = backpressure;
1894
+ }
1895
+
1896
+ class WritableStreamDefaultWriter {
1897
+ constructor(stream) {
1898
+ assertRequiredArgument(stream, 1, "WritableStreamDefaultWriter");
1899
+ assertWritableStream(stream, "First parameter");
1900
+ if (IsWritableStreamLocked(stream)) {
1901
+ throw new TypeError("This stream has already been locked for exclusive writing by another writer");
1902
+ }
1903
+ this._ownerWritableStream = stream;
1904
+ stream._writer = this;
1905
+ const state = stream._state;
1906
+ if (state === "writable") {
1907
+ if (!WritableStreamCloseQueuedOrInFlight(stream) && stream._backpressure) {
1908
+ defaultWriterReadyPromiseInitialize(this);
1909
+ } else {
1910
+ defaultWriterReadyPromiseInitializeAsResolved(this);
1911
+ }
1912
+ defaultWriterClosedPromiseInitialize(this);
1913
+ } else if (state === "erroring") {
1914
+ defaultWriterReadyPromiseInitializeAsRejected(this, stream._storedError);
1915
+ defaultWriterClosedPromiseInitialize(this);
1916
+ } else if (state === "closed") {
1917
+ defaultWriterReadyPromiseInitializeAsResolved(this);
1918
+ defaultWriterClosedPromiseInitializeAsResolved(this);
1919
+ } else {
1920
+ const storedError = stream._storedError;
1921
+ defaultWriterReadyPromiseInitializeAsRejected(this, storedError);
1922
+ defaultWriterClosedPromiseInitializeAsRejected(this, storedError);
1923
+ }
1924
+ }
1925
+ get closed() {
1926
+ if (!IsWritableStreamDefaultWriter(this)) {
1927
+ return promiseRejectedWith(defaultWriterBrandCheckException("closed"));
1928
+ }
1929
+ return this._closedPromise;
1930
+ }
1931
+ get desiredSize() {
1932
+ if (!IsWritableStreamDefaultWriter(this)) {
1933
+ throw defaultWriterBrandCheckException("desiredSize");
1934
+ }
1935
+ if (this._ownerWritableStream === undefined) {
1936
+ throw defaultWriterLockException("desiredSize");
1937
+ }
1938
+ return WritableStreamDefaultWriterGetDesiredSize(this);
1939
+ }
1940
+ get ready() {
1941
+ if (!IsWritableStreamDefaultWriter(this)) {
1942
+ return promiseRejectedWith(defaultWriterBrandCheckException("ready"));
1943
+ }
1944
+ return this._readyPromise;
1945
+ }
1946
+ abort(reason = undefined) {
1947
+ if (!IsWritableStreamDefaultWriter(this)) {
1948
+ return promiseRejectedWith(defaultWriterBrandCheckException("abort"));
1949
+ }
1950
+ if (this._ownerWritableStream === undefined) {
1951
+ return promiseRejectedWith(defaultWriterLockException("abort"));
1952
+ }
1953
+ return WritableStreamDefaultWriterAbort(this, reason);
1954
+ }
1955
+ close() {
1956
+ if (!IsWritableStreamDefaultWriter(this)) {
1957
+ return promiseRejectedWith(defaultWriterBrandCheckException("close"));
1958
+ }
1959
+ const stream = this._ownerWritableStream;
1960
+ if (stream === undefined) {
1961
+ return promiseRejectedWith(defaultWriterLockException("close"));
1962
+ }
1963
+ if (WritableStreamCloseQueuedOrInFlight(stream)) {
1964
+ return promiseRejectedWith(new TypeError("Cannot close an already-closing stream"));
1965
+ }
1966
+ return WritableStreamDefaultWriterClose(this);
1967
+ }
1968
+ releaseLock() {
1969
+ if (!IsWritableStreamDefaultWriter(this)) {
1970
+ throw defaultWriterBrandCheckException("releaseLock");
1971
+ }
1972
+ const stream = this._ownerWritableStream;
1973
+ if (stream === undefined) {
1974
+ return;
1975
+ }
1976
+ WritableStreamDefaultWriterRelease(this);
1977
+ }
1978
+ write(chunk = undefined) {
1979
+ if (!IsWritableStreamDefaultWriter(this)) {
1980
+ return promiseRejectedWith(defaultWriterBrandCheckException("write"));
1981
+ }
1982
+ if (this._ownerWritableStream === undefined) {
1983
+ return promiseRejectedWith(defaultWriterLockException("write to"));
1984
+ }
1985
+ return WritableStreamDefaultWriterWrite(this, chunk);
1986
+ }
1987
+ }
1988
+ Object.defineProperties(WritableStreamDefaultWriter.prototype, {
1989
+ abort: { enumerable: true },
1990
+ close: { enumerable: true },
1991
+ releaseLock: { enumerable: true },
1992
+ write: { enumerable: true },
1993
+ closed: { enumerable: true },
1994
+ desiredSize: { enumerable: true },
1995
+ ready: { enumerable: true }
1996
+ });
1997
+ setFunctionName(WritableStreamDefaultWriter.prototype.abort, "abort");
1998
+ setFunctionName(WritableStreamDefaultWriter.prototype.close, "close");
1999
+ setFunctionName(WritableStreamDefaultWriter.prototype.releaseLock, "releaseLock");
2000
+ setFunctionName(WritableStreamDefaultWriter.prototype.write, "write");
2001
+ if (typeof Symbol.toStringTag === "symbol") {
2002
+ Object.defineProperty(WritableStreamDefaultWriter.prototype, Symbol.toStringTag, {
2003
+ value: "WritableStreamDefaultWriter",
2004
+ configurable: true
2005
+ });
2006
+ }
2007
+ function IsWritableStreamDefaultWriter(x) {
2008
+ if (!typeIsObject(x)) {
2009
+ return false;
2010
+ }
2011
+ if (!Object.prototype.hasOwnProperty.call(x, "_ownerWritableStream")) {
2012
+ return false;
2013
+ }
2014
+ return x instanceof WritableStreamDefaultWriter;
2015
+ }
2016
+ function WritableStreamDefaultWriterAbort(writer, reason) {
2017
+ const stream = writer._ownerWritableStream;
2018
+ return WritableStreamAbort(stream, reason);
2019
+ }
2020
+ function WritableStreamDefaultWriterClose(writer) {
2021
+ const stream = writer._ownerWritableStream;
2022
+ return WritableStreamClose(stream);
2023
+ }
2024
+ function WritableStreamDefaultWriterCloseWithErrorPropagation(writer) {
2025
+ const stream = writer._ownerWritableStream;
2026
+ const state = stream._state;
2027
+ if (WritableStreamCloseQueuedOrInFlight(stream) || state === "closed") {
2028
+ return promiseResolvedWith(undefined);
2029
+ }
2030
+ if (state === "errored") {
2031
+ return promiseRejectedWith(stream._storedError);
2032
+ }
2033
+ return WritableStreamDefaultWriterClose(writer);
2034
+ }
2035
+ function WritableStreamDefaultWriterEnsureClosedPromiseRejected(writer, error) {
2036
+ if (writer._closedPromiseState === "pending") {
2037
+ defaultWriterClosedPromiseReject(writer, error);
2038
+ } else {
2039
+ defaultWriterClosedPromiseResetToRejected(writer, error);
2040
+ }
2041
+ }
2042
+ function WritableStreamDefaultWriterEnsureReadyPromiseRejected(writer, error) {
2043
+ if (writer._readyPromiseState === "pending") {
2044
+ defaultWriterReadyPromiseReject(writer, error);
2045
+ } else {
2046
+ defaultWriterReadyPromiseResetToRejected(writer, error);
2047
+ }
2048
+ }
2049
+ function WritableStreamDefaultWriterGetDesiredSize(writer) {
2050
+ const stream = writer._ownerWritableStream;
2051
+ const state = stream._state;
2052
+ if (state === "errored" || state === "erroring") {
2053
+ return null;
2054
+ }
2055
+ if (state === "closed") {
2056
+ return 0;
2057
+ }
2058
+ return WritableStreamDefaultControllerGetDesiredSize(stream._writableStreamController);
2059
+ }
2060
+ function WritableStreamDefaultWriterRelease(writer) {
2061
+ const stream = writer._ownerWritableStream;
2062
+ const releasedError = new TypeError(`Writer was released and can no longer be used to monitor the stream's closedness`);
2063
+ WritableStreamDefaultWriterEnsureReadyPromiseRejected(writer, releasedError);
2064
+ WritableStreamDefaultWriterEnsureClosedPromiseRejected(writer, releasedError);
2065
+ stream._writer = undefined;
2066
+ writer._ownerWritableStream = undefined;
2067
+ }
2068
+ function WritableStreamDefaultWriterWrite(writer, chunk) {
2069
+ const stream = writer._ownerWritableStream;
2070
+ const controller = stream._writableStreamController;
2071
+ const chunkSize = WritableStreamDefaultControllerGetChunkSize(controller, chunk);
2072
+ if (stream !== writer._ownerWritableStream) {
2073
+ return promiseRejectedWith(defaultWriterLockException("write to"));
2074
+ }
2075
+ const state = stream._state;
2076
+ if (state === "errored") {
2077
+ return promiseRejectedWith(stream._storedError);
2078
+ }
2079
+ if (WritableStreamCloseQueuedOrInFlight(stream) || state === "closed") {
2080
+ return promiseRejectedWith(new TypeError("The stream is closing or closed and cannot be written to"));
2081
+ }
2082
+ if (state === "erroring") {
2083
+ return promiseRejectedWith(stream._storedError);
2084
+ }
2085
+ const promise = WritableStreamAddWriteRequest(stream);
2086
+ WritableStreamDefaultControllerWrite(controller, chunk, chunkSize);
2087
+ return promise;
2088
+ }
2089
+ const closeSentinel = {};
2090
+
2091
+ class WritableStreamDefaultController {
2092
+ constructor() {
2093
+ throw new TypeError("Illegal constructor");
2094
+ }
2095
+ get abortReason() {
2096
+ if (!IsWritableStreamDefaultController(this)) {
2097
+ throw defaultControllerBrandCheckException$2("abortReason");
2098
+ }
2099
+ return this._abortReason;
2100
+ }
2101
+ get signal() {
2102
+ if (!IsWritableStreamDefaultController(this)) {
2103
+ throw defaultControllerBrandCheckException$2("signal");
2104
+ }
2105
+ if (this._abortController === undefined) {
2106
+ throw new TypeError("WritableStreamDefaultController.prototype.signal is not supported");
2107
+ }
2108
+ return this._abortController.signal;
2109
+ }
2110
+ error(e = undefined) {
2111
+ if (!IsWritableStreamDefaultController(this)) {
2112
+ throw defaultControllerBrandCheckException$2("error");
2113
+ }
2114
+ const state = this._controlledWritableStream._state;
2115
+ if (state !== "writable") {
2116
+ return;
2117
+ }
2118
+ WritableStreamDefaultControllerError(this, e);
2119
+ }
2120
+ [AbortSteps](reason) {
2121
+ const result = this._abortAlgorithm(reason);
2122
+ WritableStreamDefaultControllerClearAlgorithms(this);
2123
+ return result;
2124
+ }
2125
+ [ErrorSteps]() {
2126
+ ResetQueue(this);
2127
+ }
2128
+ }
2129
+ Object.defineProperties(WritableStreamDefaultController.prototype, {
2130
+ abortReason: { enumerable: true },
2131
+ signal: { enumerable: true },
2132
+ error: { enumerable: true }
2133
+ });
2134
+ if (typeof Symbol.toStringTag === "symbol") {
2135
+ Object.defineProperty(WritableStreamDefaultController.prototype, Symbol.toStringTag, {
2136
+ value: "WritableStreamDefaultController",
2137
+ configurable: true
2138
+ });
2139
+ }
2140
+ function IsWritableStreamDefaultController(x) {
2141
+ if (!typeIsObject(x)) {
2142
+ return false;
2143
+ }
2144
+ if (!Object.prototype.hasOwnProperty.call(x, "_controlledWritableStream")) {
2145
+ return false;
2146
+ }
2147
+ return x instanceof WritableStreamDefaultController;
2148
+ }
2149
+ function SetUpWritableStreamDefaultController(stream, controller, startAlgorithm, writeAlgorithm, closeAlgorithm, abortAlgorithm, highWaterMark, sizeAlgorithm) {
2150
+ controller._controlledWritableStream = stream;
2151
+ stream._writableStreamController = controller;
2152
+ controller._queue = undefined;
2153
+ controller._queueTotalSize = undefined;
2154
+ ResetQueue(controller);
2155
+ controller._abortReason = undefined;
2156
+ controller._abortController = createAbortController();
2157
+ controller._started = false;
2158
+ controller._strategySizeAlgorithm = sizeAlgorithm;
2159
+ controller._strategyHWM = highWaterMark;
2160
+ controller._writeAlgorithm = writeAlgorithm;
2161
+ controller._closeAlgorithm = closeAlgorithm;
2162
+ controller._abortAlgorithm = abortAlgorithm;
2163
+ const backpressure = WritableStreamDefaultControllerGetBackpressure(controller);
2164
+ WritableStreamUpdateBackpressure(stream, backpressure);
2165
+ const startResult = startAlgorithm();
2166
+ const startPromise = promiseResolvedWith(startResult);
2167
+ uponPromise(startPromise, () => {
2168
+ controller._started = true;
2169
+ WritableStreamDefaultControllerAdvanceQueueIfNeeded(controller);
2170
+ return null;
2171
+ }, (r) => {
2172
+ controller._started = true;
2173
+ WritableStreamDealWithRejection(stream, r);
2174
+ return null;
2175
+ });
2176
+ }
2177
+ function SetUpWritableStreamDefaultControllerFromUnderlyingSink(stream, underlyingSink, highWaterMark, sizeAlgorithm) {
2178
+ const controller = Object.create(WritableStreamDefaultController.prototype);
2179
+ let startAlgorithm;
2180
+ let writeAlgorithm;
2181
+ let closeAlgorithm;
2182
+ let abortAlgorithm;
2183
+ if (underlyingSink.start !== undefined) {
2184
+ startAlgorithm = () => underlyingSink.start(controller);
2185
+ } else {
2186
+ startAlgorithm = () => {
2187
+ return;
2188
+ };
2189
+ }
2190
+ if (underlyingSink.write !== undefined) {
2191
+ writeAlgorithm = (chunk) => underlyingSink.write(chunk, controller);
2192
+ } else {
2193
+ writeAlgorithm = () => promiseResolvedWith(undefined);
2194
+ }
2195
+ if (underlyingSink.close !== undefined) {
2196
+ closeAlgorithm = () => underlyingSink.close();
2197
+ } else {
2198
+ closeAlgorithm = () => promiseResolvedWith(undefined);
2199
+ }
2200
+ if (underlyingSink.abort !== undefined) {
2201
+ abortAlgorithm = (reason) => underlyingSink.abort(reason);
2202
+ } else {
2203
+ abortAlgorithm = () => promiseResolvedWith(undefined);
2204
+ }
2205
+ SetUpWritableStreamDefaultController(stream, controller, startAlgorithm, writeAlgorithm, closeAlgorithm, abortAlgorithm, highWaterMark, sizeAlgorithm);
2206
+ }
2207
+ function WritableStreamDefaultControllerClearAlgorithms(controller) {
2208
+ controller._writeAlgorithm = undefined;
2209
+ controller._closeAlgorithm = undefined;
2210
+ controller._abortAlgorithm = undefined;
2211
+ controller._strategySizeAlgorithm = undefined;
2212
+ }
2213
+ function WritableStreamDefaultControllerClose(controller) {
2214
+ EnqueueValueWithSize(controller, closeSentinel, 0);
2215
+ WritableStreamDefaultControllerAdvanceQueueIfNeeded(controller);
2216
+ }
2217
+ function WritableStreamDefaultControllerGetChunkSize(controller, chunk) {
2218
+ try {
2219
+ return controller._strategySizeAlgorithm(chunk);
2220
+ } catch (chunkSizeE) {
2221
+ WritableStreamDefaultControllerErrorIfNeeded(controller, chunkSizeE);
2222
+ return 1;
2223
+ }
2224
+ }
2225
+ function WritableStreamDefaultControllerGetDesiredSize(controller) {
2226
+ return controller._strategyHWM - controller._queueTotalSize;
2227
+ }
2228
+ function WritableStreamDefaultControllerWrite(controller, chunk, chunkSize) {
2229
+ try {
2230
+ EnqueueValueWithSize(controller, chunk, chunkSize);
2231
+ } catch (enqueueE) {
2232
+ WritableStreamDefaultControllerErrorIfNeeded(controller, enqueueE);
2233
+ return;
2234
+ }
2235
+ const stream = controller._controlledWritableStream;
2236
+ if (!WritableStreamCloseQueuedOrInFlight(stream) && stream._state === "writable") {
2237
+ const backpressure = WritableStreamDefaultControllerGetBackpressure(controller);
2238
+ WritableStreamUpdateBackpressure(stream, backpressure);
2239
+ }
2240
+ WritableStreamDefaultControllerAdvanceQueueIfNeeded(controller);
2241
+ }
2242
+ function WritableStreamDefaultControllerAdvanceQueueIfNeeded(controller) {
2243
+ const stream = controller._controlledWritableStream;
2244
+ if (!controller._started) {
2245
+ return;
2246
+ }
2247
+ if (stream._inFlightWriteRequest !== undefined) {
2248
+ return;
2249
+ }
2250
+ const state = stream._state;
2251
+ if (state === "erroring") {
2252
+ WritableStreamFinishErroring(stream);
2253
+ return;
2254
+ }
2255
+ if (controller._queue.length === 0) {
2256
+ return;
2257
+ }
2258
+ const value = PeekQueueValue(controller);
2259
+ if (value === closeSentinel) {
2260
+ WritableStreamDefaultControllerProcessClose(controller);
2261
+ } else {
2262
+ WritableStreamDefaultControllerProcessWrite(controller, value);
2263
+ }
2264
+ }
2265
+ function WritableStreamDefaultControllerErrorIfNeeded(controller, error) {
2266
+ if (controller._controlledWritableStream._state === "writable") {
2267
+ WritableStreamDefaultControllerError(controller, error);
2268
+ }
2269
+ }
2270
+ function WritableStreamDefaultControllerProcessClose(controller) {
2271
+ const stream = controller._controlledWritableStream;
2272
+ WritableStreamMarkCloseRequestInFlight(stream);
2273
+ DequeueValue(controller);
2274
+ const sinkClosePromise = controller._closeAlgorithm();
2275
+ WritableStreamDefaultControllerClearAlgorithms(controller);
2276
+ uponPromise(sinkClosePromise, () => {
2277
+ WritableStreamFinishInFlightClose(stream);
2278
+ return null;
2279
+ }, (reason) => {
2280
+ WritableStreamFinishInFlightCloseWithError(stream, reason);
2281
+ return null;
2282
+ });
2283
+ }
2284
+ function WritableStreamDefaultControllerProcessWrite(controller, chunk) {
2285
+ const stream = controller._controlledWritableStream;
2286
+ WritableStreamMarkFirstWriteRequestInFlight(stream);
2287
+ const sinkWritePromise = controller._writeAlgorithm(chunk);
2288
+ uponPromise(sinkWritePromise, () => {
2289
+ WritableStreamFinishInFlightWrite(stream);
2290
+ const state = stream._state;
2291
+ DequeueValue(controller);
2292
+ if (!WritableStreamCloseQueuedOrInFlight(stream) && state === "writable") {
2293
+ const backpressure = WritableStreamDefaultControllerGetBackpressure(controller);
2294
+ WritableStreamUpdateBackpressure(stream, backpressure);
2295
+ }
2296
+ WritableStreamDefaultControllerAdvanceQueueIfNeeded(controller);
2297
+ return null;
2298
+ }, (reason) => {
2299
+ if (stream._state === "writable") {
2300
+ WritableStreamDefaultControllerClearAlgorithms(controller);
2301
+ }
2302
+ WritableStreamFinishInFlightWriteWithError(stream, reason);
2303
+ return null;
2304
+ });
2305
+ }
2306
+ function WritableStreamDefaultControllerGetBackpressure(controller) {
2307
+ const desiredSize = WritableStreamDefaultControllerGetDesiredSize(controller);
2308
+ return desiredSize <= 0;
2309
+ }
2310
+ function WritableStreamDefaultControllerError(controller, error) {
2311
+ const stream = controller._controlledWritableStream;
2312
+ WritableStreamDefaultControllerClearAlgorithms(controller);
2313
+ WritableStreamStartErroring(stream, error);
2314
+ }
2315
+ function streamBrandCheckException$2(name) {
2316
+ return new TypeError(`WritableStream.prototype.${name} can only be used on a WritableStream`);
2317
+ }
2318
+ function defaultControllerBrandCheckException$2(name) {
2319
+ return new TypeError(`WritableStreamDefaultController.prototype.${name} can only be used on a WritableStreamDefaultController`);
2320
+ }
2321
+ function defaultWriterBrandCheckException(name) {
2322
+ return new TypeError(`WritableStreamDefaultWriter.prototype.${name} can only be used on a WritableStreamDefaultWriter`);
2323
+ }
2324
+ function defaultWriterLockException(name) {
2325
+ return new TypeError("Cannot " + name + " a stream using a released writer");
2326
+ }
2327
+ function defaultWriterClosedPromiseInitialize(writer) {
2328
+ writer._closedPromise = newPromise((resolve, reject) => {
2329
+ writer._closedPromise_resolve = resolve;
2330
+ writer._closedPromise_reject = reject;
2331
+ writer._closedPromiseState = "pending";
2332
+ });
2333
+ }
2334
+ function defaultWriterClosedPromiseInitializeAsRejected(writer, reason) {
2335
+ defaultWriterClosedPromiseInitialize(writer);
2336
+ defaultWriterClosedPromiseReject(writer, reason);
2337
+ }
2338
+ function defaultWriterClosedPromiseInitializeAsResolved(writer) {
2339
+ defaultWriterClosedPromiseInitialize(writer);
2340
+ defaultWriterClosedPromiseResolve(writer);
2341
+ }
2342
+ function defaultWriterClosedPromiseReject(writer, reason) {
2343
+ if (writer._closedPromise_reject === undefined) {
2344
+ return;
2345
+ }
2346
+ setPromiseIsHandledToTrue(writer._closedPromise);
2347
+ writer._closedPromise_reject(reason);
2348
+ writer._closedPromise_resolve = undefined;
2349
+ writer._closedPromise_reject = undefined;
2350
+ writer._closedPromiseState = "rejected";
2351
+ }
2352
+ function defaultWriterClosedPromiseResetToRejected(writer, reason) {
2353
+ defaultWriterClosedPromiseInitializeAsRejected(writer, reason);
2354
+ }
2355
+ function defaultWriterClosedPromiseResolve(writer) {
2356
+ if (writer._closedPromise_resolve === undefined) {
2357
+ return;
2358
+ }
2359
+ writer._closedPromise_resolve(undefined);
2360
+ writer._closedPromise_resolve = undefined;
2361
+ writer._closedPromise_reject = undefined;
2362
+ writer._closedPromiseState = "resolved";
2363
+ }
2364
+ function defaultWriterReadyPromiseInitialize(writer) {
2365
+ writer._readyPromise = newPromise((resolve, reject) => {
2366
+ writer._readyPromise_resolve = resolve;
2367
+ writer._readyPromise_reject = reject;
2368
+ });
2369
+ writer._readyPromiseState = "pending";
2370
+ }
2371
+ function defaultWriterReadyPromiseInitializeAsRejected(writer, reason) {
2372
+ defaultWriterReadyPromiseInitialize(writer);
2373
+ defaultWriterReadyPromiseReject(writer, reason);
2374
+ }
2375
+ function defaultWriterReadyPromiseInitializeAsResolved(writer) {
2376
+ defaultWriterReadyPromiseInitialize(writer);
2377
+ defaultWriterReadyPromiseResolve(writer);
2378
+ }
2379
+ function defaultWriterReadyPromiseReject(writer, reason) {
2380
+ if (writer._readyPromise_reject === undefined) {
2381
+ return;
2382
+ }
2383
+ setPromiseIsHandledToTrue(writer._readyPromise);
2384
+ writer._readyPromise_reject(reason);
2385
+ writer._readyPromise_resolve = undefined;
2386
+ writer._readyPromise_reject = undefined;
2387
+ writer._readyPromiseState = "rejected";
2388
+ }
2389
+ function defaultWriterReadyPromiseReset(writer) {
2390
+ defaultWriterReadyPromiseInitialize(writer);
2391
+ }
2392
+ function defaultWriterReadyPromiseResetToRejected(writer, reason) {
2393
+ defaultWriterReadyPromiseInitializeAsRejected(writer, reason);
2394
+ }
2395
+ function defaultWriterReadyPromiseResolve(writer) {
2396
+ if (writer._readyPromise_resolve === undefined) {
2397
+ return;
2398
+ }
2399
+ writer._readyPromise_resolve(undefined);
2400
+ writer._readyPromise_resolve = undefined;
2401
+ writer._readyPromise_reject = undefined;
2402
+ writer._readyPromiseState = "fulfilled";
2403
+ }
2404
+ function getGlobals() {
2405
+ if (typeof globalThis !== "undefined") {
2406
+ return globalThis;
2407
+ } else if (typeof self !== "undefined") {
2408
+ return self;
2409
+ } else if (typeof global !== "undefined") {
2410
+ return global;
2411
+ }
2412
+ return;
2413
+ }
2414
+ const globals = getGlobals();
2415
+ function isDOMExceptionConstructor(ctor) {
2416
+ if (!(typeof ctor === "function" || typeof ctor === "object")) {
2417
+ return false;
2418
+ }
2419
+ if (ctor.name !== "DOMException") {
2420
+ return false;
2421
+ }
2422
+ try {
2423
+ new ctor;
2424
+ return true;
2425
+ } catch (_a2) {
2426
+ return false;
2427
+ }
2428
+ }
2429
+ function getFromGlobal() {
2430
+ const ctor = globals === null || globals === undefined ? undefined : globals.DOMException;
2431
+ return isDOMExceptionConstructor(ctor) ? ctor : undefined;
2432
+ }
2433
+ function createPolyfill() {
2434
+ const ctor = function DOMException2(message, name) {
2435
+ this.message = message || "";
2436
+ this.name = name || "Error";
2437
+ if (Error.captureStackTrace) {
2438
+ Error.captureStackTrace(this, this.constructor);
2439
+ }
2440
+ };
2441
+ setFunctionName(ctor, "DOMException");
2442
+ ctor.prototype = Object.create(Error.prototype);
2443
+ Object.defineProperty(ctor.prototype, "constructor", { value: ctor, writable: true, configurable: true });
2444
+ return ctor;
2445
+ }
2446
+ const DOMException = getFromGlobal() || createPolyfill();
2447
+ function ReadableStreamPipeTo(source, dest, preventClose, preventAbort, preventCancel, signal) {
2448
+ const reader = AcquireReadableStreamDefaultReader(source);
2449
+ const writer = AcquireWritableStreamDefaultWriter(dest);
2450
+ source._disturbed = true;
2451
+ let shuttingDown = false;
2452
+ let currentWrite = promiseResolvedWith(undefined);
2453
+ return newPromise((resolve, reject) => {
2454
+ let abortAlgorithm;
2455
+ if (signal !== undefined) {
2456
+ abortAlgorithm = () => {
2457
+ const error = signal.reason !== undefined ? signal.reason : new DOMException("Aborted", "AbortError");
2458
+ const actions = [];
2459
+ if (!preventAbort) {
2460
+ actions.push(() => {
2461
+ if (dest._state === "writable") {
2462
+ return WritableStreamAbort(dest, error);
2463
+ }
2464
+ return promiseResolvedWith(undefined);
2465
+ });
2466
+ }
2467
+ if (!preventCancel) {
2468
+ actions.push(() => {
2469
+ if (source._state === "readable") {
2470
+ return ReadableStreamCancel(source, error);
2471
+ }
2472
+ return promiseResolvedWith(undefined);
2473
+ });
2474
+ }
2475
+ shutdownWithAction(() => Promise.all(actions.map((action) => action())), true, error);
2476
+ };
2477
+ if (signal.aborted) {
2478
+ abortAlgorithm();
2479
+ return;
2480
+ }
2481
+ signal.addEventListener("abort", abortAlgorithm);
2482
+ }
2483
+ function pipeLoop() {
2484
+ return newPromise((resolveLoop, rejectLoop) => {
2485
+ function next(done) {
2486
+ if (done) {
2487
+ resolveLoop();
2488
+ } else {
2489
+ PerformPromiseThen(pipeStep(), next, rejectLoop);
2490
+ }
2491
+ }
2492
+ next(false);
2493
+ });
2494
+ }
2495
+ function pipeStep() {
2496
+ if (shuttingDown) {
2497
+ return promiseResolvedWith(true);
2498
+ }
2499
+ return PerformPromiseThen(writer._readyPromise, () => {
2500
+ return newPromise((resolveRead, rejectRead) => {
2501
+ ReadableStreamDefaultReaderRead(reader, {
2502
+ _chunkSteps: (chunk) => {
2503
+ currentWrite = PerformPromiseThen(WritableStreamDefaultWriterWrite(writer, chunk), undefined, noop);
2504
+ resolveRead(false);
2505
+ },
2506
+ _closeSteps: () => resolveRead(true),
2507
+ _errorSteps: rejectRead
2508
+ });
2509
+ });
2510
+ });
2511
+ }
2512
+ isOrBecomesErrored(source, reader._closedPromise, (storedError) => {
2513
+ if (!preventAbort) {
2514
+ shutdownWithAction(() => WritableStreamAbort(dest, storedError), true, storedError);
2515
+ } else {
2516
+ shutdown(true, storedError);
2517
+ }
2518
+ return null;
2519
+ });
2520
+ isOrBecomesErrored(dest, writer._closedPromise, (storedError) => {
2521
+ if (!preventCancel) {
2522
+ shutdownWithAction(() => ReadableStreamCancel(source, storedError), true, storedError);
2523
+ } else {
2524
+ shutdown(true, storedError);
2525
+ }
2526
+ return null;
2527
+ });
2528
+ isOrBecomesClosed(source, reader._closedPromise, () => {
2529
+ if (!preventClose) {
2530
+ shutdownWithAction(() => WritableStreamDefaultWriterCloseWithErrorPropagation(writer));
2531
+ } else {
2532
+ shutdown();
2533
+ }
2534
+ return null;
2535
+ });
2536
+ if (WritableStreamCloseQueuedOrInFlight(dest) || dest._state === "closed") {
2537
+ const destClosed = new TypeError("the destination writable stream closed before all data could be piped to it");
2538
+ if (!preventCancel) {
2539
+ shutdownWithAction(() => ReadableStreamCancel(source, destClosed), true, destClosed);
2540
+ } else {
2541
+ shutdown(true, destClosed);
2542
+ }
2543
+ }
2544
+ setPromiseIsHandledToTrue(pipeLoop());
2545
+ function waitForWritesToFinish() {
2546
+ const oldCurrentWrite = currentWrite;
2547
+ return PerformPromiseThen(currentWrite, () => oldCurrentWrite !== currentWrite ? waitForWritesToFinish() : undefined);
2548
+ }
2549
+ function isOrBecomesErrored(stream, promise, action) {
2550
+ if (stream._state === "errored") {
2551
+ action(stream._storedError);
2552
+ } else {
2553
+ uponRejection(promise, action);
2554
+ }
2555
+ }
2556
+ function isOrBecomesClosed(stream, promise, action) {
2557
+ if (stream._state === "closed") {
2558
+ action();
2559
+ } else {
2560
+ uponFulfillment(promise, action);
2561
+ }
2562
+ }
2563
+ function shutdownWithAction(action, originalIsError, originalError) {
2564
+ if (shuttingDown) {
2565
+ return;
2566
+ }
2567
+ shuttingDown = true;
2568
+ if (dest._state === "writable" && !WritableStreamCloseQueuedOrInFlight(dest)) {
2569
+ uponFulfillment(waitForWritesToFinish(), doTheRest);
2570
+ } else {
2571
+ doTheRest();
2572
+ }
2573
+ function doTheRest() {
2574
+ uponPromise(action(), () => finalize(originalIsError, originalError), (newError) => finalize(true, newError));
2575
+ return null;
2576
+ }
2577
+ }
2578
+ function shutdown(isError, error) {
2579
+ if (shuttingDown) {
2580
+ return;
2581
+ }
2582
+ shuttingDown = true;
2583
+ if (dest._state === "writable" && !WritableStreamCloseQueuedOrInFlight(dest)) {
2584
+ uponFulfillment(waitForWritesToFinish(), () => finalize(isError, error));
2585
+ } else {
2586
+ finalize(isError, error);
2587
+ }
2588
+ }
2589
+ function finalize(isError, error) {
2590
+ WritableStreamDefaultWriterRelease(writer);
2591
+ ReadableStreamReaderGenericRelease(reader);
2592
+ if (signal !== undefined) {
2593
+ signal.removeEventListener("abort", abortAlgorithm);
2594
+ }
2595
+ if (isError) {
2596
+ reject(error);
2597
+ } else {
2598
+ resolve(undefined);
2599
+ }
2600
+ return null;
2601
+ }
2602
+ });
2603
+ }
2604
+
2605
+ class ReadableStreamDefaultController {
2606
+ constructor() {
2607
+ throw new TypeError("Illegal constructor");
2608
+ }
2609
+ get desiredSize() {
2610
+ if (!IsReadableStreamDefaultController(this)) {
2611
+ throw defaultControllerBrandCheckException$1("desiredSize");
2612
+ }
2613
+ return ReadableStreamDefaultControllerGetDesiredSize(this);
2614
+ }
2615
+ close() {
2616
+ if (!IsReadableStreamDefaultController(this)) {
2617
+ throw defaultControllerBrandCheckException$1("close");
2618
+ }
2619
+ if (!ReadableStreamDefaultControllerCanCloseOrEnqueue(this)) {
2620
+ throw new TypeError("The stream is not in a state that permits close");
2621
+ }
2622
+ ReadableStreamDefaultControllerClose(this);
2623
+ }
2624
+ enqueue(chunk = undefined) {
2625
+ if (!IsReadableStreamDefaultController(this)) {
2626
+ throw defaultControllerBrandCheckException$1("enqueue");
2627
+ }
2628
+ if (!ReadableStreamDefaultControllerCanCloseOrEnqueue(this)) {
2629
+ throw new TypeError("The stream is not in a state that permits enqueue");
2630
+ }
2631
+ return ReadableStreamDefaultControllerEnqueue(this, chunk);
2632
+ }
2633
+ error(e = undefined) {
2634
+ if (!IsReadableStreamDefaultController(this)) {
2635
+ throw defaultControllerBrandCheckException$1("error");
2636
+ }
2637
+ ReadableStreamDefaultControllerError(this, e);
2638
+ }
2639
+ [CancelSteps](reason) {
2640
+ ResetQueue(this);
2641
+ const result = this._cancelAlgorithm(reason);
2642
+ ReadableStreamDefaultControllerClearAlgorithms(this);
2643
+ return result;
2644
+ }
2645
+ [PullSteps](readRequest) {
2646
+ const stream = this._controlledReadableStream;
2647
+ if (this._queue.length > 0) {
2648
+ const chunk = DequeueValue(this);
2649
+ if (this._closeRequested && this._queue.length === 0) {
2650
+ ReadableStreamDefaultControllerClearAlgorithms(this);
2651
+ ReadableStreamClose(stream);
2652
+ } else {
2653
+ ReadableStreamDefaultControllerCallPullIfNeeded(this);
2654
+ }
2655
+ readRequest._chunkSteps(chunk);
2656
+ } else {
2657
+ ReadableStreamAddReadRequest(stream, readRequest);
2658
+ ReadableStreamDefaultControllerCallPullIfNeeded(this);
2659
+ }
2660
+ }
2661
+ [ReleaseSteps]() {}
2662
+ }
2663
+ Object.defineProperties(ReadableStreamDefaultController.prototype, {
2664
+ close: { enumerable: true },
2665
+ enqueue: { enumerable: true },
2666
+ error: { enumerable: true },
2667
+ desiredSize: { enumerable: true }
2668
+ });
2669
+ setFunctionName(ReadableStreamDefaultController.prototype.close, "close");
2670
+ setFunctionName(ReadableStreamDefaultController.prototype.enqueue, "enqueue");
2671
+ setFunctionName(ReadableStreamDefaultController.prototype.error, "error");
2672
+ if (typeof Symbol.toStringTag === "symbol") {
2673
+ Object.defineProperty(ReadableStreamDefaultController.prototype, Symbol.toStringTag, {
2674
+ value: "ReadableStreamDefaultController",
2675
+ configurable: true
2676
+ });
2677
+ }
2678
+ function IsReadableStreamDefaultController(x) {
2679
+ if (!typeIsObject(x)) {
2680
+ return false;
2681
+ }
2682
+ if (!Object.prototype.hasOwnProperty.call(x, "_controlledReadableStream")) {
2683
+ return false;
2684
+ }
2685
+ return x instanceof ReadableStreamDefaultController;
2686
+ }
2687
+ function ReadableStreamDefaultControllerCallPullIfNeeded(controller) {
2688
+ const shouldPull = ReadableStreamDefaultControllerShouldCallPull(controller);
2689
+ if (!shouldPull) {
2690
+ return;
2691
+ }
2692
+ if (controller._pulling) {
2693
+ controller._pullAgain = true;
2694
+ return;
2695
+ }
2696
+ controller._pulling = true;
2697
+ const pullPromise = controller._pullAlgorithm();
2698
+ uponPromise(pullPromise, () => {
2699
+ controller._pulling = false;
2700
+ if (controller._pullAgain) {
2701
+ controller._pullAgain = false;
2702
+ ReadableStreamDefaultControllerCallPullIfNeeded(controller);
2703
+ }
2704
+ return null;
2705
+ }, (e) => {
2706
+ ReadableStreamDefaultControllerError(controller, e);
2707
+ return null;
2708
+ });
2709
+ }
2710
+ function ReadableStreamDefaultControllerShouldCallPull(controller) {
2711
+ const stream = controller._controlledReadableStream;
2712
+ if (!ReadableStreamDefaultControllerCanCloseOrEnqueue(controller)) {
2713
+ return false;
2714
+ }
2715
+ if (!controller._started) {
2716
+ return false;
2717
+ }
2718
+ if (IsReadableStreamLocked(stream) && ReadableStreamGetNumReadRequests(stream) > 0) {
2719
+ return true;
2720
+ }
2721
+ const desiredSize = ReadableStreamDefaultControllerGetDesiredSize(controller);
2722
+ if (desiredSize > 0) {
2723
+ return true;
2724
+ }
2725
+ return false;
2726
+ }
2727
+ function ReadableStreamDefaultControllerClearAlgorithms(controller) {
2728
+ controller._pullAlgorithm = undefined;
2729
+ controller._cancelAlgorithm = undefined;
2730
+ controller._strategySizeAlgorithm = undefined;
2731
+ }
2732
+ function ReadableStreamDefaultControllerClose(controller) {
2733
+ if (!ReadableStreamDefaultControllerCanCloseOrEnqueue(controller)) {
2734
+ return;
2735
+ }
2736
+ const stream = controller._controlledReadableStream;
2737
+ controller._closeRequested = true;
2738
+ if (controller._queue.length === 0) {
2739
+ ReadableStreamDefaultControllerClearAlgorithms(controller);
2740
+ ReadableStreamClose(stream);
2741
+ }
2742
+ }
2743
+ function ReadableStreamDefaultControllerEnqueue(controller, chunk) {
2744
+ if (!ReadableStreamDefaultControllerCanCloseOrEnqueue(controller)) {
2745
+ return;
2746
+ }
2747
+ const stream = controller._controlledReadableStream;
2748
+ if (IsReadableStreamLocked(stream) && ReadableStreamGetNumReadRequests(stream) > 0) {
2749
+ ReadableStreamFulfillReadRequest(stream, chunk, false);
2750
+ } else {
2751
+ let chunkSize;
2752
+ try {
2753
+ chunkSize = controller._strategySizeAlgorithm(chunk);
2754
+ } catch (chunkSizeE) {
2755
+ ReadableStreamDefaultControllerError(controller, chunkSizeE);
2756
+ throw chunkSizeE;
2757
+ }
2758
+ try {
2759
+ EnqueueValueWithSize(controller, chunk, chunkSize);
2760
+ } catch (enqueueE) {
2761
+ ReadableStreamDefaultControllerError(controller, enqueueE);
2762
+ throw enqueueE;
2763
+ }
2764
+ }
2765
+ ReadableStreamDefaultControllerCallPullIfNeeded(controller);
2766
+ }
2767
+ function ReadableStreamDefaultControllerError(controller, e) {
2768
+ const stream = controller._controlledReadableStream;
2769
+ if (stream._state !== "readable") {
2770
+ return;
2771
+ }
2772
+ ResetQueue(controller);
2773
+ ReadableStreamDefaultControllerClearAlgorithms(controller);
2774
+ ReadableStreamError(stream, e);
2775
+ }
2776
+ function ReadableStreamDefaultControllerGetDesiredSize(controller) {
2777
+ const state = controller._controlledReadableStream._state;
2778
+ if (state === "errored") {
2779
+ return null;
2780
+ }
2781
+ if (state === "closed") {
2782
+ return 0;
2783
+ }
2784
+ return controller._strategyHWM - controller._queueTotalSize;
2785
+ }
2786
+ function ReadableStreamDefaultControllerHasBackpressure(controller) {
2787
+ if (ReadableStreamDefaultControllerShouldCallPull(controller)) {
2788
+ return false;
2789
+ }
2790
+ return true;
2791
+ }
2792
+ function ReadableStreamDefaultControllerCanCloseOrEnqueue(controller) {
2793
+ const state = controller._controlledReadableStream._state;
2794
+ if (!controller._closeRequested && state === "readable") {
2795
+ return true;
2796
+ }
2797
+ return false;
2798
+ }
2799
+ function SetUpReadableStreamDefaultController(stream, controller, startAlgorithm, pullAlgorithm, cancelAlgorithm, highWaterMark, sizeAlgorithm) {
2800
+ controller._controlledReadableStream = stream;
2801
+ controller._queue = undefined;
2802
+ controller._queueTotalSize = undefined;
2803
+ ResetQueue(controller);
2804
+ controller._started = false;
2805
+ controller._closeRequested = false;
2806
+ controller._pullAgain = false;
2807
+ controller._pulling = false;
2808
+ controller._strategySizeAlgorithm = sizeAlgorithm;
2809
+ controller._strategyHWM = highWaterMark;
2810
+ controller._pullAlgorithm = pullAlgorithm;
2811
+ controller._cancelAlgorithm = cancelAlgorithm;
2812
+ stream._readableStreamController = controller;
2813
+ const startResult = startAlgorithm();
2814
+ uponPromise(promiseResolvedWith(startResult), () => {
2815
+ controller._started = true;
2816
+ ReadableStreamDefaultControllerCallPullIfNeeded(controller);
2817
+ return null;
2818
+ }, (r) => {
2819
+ ReadableStreamDefaultControllerError(controller, r);
2820
+ return null;
2821
+ });
2822
+ }
2823
+ function SetUpReadableStreamDefaultControllerFromUnderlyingSource(stream, underlyingSource, highWaterMark, sizeAlgorithm) {
2824
+ const controller = Object.create(ReadableStreamDefaultController.prototype);
2825
+ let startAlgorithm;
2826
+ let pullAlgorithm;
2827
+ let cancelAlgorithm;
2828
+ if (underlyingSource.start !== undefined) {
2829
+ startAlgorithm = () => underlyingSource.start(controller);
2830
+ } else {
2831
+ startAlgorithm = () => {
2832
+ return;
2833
+ };
2834
+ }
2835
+ if (underlyingSource.pull !== undefined) {
2836
+ pullAlgorithm = () => underlyingSource.pull(controller);
2837
+ } else {
2838
+ pullAlgorithm = () => promiseResolvedWith(undefined);
2839
+ }
2840
+ if (underlyingSource.cancel !== undefined) {
2841
+ cancelAlgorithm = (reason) => underlyingSource.cancel(reason);
2842
+ } else {
2843
+ cancelAlgorithm = () => promiseResolvedWith(undefined);
2844
+ }
2845
+ SetUpReadableStreamDefaultController(stream, controller, startAlgorithm, pullAlgorithm, cancelAlgorithm, highWaterMark, sizeAlgorithm);
2846
+ }
2847
+ function defaultControllerBrandCheckException$1(name) {
2848
+ return new TypeError(`ReadableStreamDefaultController.prototype.${name} can only be used on a ReadableStreamDefaultController`);
2849
+ }
2850
+ function ReadableStreamTee(stream, cloneForBranch2) {
2851
+ if (IsReadableByteStreamController(stream._readableStreamController)) {
2852
+ return ReadableByteStreamTee(stream);
2853
+ }
2854
+ return ReadableStreamDefaultTee(stream);
2855
+ }
2856
+ function ReadableStreamDefaultTee(stream, cloneForBranch2) {
2857
+ const reader = AcquireReadableStreamDefaultReader(stream);
2858
+ let reading = false;
2859
+ let readAgain = false;
2860
+ let canceled1 = false;
2861
+ let canceled2 = false;
2862
+ let reason1;
2863
+ let reason2;
2864
+ let branch1;
2865
+ let branch2;
2866
+ let resolveCancelPromise;
2867
+ const cancelPromise = newPromise((resolve) => {
2868
+ resolveCancelPromise = resolve;
2869
+ });
2870
+ function pullAlgorithm() {
2871
+ if (reading) {
2872
+ readAgain = true;
2873
+ return promiseResolvedWith(undefined);
2874
+ }
2875
+ reading = true;
2876
+ const readRequest = {
2877
+ _chunkSteps: (chunk) => {
2878
+ _queueMicrotask(() => {
2879
+ readAgain = false;
2880
+ const chunk1 = chunk;
2881
+ const chunk2 = chunk;
2882
+ if (!canceled1) {
2883
+ ReadableStreamDefaultControllerEnqueue(branch1._readableStreamController, chunk1);
2884
+ }
2885
+ if (!canceled2) {
2886
+ ReadableStreamDefaultControllerEnqueue(branch2._readableStreamController, chunk2);
2887
+ }
2888
+ reading = false;
2889
+ if (readAgain) {
2890
+ pullAlgorithm();
2891
+ }
2892
+ });
2893
+ },
2894
+ _closeSteps: () => {
2895
+ reading = false;
2896
+ if (!canceled1) {
2897
+ ReadableStreamDefaultControllerClose(branch1._readableStreamController);
2898
+ }
2899
+ if (!canceled2) {
2900
+ ReadableStreamDefaultControllerClose(branch2._readableStreamController);
2901
+ }
2902
+ if (!canceled1 || !canceled2) {
2903
+ resolveCancelPromise(undefined);
2904
+ }
2905
+ },
2906
+ _errorSteps: () => {
2907
+ reading = false;
2908
+ }
2909
+ };
2910
+ ReadableStreamDefaultReaderRead(reader, readRequest);
2911
+ return promiseResolvedWith(undefined);
2912
+ }
2913
+ function cancel1Algorithm(reason) {
2914
+ canceled1 = true;
2915
+ reason1 = reason;
2916
+ if (canceled2) {
2917
+ const compositeReason = CreateArrayFromList([reason1, reason2]);
2918
+ const cancelResult = ReadableStreamCancel(stream, compositeReason);
2919
+ resolveCancelPromise(cancelResult);
2920
+ }
2921
+ return cancelPromise;
2922
+ }
2923
+ function cancel2Algorithm(reason) {
2924
+ canceled2 = true;
2925
+ reason2 = reason;
2926
+ if (canceled1) {
2927
+ const compositeReason = CreateArrayFromList([reason1, reason2]);
2928
+ const cancelResult = ReadableStreamCancel(stream, compositeReason);
2929
+ resolveCancelPromise(cancelResult);
2930
+ }
2931
+ return cancelPromise;
2932
+ }
2933
+ function startAlgorithm() {}
2934
+ branch1 = CreateReadableStream(startAlgorithm, pullAlgorithm, cancel1Algorithm);
2935
+ branch2 = CreateReadableStream(startAlgorithm, pullAlgorithm, cancel2Algorithm);
2936
+ uponRejection(reader._closedPromise, (r) => {
2937
+ ReadableStreamDefaultControllerError(branch1._readableStreamController, r);
2938
+ ReadableStreamDefaultControllerError(branch2._readableStreamController, r);
2939
+ if (!canceled1 || !canceled2) {
2940
+ resolveCancelPromise(undefined);
2941
+ }
2942
+ return null;
2943
+ });
2944
+ return [branch1, branch2];
2945
+ }
2946
+ function ReadableByteStreamTee(stream) {
2947
+ let reader = AcquireReadableStreamDefaultReader(stream);
2948
+ let reading = false;
2949
+ let readAgainForBranch1 = false;
2950
+ let readAgainForBranch2 = false;
2951
+ let canceled1 = false;
2952
+ let canceled2 = false;
2953
+ let reason1;
2954
+ let reason2;
2955
+ let branch1;
2956
+ let branch2;
2957
+ let resolveCancelPromise;
2958
+ const cancelPromise = newPromise((resolve) => {
2959
+ resolveCancelPromise = resolve;
2960
+ });
2961
+ function forwardReaderError(thisReader) {
2962
+ uponRejection(thisReader._closedPromise, (r) => {
2963
+ if (thisReader !== reader) {
2964
+ return null;
2965
+ }
2966
+ ReadableByteStreamControllerError(branch1._readableStreamController, r);
2967
+ ReadableByteStreamControllerError(branch2._readableStreamController, r);
2968
+ if (!canceled1 || !canceled2) {
2969
+ resolveCancelPromise(undefined);
2970
+ }
2971
+ return null;
2972
+ });
2973
+ }
2974
+ function pullWithDefaultReader() {
2975
+ if (IsReadableStreamBYOBReader(reader)) {
2976
+ ReadableStreamReaderGenericRelease(reader);
2977
+ reader = AcquireReadableStreamDefaultReader(stream);
2978
+ forwardReaderError(reader);
2979
+ }
2980
+ const readRequest = {
2981
+ _chunkSteps: (chunk) => {
2982
+ _queueMicrotask(() => {
2983
+ readAgainForBranch1 = false;
2984
+ readAgainForBranch2 = false;
2985
+ const chunk1 = chunk;
2986
+ let chunk2 = chunk;
2987
+ if (!canceled1 && !canceled2) {
2988
+ try {
2989
+ chunk2 = CloneAsUint8Array(chunk);
2990
+ } catch (cloneE) {
2991
+ ReadableByteStreamControllerError(branch1._readableStreamController, cloneE);
2992
+ ReadableByteStreamControllerError(branch2._readableStreamController, cloneE);
2993
+ resolveCancelPromise(ReadableStreamCancel(stream, cloneE));
2994
+ return;
2995
+ }
2996
+ }
2997
+ if (!canceled1) {
2998
+ ReadableByteStreamControllerEnqueue(branch1._readableStreamController, chunk1);
2999
+ }
3000
+ if (!canceled2) {
3001
+ ReadableByteStreamControllerEnqueue(branch2._readableStreamController, chunk2);
3002
+ }
3003
+ reading = false;
3004
+ if (readAgainForBranch1) {
3005
+ pull1Algorithm();
3006
+ } else if (readAgainForBranch2) {
3007
+ pull2Algorithm();
3008
+ }
3009
+ });
3010
+ },
3011
+ _closeSteps: () => {
3012
+ reading = false;
3013
+ if (!canceled1) {
3014
+ ReadableByteStreamControllerClose(branch1._readableStreamController);
3015
+ }
3016
+ if (!canceled2) {
3017
+ ReadableByteStreamControllerClose(branch2._readableStreamController);
3018
+ }
3019
+ if (branch1._readableStreamController._pendingPullIntos.length > 0) {
3020
+ ReadableByteStreamControllerRespond(branch1._readableStreamController, 0);
3021
+ }
3022
+ if (branch2._readableStreamController._pendingPullIntos.length > 0) {
3023
+ ReadableByteStreamControllerRespond(branch2._readableStreamController, 0);
3024
+ }
3025
+ if (!canceled1 || !canceled2) {
3026
+ resolveCancelPromise(undefined);
3027
+ }
3028
+ },
3029
+ _errorSteps: () => {
3030
+ reading = false;
3031
+ }
3032
+ };
3033
+ ReadableStreamDefaultReaderRead(reader, readRequest);
3034
+ }
3035
+ function pullWithBYOBReader(view, forBranch2) {
3036
+ if (IsReadableStreamDefaultReader(reader)) {
3037
+ ReadableStreamReaderGenericRelease(reader);
3038
+ reader = AcquireReadableStreamBYOBReader(stream);
3039
+ forwardReaderError(reader);
3040
+ }
3041
+ const byobBranch = forBranch2 ? branch2 : branch1;
3042
+ const otherBranch = forBranch2 ? branch1 : branch2;
3043
+ const readIntoRequest = {
3044
+ _chunkSteps: (chunk) => {
3045
+ _queueMicrotask(() => {
3046
+ readAgainForBranch1 = false;
3047
+ readAgainForBranch2 = false;
3048
+ const byobCanceled = forBranch2 ? canceled2 : canceled1;
3049
+ const otherCanceled = forBranch2 ? canceled1 : canceled2;
3050
+ if (!otherCanceled) {
3051
+ let clonedChunk;
3052
+ try {
3053
+ clonedChunk = CloneAsUint8Array(chunk);
3054
+ } catch (cloneE) {
3055
+ ReadableByteStreamControllerError(byobBranch._readableStreamController, cloneE);
3056
+ ReadableByteStreamControllerError(otherBranch._readableStreamController, cloneE);
3057
+ resolveCancelPromise(ReadableStreamCancel(stream, cloneE));
3058
+ return;
3059
+ }
3060
+ if (!byobCanceled) {
3061
+ ReadableByteStreamControllerRespondWithNewView(byobBranch._readableStreamController, chunk);
3062
+ }
3063
+ ReadableByteStreamControllerEnqueue(otherBranch._readableStreamController, clonedChunk);
3064
+ } else if (!byobCanceled) {
3065
+ ReadableByteStreamControllerRespondWithNewView(byobBranch._readableStreamController, chunk);
3066
+ }
3067
+ reading = false;
3068
+ if (readAgainForBranch1) {
3069
+ pull1Algorithm();
3070
+ } else if (readAgainForBranch2) {
3071
+ pull2Algorithm();
3072
+ }
3073
+ });
3074
+ },
3075
+ _closeSteps: (chunk) => {
3076
+ reading = false;
3077
+ const byobCanceled = forBranch2 ? canceled2 : canceled1;
3078
+ const otherCanceled = forBranch2 ? canceled1 : canceled2;
3079
+ if (!byobCanceled) {
3080
+ ReadableByteStreamControllerClose(byobBranch._readableStreamController);
3081
+ }
3082
+ if (!otherCanceled) {
3083
+ ReadableByteStreamControllerClose(otherBranch._readableStreamController);
3084
+ }
3085
+ if (chunk !== undefined) {
3086
+ if (!byobCanceled) {
3087
+ ReadableByteStreamControllerRespondWithNewView(byobBranch._readableStreamController, chunk);
3088
+ }
3089
+ if (!otherCanceled && otherBranch._readableStreamController._pendingPullIntos.length > 0) {
3090
+ ReadableByteStreamControllerRespond(otherBranch._readableStreamController, 0);
3091
+ }
3092
+ }
3093
+ if (!byobCanceled || !otherCanceled) {
3094
+ resolveCancelPromise(undefined);
3095
+ }
3096
+ },
3097
+ _errorSteps: () => {
3098
+ reading = false;
3099
+ }
3100
+ };
3101
+ ReadableStreamBYOBReaderRead(reader, view, 1, readIntoRequest);
3102
+ }
3103
+ function pull1Algorithm() {
3104
+ if (reading) {
3105
+ readAgainForBranch1 = true;
3106
+ return promiseResolvedWith(undefined);
3107
+ }
3108
+ reading = true;
3109
+ const byobRequest = ReadableByteStreamControllerGetBYOBRequest(branch1._readableStreamController);
3110
+ if (byobRequest === null) {
3111
+ pullWithDefaultReader();
3112
+ } else {
3113
+ pullWithBYOBReader(byobRequest._view, false);
3114
+ }
3115
+ return promiseResolvedWith(undefined);
3116
+ }
3117
+ function pull2Algorithm() {
3118
+ if (reading) {
3119
+ readAgainForBranch2 = true;
3120
+ return promiseResolvedWith(undefined);
3121
+ }
3122
+ reading = true;
3123
+ const byobRequest = ReadableByteStreamControllerGetBYOBRequest(branch2._readableStreamController);
3124
+ if (byobRequest === null) {
3125
+ pullWithDefaultReader();
3126
+ } else {
3127
+ pullWithBYOBReader(byobRequest._view, true);
3128
+ }
3129
+ return promiseResolvedWith(undefined);
3130
+ }
3131
+ function cancel1Algorithm(reason) {
3132
+ canceled1 = true;
3133
+ reason1 = reason;
3134
+ if (canceled2) {
3135
+ const compositeReason = CreateArrayFromList([reason1, reason2]);
3136
+ const cancelResult = ReadableStreamCancel(stream, compositeReason);
3137
+ resolveCancelPromise(cancelResult);
3138
+ }
3139
+ return cancelPromise;
3140
+ }
3141
+ function cancel2Algorithm(reason) {
3142
+ canceled2 = true;
3143
+ reason2 = reason;
3144
+ if (canceled1) {
3145
+ const compositeReason = CreateArrayFromList([reason1, reason2]);
3146
+ const cancelResult = ReadableStreamCancel(stream, compositeReason);
3147
+ resolveCancelPromise(cancelResult);
3148
+ }
3149
+ return cancelPromise;
3150
+ }
3151
+ function startAlgorithm() {
3152
+ return;
3153
+ }
3154
+ branch1 = CreateReadableByteStream(startAlgorithm, pull1Algorithm, cancel1Algorithm);
3155
+ branch2 = CreateReadableByteStream(startAlgorithm, pull2Algorithm, cancel2Algorithm);
3156
+ forwardReaderError(reader);
3157
+ return [branch1, branch2];
3158
+ }
3159
+ function isReadableStreamLike(stream) {
3160
+ return typeIsObject(stream) && typeof stream.getReader !== "undefined";
3161
+ }
3162
+ function ReadableStreamFrom(source) {
3163
+ if (isReadableStreamLike(source)) {
3164
+ return ReadableStreamFromDefaultReader(source.getReader());
3165
+ }
3166
+ return ReadableStreamFromIterable(source);
3167
+ }
3168
+ function ReadableStreamFromIterable(asyncIterable) {
3169
+ let stream;
3170
+ const iteratorRecord = GetIterator(asyncIterable, "async");
3171
+ const startAlgorithm = noop;
3172
+ function pullAlgorithm() {
3173
+ let nextResult;
3174
+ try {
3175
+ nextResult = IteratorNext(iteratorRecord);
3176
+ } catch (e) {
3177
+ return promiseRejectedWith(e);
3178
+ }
3179
+ const nextPromise = promiseResolvedWith(nextResult);
3180
+ return transformPromiseWith(nextPromise, (iterResult) => {
3181
+ if (!typeIsObject(iterResult)) {
3182
+ throw new TypeError("The promise returned by the iterator.next() method must fulfill with an object");
3183
+ }
3184
+ const done = IteratorComplete(iterResult);
3185
+ if (done) {
3186
+ ReadableStreamDefaultControllerClose(stream._readableStreamController);
3187
+ } else {
3188
+ const value = IteratorValue(iterResult);
3189
+ ReadableStreamDefaultControllerEnqueue(stream._readableStreamController, value);
3190
+ }
3191
+ });
3192
+ }
3193
+ function cancelAlgorithm(reason) {
3194
+ const iterator = iteratorRecord.iterator;
3195
+ let returnMethod;
3196
+ try {
3197
+ returnMethod = GetMethod(iterator, "return");
3198
+ } catch (e) {
3199
+ return promiseRejectedWith(e);
3200
+ }
3201
+ if (returnMethod === undefined) {
3202
+ return promiseResolvedWith(undefined);
3203
+ }
3204
+ let returnResult;
3205
+ try {
3206
+ returnResult = reflectCall(returnMethod, iterator, [reason]);
3207
+ } catch (e) {
3208
+ return promiseRejectedWith(e);
3209
+ }
3210
+ const returnPromise = promiseResolvedWith(returnResult);
3211
+ return transformPromiseWith(returnPromise, (iterResult) => {
3212
+ if (!typeIsObject(iterResult)) {
3213
+ throw new TypeError("The promise returned by the iterator.return() method must fulfill with an object");
3214
+ }
3215
+ return;
3216
+ });
3217
+ }
3218
+ stream = CreateReadableStream(startAlgorithm, pullAlgorithm, cancelAlgorithm, 0);
3219
+ return stream;
3220
+ }
3221
+ function ReadableStreamFromDefaultReader(reader) {
3222
+ let stream;
3223
+ const startAlgorithm = noop;
3224
+ function pullAlgorithm() {
3225
+ let readPromise;
3226
+ try {
3227
+ readPromise = reader.read();
3228
+ } catch (e) {
3229
+ return promiseRejectedWith(e);
3230
+ }
3231
+ return transformPromiseWith(readPromise, (readResult) => {
3232
+ if (!typeIsObject(readResult)) {
3233
+ throw new TypeError("The promise returned by the reader.read() method must fulfill with an object");
3234
+ }
3235
+ if (readResult.done) {
3236
+ ReadableStreamDefaultControllerClose(stream._readableStreamController);
3237
+ } else {
3238
+ const value = readResult.value;
3239
+ ReadableStreamDefaultControllerEnqueue(stream._readableStreamController, value);
3240
+ }
3241
+ });
3242
+ }
3243
+ function cancelAlgorithm(reason) {
3244
+ try {
3245
+ return promiseResolvedWith(reader.cancel(reason));
3246
+ } catch (e) {
3247
+ return promiseRejectedWith(e);
3248
+ }
3249
+ }
3250
+ stream = CreateReadableStream(startAlgorithm, pullAlgorithm, cancelAlgorithm, 0);
3251
+ return stream;
3252
+ }
3253
+ function convertUnderlyingDefaultOrByteSource(source, context) {
3254
+ assertDictionary(source, context);
3255
+ const original = source;
3256
+ const autoAllocateChunkSize = original === null || original === undefined ? undefined : original.autoAllocateChunkSize;
3257
+ const cancel = original === null || original === undefined ? undefined : original.cancel;
3258
+ const pull = original === null || original === undefined ? undefined : original.pull;
3259
+ const start = original === null || original === undefined ? undefined : original.start;
3260
+ const type = original === null || original === undefined ? undefined : original.type;
3261
+ return {
3262
+ autoAllocateChunkSize: autoAllocateChunkSize === undefined ? undefined : convertUnsignedLongLongWithEnforceRange(autoAllocateChunkSize, `${context} has member 'autoAllocateChunkSize' that`),
3263
+ cancel: cancel === undefined ? undefined : convertUnderlyingSourceCancelCallback(cancel, original, `${context} has member 'cancel' that`),
3264
+ pull: pull === undefined ? undefined : convertUnderlyingSourcePullCallback(pull, original, `${context} has member 'pull' that`),
3265
+ start: start === undefined ? undefined : convertUnderlyingSourceStartCallback(start, original, `${context} has member 'start' that`),
3266
+ type: type === undefined ? undefined : convertReadableStreamType(type, `${context} has member 'type' that`)
3267
+ };
3268
+ }
3269
+ function convertUnderlyingSourceCancelCallback(fn, original, context) {
3270
+ assertFunction(fn, context);
3271
+ return (reason) => promiseCall(fn, original, [reason]);
3272
+ }
3273
+ function convertUnderlyingSourcePullCallback(fn, original, context) {
3274
+ assertFunction(fn, context);
3275
+ return (controller) => promiseCall(fn, original, [controller]);
3276
+ }
3277
+ function convertUnderlyingSourceStartCallback(fn, original, context) {
3278
+ assertFunction(fn, context);
3279
+ return (controller) => reflectCall(fn, original, [controller]);
3280
+ }
3281
+ function convertReadableStreamType(type, context) {
3282
+ type = `${type}`;
3283
+ if (type !== "bytes") {
3284
+ throw new TypeError(`${context} '${type}' is not a valid enumeration value for ReadableStreamType`);
3285
+ }
3286
+ return type;
3287
+ }
3288
+ function convertIteratorOptions(options, context) {
3289
+ assertDictionary(options, context);
3290
+ const preventCancel = options === null || options === undefined ? undefined : options.preventCancel;
3291
+ return { preventCancel: Boolean(preventCancel) };
3292
+ }
3293
+ function convertPipeOptions(options, context) {
3294
+ assertDictionary(options, context);
3295
+ const preventAbort = options === null || options === undefined ? undefined : options.preventAbort;
3296
+ const preventCancel = options === null || options === undefined ? undefined : options.preventCancel;
3297
+ const preventClose = options === null || options === undefined ? undefined : options.preventClose;
3298
+ const signal = options === null || options === undefined ? undefined : options.signal;
3299
+ if (signal !== undefined) {
3300
+ assertAbortSignal(signal, `${context} has member 'signal' that`);
3301
+ }
3302
+ return {
3303
+ preventAbort: Boolean(preventAbort),
3304
+ preventCancel: Boolean(preventCancel),
3305
+ preventClose: Boolean(preventClose),
3306
+ signal
3307
+ };
3308
+ }
3309
+ function assertAbortSignal(signal, context) {
3310
+ if (!isAbortSignal(signal)) {
3311
+ throw new TypeError(`${context} is not an AbortSignal.`);
3312
+ }
3313
+ }
3314
+ function convertReadableWritablePair(pair, context) {
3315
+ assertDictionary(pair, context);
3316
+ const readable = pair === null || pair === undefined ? undefined : pair.readable;
3317
+ assertRequiredField(readable, "readable", "ReadableWritablePair");
3318
+ assertReadableStream(readable, `${context} has member 'readable' that`);
3319
+ const writable = pair === null || pair === undefined ? undefined : pair.writable;
3320
+ assertRequiredField(writable, "writable", "ReadableWritablePair");
3321
+ assertWritableStream(writable, `${context} has member 'writable' that`);
3322
+ return { readable, writable };
3323
+ }
3324
+
3325
+ class ReadableStream2 {
3326
+ constructor(rawUnderlyingSource = {}, rawStrategy = {}) {
3327
+ if (rawUnderlyingSource === undefined) {
3328
+ rawUnderlyingSource = null;
3329
+ } else {
3330
+ assertObject(rawUnderlyingSource, "First parameter");
3331
+ }
3332
+ const strategy = convertQueuingStrategy(rawStrategy, "Second parameter");
3333
+ const underlyingSource = convertUnderlyingDefaultOrByteSource(rawUnderlyingSource, "First parameter");
3334
+ InitializeReadableStream(this);
3335
+ if (underlyingSource.type === "bytes") {
3336
+ if (strategy.size !== undefined) {
3337
+ throw new RangeError("The strategy for a byte stream cannot have a size function");
3338
+ }
3339
+ const highWaterMark = ExtractHighWaterMark(strategy, 0);
3340
+ SetUpReadableByteStreamControllerFromUnderlyingSource(this, underlyingSource, highWaterMark);
3341
+ } else {
3342
+ const sizeAlgorithm = ExtractSizeAlgorithm(strategy);
3343
+ const highWaterMark = ExtractHighWaterMark(strategy, 1);
3344
+ SetUpReadableStreamDefaultControllerFromUnderlyingSource(this, underlyingSource, highWaterMark, sizeAlgorithm);
3345
+ }
3346
+ }
3347
+ get locked() {
3348
+ if (!IsReadableStream(this)) {
3349
+ throw streamBrandCheckException$1("locked");
3350
+ }
3351
+ return IsReadableStreamLocked(this);
3352
+ }
3353
+ cancel(reason = undefined) {
3354
+ if (!IsReadableStream(this)) {
3355
+ return promiseRejectedWith(streamBrandCheckException$1("cancel"));
3356
+ }
3357
+ if (IsReadableStreamLocked(this)) {
3358
+ return promiseRejectedWith(new TypeError("Cannot cancel a stream that already has a reader"));
3359
+ }
3360
+ return ReadableStreamCancel(this, reason);
3361
+ }
3362
+ getReader(rawOptions = undefined) {
3363
+ if (!IsReadableStream(this)) {
3364
+ throw streamBrandCheckException$1("getReader");
3365
+ }
3366
+ const options = convertReaderOptions(rawOptions, "First parameter");
3367
+ if (options.mode === undefined) {
3368
+ return AcquireReadableStreamDefaultReader(this);
3369
+ }
3370
+ return AcquireReadableStreamBYOBReader(this);
3371
+ }
3372
+ pipeThrough(rawTransform, rawOptions = {}) {
3373
+ if (!IsReadableStream(this)) {
3374
+ throw streamBrandCheckException$1("pipeThrough");
3375
+ }
3376
+ assertRequiredArgument(rawTransform, 1, "pipeThrough");
3377
+ const transform = convertReadableWritablePair(rawTransform, "First parameter");
3378
+ const options = convertPipeOptions(rawOptions, "Second parameter");
3379
+ if (IsReadableStreamLocked(this)) {
3380
+ throw new TypeError("ReadableStream.prototype.pipeThrough cannot be used on a locked ReadableStream");
3381
+ }
3382
+ if (IsWritableStreamLocked(transform.writable)) {
3383
+ throw new TypeError("ReadableStream.prototype.pipeThrough cannot be used on a locked WritableStream");
3384
+ }
3385
+ const promise = ReadableStreamPipeTo(this, transform.writable, options.preventClose, options.preventAbort, options.preventCancel, options.signal);
3386
+ setPromiseIsHandledToTrue(promise);
3387
+ return transform.readable;
3388
+ }
3389
+ pipeTo(destination, rawOptions = {}) {
3390
+ if (!IsReadableStream(this)) {
3391
+ return promiseRejectedWith(streamBrandCheckException$1("pipeTo"));
3392
+ }
3393
+ if (destination === undefined) {
3394
+ return promiseRejectedWith(`Parameter 1 is required in 'pipeTo'.`);
3395
+ }
3396
+ if (!IsWritableStream(destination)) {
3397
+ return promiseRejectedWith(new TypeError(`ReadableStream.prototype.pipeTo's first argument must be a WritableStream`));
3398
+ }
3399
+ let options;
3400
+ try {
3401
+ options = convertPipeOptions(rawOptions, "Second parameter");
3402
+ } catch (e) {
3403
+ return promiseRejectedWith(e);
3404
+ }
3405
+ if (IsReadableStreamLocked(this)) {
3406
+ return promiseRejectedWith(new TypeError("ReadableStream.prototype.pipeTo cannot be used on a locked ReadableStream"));
3407
+ }
3408
+ if (IsWritableStreamLocked(destination)) {
3409
+ return promiseRejectedWith(new TypeError("ReadableStream.prototype.pipeTo cannot be used on a locked WritableStream"));
3410
+ }
3411
+ return ReadableStreamPipeTo(this, destination, options.preventClose, options.preventAbort, options.preventCancel, options.signal);
3412
+ }
3413
+ tee() {
3414
+ if (!IsReadableStream(this)) {
3415
+ throw streamBrandCheckException$1("tee");
3416
+ }
3417
+ const branches = ReadableStreamTee(this);
3418
+ return CreateArrayFromList(branches);
3419
+ }
3420
+ values(rawOptions = undefined) {
3421
+ if (!IsReadableStream(this)) {
3422
+ throw streamBrandCheckException$1("values");
3423
+ }
3424
+ const options = convertIteratorOptions(rawOptions, "First parameter");
3425
+ return AcquireReadableStreamAsyncIterator(this, options.preventCancel);
3426
+ }
3427
+ [SymbolAsyncIterator](options) {
3428
+ return this.values(options);
3429
+ }
3430
+ static from(asyncIterable) {
3431
+ return ReadableStreamFrom(asyncIterable);
3432
+ }
3433
+ }
3434
+ Object.defineProperties(ReadableStream2, {
3435
+ from: { enumerable: true }
3436
+ });
3437
+ Object.defineProperties(ReadableStream2.prototype, {
3438
+ cancel: { enumerable: true },
3439
+ getReader: { enumerable: true },
3440
+ pipeThrough: { enumerable: true },
3441
+ pipeTo: { enumerable: true },
3442
+ tee: { enumerable: true },
3443
+ values: { enumerable: true },
3444
+ locked: { enumerable: true }
3445
+ });
3446
+ setFunctionName(ReadableStream2.from, "from");
3447
+ setFunctionName(ReadableStream2.prototype.cancel, "cancel");
3448
+ setFunctionName(ReadableStream2.prototype.getReader, "getReader");
3449
+ setFunctionName(ReadableStream2.prototype.pipeThrough, "pipeThrough");
3450
+ setFunctionName(ReadableStream2.prototype.pipeTo, "pipeTo");
3451
+ setFunctionName(ReadableStream2.prototype.tee, "tee");
3452
+ setFunctionName(ReadableStream2.prototype.values, "values");
3453
+ if (typeof Symbol.toStringTag === "symbol") {
3454
+ Object.defineProperty(ReadableStream2.prototype, Symbol.toStringTag, {
3455
+ value: "ReadableStream",
3456
+ configurable: true
3457
+ });
3458
+ }
3459
+ Object.defineProperty(ReadableStream2.prototype, SymbolAsyncIterator, {
3460
+ value: ReadableStream2.prototype.values,
3461
+ writable: true,
3462
+ configurable: true
3463
+ });
3464
+ function CreateReadableStream(startAlgorithm, pullAlgorithm, cancelAlgorithm, highWaterMark = 1, sizeAlgorithm = () => 1) {
3465
+ const stream = Object.create(ReadableStream2.prototype);
3466
+ InitializeReadableStream(stream);
3467
+ const controller = Object.create(ReadableStreamDefaultController.prototype);
3468
+ SetUpReadableStreamDefaultController(stream, controller, startAlgorithm, pullAlgorithm, cancelAlgorithm, highWaterMark, sizeAlgorithm);
3469
+ return stream;
3470
+ }
3471
+ function CreateReadableByteStream(startAlgorithm, pullAlgorithm, cancelAlgorithm) {
3472
+ const stream = Object.create(ReadableStream2.prototype);
3473
+ InitializeReadableStream(stream);
3474
+ const controller = Object.create(ReadableByteStreamController.prototype);
3475
+ SetUpReadableByteStreamController(stream, controller, startAlgorithm, pullAlgorithm, cancelAlgorithm, 0, undefined);
3476
+ return stream;
3477
+ }
3478
+ function InitializeReadableStream(stream) {
3479
+ stream._state = "readable";
3480
+ stream._reader = undefined;
3481
+ stream._storedError = undefined;
3482
+ stream._disturbed = false;
3483
+ }
3484
+ function IsReadableStream(x) {
3485
+ if (!typeIsObject(x)) {
3486
+ return false;
3487
+ }
3488
+ if (!Object.prototype.hasOwnProperty.call(x, "_readableStreamController")) {
3489
+ return false;
3490
+ }
3491
+ return x instanceof ReadableStream2;
3492
+ }
3493
+ function IsReadableStreamLocked(stream) {
3494
+ if (stream._reader === undefined) {
3495
+ return false;
3496
+ }
3497
+ return true;
3498
+ }
3499
+ function ReadableStreamCancel(stream, reason) {
3500
+ stream._disturbed = true;
3501
+ if (stream._state === "closed") {
3502
+ return promiseResolvedWith(undefined);
3503
+ }
3504
+ if (stream._state === "errored") {
3505
+ return promiseRejectedWith(stream._storedError);
3506
+ }
3507
+ ReadableStreamClose(stream);
3508
+ const reader = stream._reader;
3509
+ if (reader !== undefined && IsReadableStreamBYOBReader(reader)) {
3510
+ const readIntoRequests = reader._readIntoRequests;
3511
+ reader._readIntoRequests = new SimpleQueue;
3512
+ readIntoRequests.forEach((readIntoRequest) => {
3513
+ readIntoRequest._closeSteps(undefined);
3514
+ });
3515
+ }
3516
+ const sourceCancelPromise = stream._readableStreamController[CancelSteps](reason);
3517
+ return transformPromiseWith(sourceCancelPromise, noop);
3518
+ }
3519
+ function ReadableStreamClose(stream) {
3520
+ stream._state = "closed";
3521
+ const reader = stream._reader;
3522
+ if (reader === undefined) {
3523
+ return;
3524
+ }
3525
+ defaultReaderClosedPromiseResolve(reader);
3526
+ if (IsReadableStreamDefaultReader(reader)) {
3527
+ const readRequests = reader._readRequests;
3528
+ reader._readRequests = new SimpleQueue;
3529
+ readRequests.forEach((readRequest) => {
3530
+ readRequest._closeSteps();
3531
+ });
3532
+ }
3533
+ }
3534
+ function ReadableStreamError(stream, e) {
3535
+ stream._state = "errored";
3536
+ stream._storedError = e;
3537
+ const reader = stream._reader;
3538
+ if (reader === undefined) {
3539
+ return;
3540
+ }
3541
+ defaultReaderClosedPromiseReject(reader, e);
3542
+ if (IsReadableStreamDefaultReader(reader)) {
3543
+ ReadableStreamDefaultReaderErrorReadRequests(reader, e);
3544
+ } else {
3545
+ ReadableStreamBYOBReaderErrorReadIntoRequests(reader, e);
3546
+ }
3547
+ }
3548
+ function streamBrandCheckException$1(name) {
3549
+ return new TypeError(`ReadableStream.prototype.${name} can only be used on a ReadableStream`);
3550
+ }
3551
+ function convertQueuingStrategyInit(init, context) {
3552
+ assertDictionary(init, context);
3553
+ const highWaterMark = init === null || init === undefined ? undefined : init.highWaterMark;
3554
+ assertRequiredField(highWaterMark, "highWaterMark", "QueuingStrategyInit");
3555
+ return {
3556
+ highWaterMark: convertUnrestrictedDouble(highWaterMark)
3557
+ };
3558
+ }
3559
+ const byteLengthSizeFunction = (chunk) => {
3560
+ return chunk.byteLength;
3561
+ };
3562
+ setFunctionName(byteLengthSizeFunction, "size");
3563
+
3564
+ class ByteLengthQueuingStrategy {
3565
+ constructor(options) {
3566
+ assertRequiredArgument(options, 1, "ByteLengthQueuingStrategy");
3567
+ options = convertQueuingStrategyInit(options, "First parameter");
3568
+ this._byteLengthQueuingStrategyHighWaterMark = options.highWaterMark;
3569
+ }
3570
+ get highWaterMark() {
3571
+ if (!IsByteLengthQueuingStrategy(this)) {
3572
+ throw byteLengthBrandCheckException("highWaterMark");
3573
+ }
3574
+ return this._byteLengthQueuingStrategyHighWaterMark;
3575
+ }
3576
+ get size() {
3577
+ if (!IsByteLengthQueuingStrategy(this)) {
3578
+ throw byteLengthBrandCheckException("size");
3579
+ }
3580
+ return byteLengthSizeFunction;
3581
+ }
3582
+ }
3583
+ Object.defineProperties(ByteLengthQueuingStrategy.prototype, {
3584
+ highWaterMark: { enumerable: true },
3585
+ size: { enumerable: true }
3586
+ });
3587
+ if (typeof Symbol.toStringTag === "symbol") {
3588
+ Object.defineProperty(ByteLengthQueuingStrategy.prototype, Symbol.toStringTag, {
3589
+ value: "ByteLengthQueuingStrategy",
3590
+ configurable: true
3591
+ });
3592
+ }
3593
+ function byteLengthBrandCheckException(name) {
3594
+ return new TypeError(`ByteLengthQueuingStrategy.prototype.${name} can only be used on a ByteLengthQueuingStrategy`);
3595
+ }
3596
+ function IsByteLengthQueuingStrategy(x) {
3597
+ if (!typeIsObject(x)) {
3598
+ return false;
3599
+ }
3600
+ if (!Object.prototype.hasOwnProperty.call(x, "_byteLengthQueuingStrategyHighWaterMark")) {
3601
+ return false;
3602
+ }
3603
+ return x instanceof ByteLengthQueuingStrategy;
3604
+ }
3605
+ const countSizeFunction = () => {
3606
+ return 1;
3607
+ };
3608
+ setFunctionName(countSizeFunction, "size");
3609
+
3610
+ class CountQueuingStrategy {
3611
+ constructor(options) {
3612
+ assertRequiredArgument(options, 1, "CountQueuingStrategy");
3613
+ options = convertQueuingStrategyInit(options, "First parameter");
3614
+ this._countQueuingStrategyHighWaterMark = options.highWaterMark;
3615
+ }
3616
+ get highWaterMark() {
3617
+ if (!IsCountQueuingStrategy(this)) {
3618
+ throw countBrandCheckException("highWaterMark");
3619
+ }
3620
+ return this._countQueuingStrategyHighWaterMark;
3621
+ }
3622
+ get size() {
3623
+ if (!IsCountQueuingStrategy(this)) {
3624
+ throw countBrandCheckException("size");
3625
+ }
3626
+ return countSizeFunction;
3627
+ }
3628
+ }
3629
+ Object.defineProperties(CountQueuingStrategy.prototype, {
3630
+ highWaterMark: { enumerable: true },
3631
+ size: { enumerable: true }
3632
+ });
3633
+ if (typeof Symbol.toStringTag === "symbol") {
3634
+ Object.defineProperty(CountQueuingStrategy.prototype, Symbol.toStringTag, {
3635
+ value: "CountQueuingStrategy",
3636
+ configurable: true
3637
+ });
3638
+ }
3639
+ function countBrandCheckException(name) {
3640
+ return new TypeError(`CountQueuingStrategy.prototype.${name} can only be used on a CountQueuingStrategy`);
3641
+ }
3642
+ function IsCountQueuingStrategy(x) {
3643
+ if (!typeIsObject(x)) {
3644
+ return false;
3645
+ }
3646
+ if (!Object.prototype.hasOwnProperty.call(x, "_countQueuingStrategyHighWaterMark")) {
3647
+ return false;
3648
+ }
3649
+ return x instanceof CountQueuingStrategy;
3650
+ }
3651
+ function convertTransformer(original, context) {
3652
+ assertDictionary(original, context);
3653
+ const cancel = original === null || original === undefined ? undefined : original.cancel;
3654
+ const flush = original === null || original === undefined ? undefined : original.flush;
3655
+ const readableType = original === null || original === undefined ? undefined : original.readableType;
3656
+ const start = original === null || original === undefined ? undefined : original.start;
3657
+ const transform = original === null || original === undefined ? undefined : original.transform;
3658
+ const writableType = original === null || original === undefined ? undefined : original.writableType;
3659
+ return {
3660
+ cancel: cancel === undefined ? undefined : convertTransformerCancelCallback(cancel, original, `${context} has member 'cancel' that`),
3661
+ flush: flush === undefined ? undefined : convertTransformerFlushCallback(flush, original, `${context} has member 'flush' that`),
3662
+ readableType,
3663
+ start: start === undefined ? undefined : convertTransformerStartCallback(start, original, `${context} has member 'start' that`),
3664
+ transform: transform === undefined ? undefined : convertTransformerTransformCallback(transform, original, `${context} has member 'transform' that`),
3665
+ writableType
3666
+ };
3667
+ }
3668
+ function convertTransformerFlushCallback(fn, original, context) {
3669
+ assertFunction(fn, context);
3670
+ return (controller) => promiseCall(fn, original, [controller]);
3671
+ }
3672
+ function convertTransformerStartCallback(fn, original, context) {
3673
+ assertFunction(fn, context);
3674
+ return (controller) => reflectCall(fn, original, [controller]);
3675
+ }
3676
+ function convertTransformerTransformCallback(fn, original, context) {
3677
+ assertFunction(fn, context);
3678
+ return (chunk, controller) => promiseCall(fn, original, [chunk, controller]);
3679
+ }
3680
+ function convertTransformerCancelCallback(fn, original, context) {
3681
+ assertFunction(fn, context);
3682
+ return (reason) => promiseCall(fn, original, [reason]);
3683
+ }
3684
+
3685
+ class TransformStream {
3686
+ constructor(rawTransformer = {}, rawWritableStrategy = {}, rawReadableStrategy = {}) {
3687
+ if (rawTransformer === undefined) {
3688
+ rawTransformer = null;
3689
+ }
3690
+ const writableStrategy = convertQueuingStrategy(rawWritableStrategy, "Second parameter");
3691
+ const readableStrategy = convertQueuingStrategy(rawReadableStrategy, "Third parameter");
3692
+ const transformer = convertTransformer(rawTransformer, "First parameter");
3693
+ if (transformer.readableType !== undefined) {
3694
+ throw new RangeError("Invalid readableType specified");
3695
+ }
3696
+ if (transformer.writableType !== undefined) {
3697
+ throw new RangeError("Invalid writableType specified");
3698
+ }
3699
+ const readableHighWaterMark = ExtractHighWaterMark(readableStrategy, 0);
3700
+ const readableSizeAlgorithm = ExtractSizeAlgorithm(readableStrategy);
3701
+ const writableHighWaterMark = ExtractHighWaterMark(writableStrategy, 1);
3702
+ const writableSizeAlgorithm = ExtractSizeAlgorithm(writableStrategy);
3703
+ let startPromise_resolve;
3704
+ const startPromise = newPromise((resolve) => {
3705
+ startPromise_resolve = resolve;
3706
+ });
3707
+ InitializeTransformStream(this, startPromise, writableHighWaterMark, writableSizeAlgorithm, readableHighWaterMark, readableSizeAlgorithm);
3708
+ SetUpTransformStreamDefaultControllerFromTransformer(this, transformer);
3709
+ if (transformer.start !== undefined) {
3710
+ startPromise_resolve(transformer.start(this._transformStreamController));
3711
+ } else {
3712
+ startPromise_resolve(undefined);
3713
+ }
3714
+ }
3715
+ get readable() {
3716
+ if (!IsTransformStream(this)) {
3717
+ throw streamBrandCheckException("readable");
3718
+ }
3719
+ return this._readable;
3720
+ }
3721
+ get writable() {
3722
+ if (!IsTransformStream(this)) {
3723
+ throw streamBrandCheckException("writable");
3724
+ }
3725
+ return this._writable;
3726
+ }
3727
+ }
3728
+ Object.defineProperties(TransformStream.prototype, {
3729
+ readable: { enumerable: true },
3730
+ writable: { enumerable: true }
3731
+ });
3732
+ if (typeof Symbol.toStringTag === "symbol") {
3733
+ Object.defineProperty(TransformStream.prototype, Symbol.toStringTag, {
3734
+ value: "TransformStream",
3735
+ configurable: true
3736
+ });
3737
+ }
3738
+ function InitializeTransformStream(stream, startPromise, writableHighWaterMark, writableSizeAlgorithm, readableHighWaterMark, readableSizeAlgorithm) {
3739
+ function startAlgorithm() {
3740
+ return startPromise;
3741
+ }
3742
+ function writeAlgorithm(chunk) {
3743
+ return TransformStreamDefaultSinkWriteAlgorithm(stream, chunk);
3744
+ }
3745
+ function abortAlgorithm(reason) {
3746
+ return TransformStreamDefaultSinkAbortAlgorithm(stream, reason);
3747
+ }
3748
+ function closeAlgorithm() {
3749
+ return TransformStreamDefaultSinkCloseAlgorithm(stream);
3750
+ }
3751
+ stream._writable = CreateWritableStream(startAlgorithm, writeAlgorithm, closeAlgorithm, abortAlgorithm, writableHighWaterMark, writableSizeAlgorithm);
3752
+ function pullAlgorithm() {
3753
+ return TransformStreamDefaultSourcePullAlgorithm(stream);
3754
+ }
3755
+ function cancelAlgorithm(reason) {
3756
+ return TransformStreamDefaultSourceCancelAlgorithm(stream, reason);
3757
+ }
3758
+ stream._readable = CreateReadableStream(startAlgorithm, pullAlgorithm, cancelAlgorithm, readableHighWaterMark, readableSizeAlgorithm);
3759
+ stream._backpressure = undefined;
3760
+ stream._backpressureChangePromise = undefined;
3761
+ stream._backpressureChangePromise_resolve = undefined;
3762
+ TransformStreamSetBackpressure(stream, true);
3763
+ stream._transformStreamController = undefined;
3764
+ }
3765
+ function IsTransformStream(x) {
3766
+ if (!typeIsObject(x)) {
3767
+ return false;
3768
+ }
3769
+ if (!Object.prototype.hasOwnProperty.call(x, "_transformStreamController")) {
3770
+ return false;
3771
+ }
3772
+ return x instanceof TransformStream;
3773
+ }
3774
+ function TransformStreamError(stream, e) {
3775
+ ReadableStreamDefaultControllerError(stream._readable._readableStreamController, e);
3776
+ TransformStreamErrorWritableAndUnblockWrite(stream, e);
3777
+ }
3778
+ function TransformStreamErrorWritableAndUnblockWrite(stream, e) {
3779
+ TransformStreamDefaultControllerClearAlgorithms(stream._transformStreamController);
3780
+ WritableStreamDefaultControllerErrorIfNeeded(stream._writable._writableStreamController, e);
3781
+ TransformStreamUnblockWrite(stream);
3782
+ }
3783
+ function TransformStreamUnblockWrite(stream) {
3784
+ if (stream._backpressure) {
3785
+ TransformStreamSetBackpressure(stream, false);
3786
+ }
3787
+ }
3788
+ function TransformStreamSetBackpressure(stream, backpressure) {
3789
+ if (stream._backpressureChangePromise !== undefined) {
3790
+ stream._backpressureChangePromise_resolve();
3791
+ }
3792
+ stream._backpressureChangePromise = newPromise((resolve) => {
3793
+ stream._backpressureChangePromise_resolve = resolve;
3794
+ });
3795
+ stream._backpressure = backpressure;
3796
+ }
3797
+
3798
+ class TransformStreamDefaultController {
3799
+ constructor() {
3800
+ throw new TypeError("Illegal constructor");
3801
+ }
3802
+ get desiredSize() {
3803
+ if (!IsTransformStreamDefaultController(this)) {
3804
+ throw defaultControllerBrandCheckException("desiredSize");
3805
+ }
3806
+ const readableController = this._controlledTransformStream._readable._readableStreamController;
3807
+ return ReadableStreamDefaultControllerGetDesiredSize(readableController);
3808
+ }
3809
+ enqueue(chunk = undefined) {
3810
+ if (!IsTransformStreamDefaultController(this)) {
3811
+ throw defaultControllerBrandCheckException("enqueue");
3812
+ }
3813
+ TransformStreamDefaultControllerEnqueue(this, chunk);
3814
+ }
3815
+ error(reason = undefined) {
3816
+ if (!IsTransformStreamDefaultController(this)) {
3817
+ throw defaultControllerBrandCheckException("error");
3818
+ }
3819
+ TransformStreamDefaultControllerError(this, reason);
3820
+ }
3821
+ terminate() {
3822
+ if (!IsTransformStreamDefaultController(this)) {
3823
+ throw defaultControllerBrandCheckException("terminate");
3824
+ }
3825
+ TransformStreamDefaultControllerTerminate(this);
3826
+ }
3827
+ }
3828
+ Object.defineProperties(TransformStreamDefaultController.prototype, {
3829
+ enqueue: { enumerable: true },
3830
+ error: { enumerable: true },
3831
+ terminate: { enumerable: true },
3832
+ desiredSize: { enumerable: true }
3833
+ });
3834
+ setFunctionName(TransformStreamDefaultController.prototype.enqueue, "enqueue");
3835
+ setFunctionName(TransformStreamDefaultController.prototype.error, "error");
3836
+ setFunctionName(TransformStreamDefaultController.prototype.terminate, "terminate");
3837
+ if (typeof Symbol.toStringTag === "symbol") {
3838
+ Object.defineProperty(TransformStreamDefaultController.prototype, Symbol.toStringTag, {
3839
+ value: "TransformStreamDefaultController",
3840
+ configurable: true
3841
+ });
3842
+ }
3843
+ function IsTransformStreamDefaultController(x) {
3844
+ if (!typeIsObject(x)) {
3845
+ return false;
3846
+ }
3847
+ if (!Object.prototype.hasOwnProperty.call(x, "_controlledTransformStream")) {
3848
+ return false;
3849
+ }
3850
+ return x instanceof TransformStreamDefaultController;
3851
+ }
3852
+ function SetUpTransformStreamDefaultController(stream, controller, transformAlgorithm, flushAlgorithm, cancelAlgorithm) {
3853
+ controller._controlledTransformStream = stream;
3854
+ stream._transformStreamController = controller;
3855
+ controller._transformAlgorithm = transformAlgorithm;
3856
+ controller._flushAlgorithm = flushAlgorithm;
3857
+ controller._cancelAlgorithm = cancelAlgorithm;
3858
+ controller._finishPromise = undefined;
3859
+ controller._finishPromise_resolve = undefined;
3860
+ controller._finishPromise_reject = undefined;
3861
+ }
3862
+ function SetUpTransformStreamDefaultControllerFromTransformer(stream, transformer) {
3863
+ const controller = Object.create(TransformStreamDefaultController.prototype);
3864
+ let transformAlgorithm;
3865
+ let flushAlgorithm;
3866
+ let cancelAlgorithm;
3867
+ if (transformer.transform !== undefined) {
3868
+ transformAlgorithm = (chunk) => transformer.transform(chunk, controller);
3869
+ } else {
3870
+ transformAlgorithm = (chunk) => {
3871
+ try {
3872
+ TransformStreamDefaultControllerEnqueue(controller, chunk);
3873
+ return promiseResolvedWith(undefined);
3874
+ } catch (transformResultE) {
3875
+ return promiseRejectedWith(transformResultE);
3876
+ }
3877
+ };
3878
+ }
3879
+ if (transformer.flush !== undefined) {
3880
+ flushAlgorithm = () => transformer.flush(controller);
3881
+ } else {
3882
+ flushAlgorithm = () => promiseResolvedWith(undefined);
3883
+ }
3884
+ if (transformer.cancel !== undefined) {
3885
+ cancelAlgorithm = (reason) => transformer.cancel(reason);
3886
+ } else {
3887
+ cancelAlgorithm = () => promiseResolvedWith(undefined);
3888
+ }
3889
+ SetUpTransformStreamDefaultController(stream, controller, transformAlgorithm, flushAlgorithm, cancelAlgorithm);
3890
+ }
3891
+ function TransformStreamDefaultControllerClearAlgorithms(controller) {
3892
+ controller._transformAlgorithm = undefined;
3893
+ controller._flushAlgorithm = undefined;
3894
+ controller._cancelAlgorithm = undefined;
3895
+ }
3896
+ function TransformStreamDefaultControllerEnqueue(controller, chunk) {
3897
+ const stream = controller._controlledTransformStream;
3898
+ const readableController = stream._readable._readableStreamController;
3899
+ if (!ReadableStreamDefaultControllerCanCloseOrEnqueue(readableController)) {
3900
+ throw new TypeError("Readable side is not in a state that permits enqueue");
3901
+ }
3902
+ try {
3903
+ ReadableStreamDefaultControllerEnqueue(readableController, chunk);
3904
+ } catch (e) {
3905
+ TransformStreamErrorWritableAndUnblockWrite(stream, e);
3906
+ throw stream._readable._storedError;
3907
+ }
3908
+ const backpressure = ReadableStreamDefaultControllerHasBackpressure(readableController);
3909
+ if (backpressure !== stream._backpressure) {
3910
+ TransformStreamSetBackpressure(stream, true);
3911
+ }
3912
+ }
3913
+ function TransformStreamDefaultControllerError(controller, e) {
3914
+ TransformStreamError(controller._controlledTransformStream, e);
3915
+ }
3916
+ function TransformStreamDefaultControllerPerformTransform(controller, chunk) {
3917
+ const transformPromise = controller._transformAlgorithm(chunk);
3918
+ return transformPromiseWith(transformPromise, undefined, (r) => {
3919
+ TransformStreamError(controller._controlledTransformStream, r);
3920
+ throw r;
3921
+ });
3922
+ }
3923
+ function TransformStreamDefaultControllerTerminate(controller) {
3924
+ const stream = controller._controlledTransformStream;
3925
+ const readableController = stream._readable._readableStreamController;
3926
+ ReadableStreamDefaultControllerClose(readableController);
3927
+ const error = new TypeError("TransformStream terminated");
3928
+ TransformStreamErrorWritableAndUnblockWrite(stream, error);
3929
+ }
3930
+ function TransformStreamDefaultSinkWriteAlgorithm(stream, chunk) {
3931
+ const controller = stream._transformStreamController;
3932
+ if (stream._backpressure) {
3933
+ const backpressureChangePromise = stream._backpressureChangePromise;
3934
+ return transformPromiseWith(backpressureChangePromise, () => {
3935
+ const writable = stream._writable;
3936
+ const state = writable._state;
3937
+ if (state === "erroring") {
3938
+ throw writable._storedError;
3939
+ }
3940
+ return TransformStreamDefaultControllerPerformTransform(controller, chunk);
3941
+ });
3942
+ }
3943
+ return TransformStreamDefaultControllerPerformTransform(controller, chunk);
3944
+ }
3945
+ function TransformStreamDefaultSinkAbortAlgorithm(stream, reason) {
3946
+ const controller = stream._transformStreamController;
3947
+ if (controller._finishPromise !== undefined) {
3948
+ return controller._finishPromise;
3949
+ }
3950
+ const readable = stream._readable;
3951
+ controller._finishPromise = newPromise((resolve, reject) => {
3952
+ controller._finishPromise_resolve = resolve;
3953
+ controller._finishPromise_reject = reject;
3954
+ });
3955
+ const cancelPromise = controller._cancelAlgorithm(reason);
3956
+ TransformStreamDefaultControllerClearAlgorithms(controller);
3957
+ uponPromise(cancelPromise, () => {
3958
+ if (readable._state === "errored") {
3959
+ defaultControllerFinishPromiseReject(controller, readable._storedError);
3960
+ } else {
3961
+ ReadableStreamDefaultControllerError(readable._readableStreamController, reason);
3962
+ defaultControllerFinishPromiseResolve(controller);
3963
+ }
3964
+ return null;
3965
+ }, (r) => {
3966
+ ReadableStreamDefaultControllerError(readable._readableStreamController, r);
3967
+ defaultControllerFinishPromiseReject(controller, r);
3968
+ return null;
3969
+ });
3970
+ return controller._finishPromise;
3971
+ }
3972
+ function TransformStreamDefaultSinkCloseAlgorithm(stream) {
3973
+ const controller = stream._transformStreamController;
3974
+ if (controller._finishPromise !== undefined) {
3975
+ return controller._finishPromise;
3976
+ }
3977
+ const readable = stream._readable;
3978
+ controller._finishPromise = newPromise((resolve, reject) => {
3979
+ controller._finishPromise_resolve = resolve;
3980
+ controller._finishPromise_reject = reject;
3981
+ });
3982
+ const flushPromise = controller._flushAlgorithm();
3983
+ TransformStreamDefaultControllerClearAlgorithms(controller);
3984
+ uponPromise(flushPromise, () => {
3985
+ if (readable._state === "errored") {
3986
+ defaultControllerFinishPromiseReject(controller, readable._storedError);
3987
+ } else {
3988
+ ReadableStreamDefaultControllerClose(readable._readableStreamController);
3989
+ defaultControllerFinishPromiseResolve(controller);
3990
+ }
3991
+ return null;
3992
+ }, (r) => {
3993
+ ReadableStreamDefaultControllerError(readable._readableStreamController, r);
3994
+ defaultControllerFinishPromiseReject(controller, r);
3995
+ return null;
3996
+ });
3997
+ return controller._finishPromise;
3998
+ }
3999
+ function TransformStreamDefaultSourcePullAlgorithm(stream) {
4000
+ TransformStreamSetBackpressure(stream, false);
4001
+ return stream._backpressureChangePromise;
4002
+ }
4003
+ function TransformStreamDefaultSourceCancelAlgorithm(stream, reason) {
4004
+ const controller = stream._transformStreamController;
4005
+ if (controller._finishPromise !== undefined) {
4006
+ return controller._finishPromise;
4007
+ }
4008
+ const writable = stream._writable;
4009
+ controller._finishPromise = newPromise((resolve, reject) => {
4010
+ controller._finishPromise_resolve = resolve;
4011
+ controller._finishPromise_reject = reject;
4012
+ });
4013
+ const cancelPromise = controller._cancelAlgorithm(reason);
4014
+ TransformStreamDefaultControllerClearAlgorithms(controller);
4015
+ uponPromise(cancelPromise, () => {
4016
+ if (writable._state === "errored") {
4017
+ defaultControllerFinishPromiseReject(controller, writable._storedError);
4018
+ } else {
4019
+ WritableStreamDefaultControllerErrorIfNeeded(writable._writableStreamController, reason);
4020
+ TransformStreamUnblockWrite(stream);
4021
+ defaultControllerFinishPromiseResolve(controller);
4022
+ }
4023
+ return null;
4024
+ }, (r) => {
4025
+ WritableStreamDefaultControllerErrorIfNeeded(writable._writableStreamController, r);
4026
+ TransformStreamUnblockWrite(stream);
4027
+ defaultControllerFinishPromiseReject(controller, r);
4028
+ return null;
4029
+ });
4030
+ return controller._finishPromise;
4031
+ }
4032
+ function defaultControllerBrandCheckException(name) {
4033
+ return new TypeError(`TransformStreamDefaultController.prototype.${name} can only be used on a TransformStreamDefaultController`);
4034
+ }
4035
+ function defaultControllerFinishPromiseResolve(controller) {
4036
+ if (controller._finishPromise_resolve === undefined) {
4037
+ return;
4038
+ }
4039
+ controller._finishPromise_resolve();
4040
+ controller._finishPromise_resolve = undefined;
4041
+ controller._finishPromise_reject = undefined;
4042
+ }
4043
+ function defaultControllerFinishPromiseReject(controller, reason) {
4044
+ if (controller._finishPromise_reject === undefined) {
4045
+ return;
4046
+ }
4047
+ setPromiseIsHandledToTrue(controller._finishPromise);
4048
+ controller._finishPromise_reject(reason);
4049
+ controller._finishPromise_resolve = undefined;
4050
+ controller._finishPromise_reject = undefined;
4051
+ }
4052
+ function streamBrandCheckException(name) {
4053
+ return new TypeError(`TransformStream.prototype.${name} can only be used on a TransformStream`);
4054
+ }
4055
+ exports2.ByteLengthQueuingStrategy = ByteLengthQueuingStrategy;
4056
+ exports2.CountQueuingStrategy = CountQueuingStrategy;
4057
+ exports2.ReadableByteStreamController = ReadableByteStreamController;
4058
+ exports2.ReadableStream = ReadableStream2;
4059
+ exports2.ReadableStreamBYOBReader = ReadableStreamBYOBReader;
4060
+ exports2.ReadableStreamBYOBRequest = ReadableStreamBYOBRequest;
4061
+ exports2.ReadableStreamDefaultController = ReadableStreamDefaultController;
4062
+ exports2.ReadableStreamDefaultReader = ReadableStreamDefaultReader;
4063
+ exports2.TransformStream = TransformStream;
4064
+ exports2.TransformStreamDefaultController = TransformStreamDefaultController;
4065
+ exports2.WritableStream = WritableStream;
4066
+ exports2.WritableStreamDefaultController = WritableStreamDefaultController;
4067
+ exports2.WritableStreamDefaultWriter = WritableStreamDefaultWriter;
4068
+ });
4069
+ });
4070
+
4071
+ // node_modules/fetch-blob/streams.cjs
4072
+ var require_streams = __commonJS(() => {
4073
+ var POOL_SIZE = 65536;
4074
+ if (!globalThis.ReadableStream) {
4075
+ try {
4076
+ const process = __require("node:process");
4077
+ const { emitWarning } = process;
4078
+ try {
4079
+ process.emitWarning = () => {};
4080
+ Object.assign(globalThis, __require("node:stream/web"));
4081
+ process.emitWarning = emitWarning;
4082
+ } catch (error) {
4083
+ process.emitWarning = emitWarning;
4084
+ throw error;
4085
+ }
4086
+ } catch (error) {
4087
+ Object.assign(globalThis, require_ponyfill_es2018());
4088
+ }
4089
+ }
4090
+ try {
4091
+ const { Blob } = __require("buffer");
4092
+ if (Blob && !Blob.prototype.stream) {
4093
+ Blob.prototype.stream = function name(params) {
4094
+ let position = 0;
4095
+ const blob = this;
4096
+ return new ReadableStream({
4097
+ type: "bytes",
4098
+ async pull(ctrl) {
4099
+ const chunk = blob.slice(position, Math.min(blob.size, position + POOL_SIZE));
4100
+ const buffer = await chunk.arrayBuffer();
4101
+ position += buffer.byteLength;
4102
+ ctrl.enqueue(new Uint8Array(buffer));
4103
+ if (position === blob.size) {
4104
+ ctrl.close();
4105
+ }
4106
+ }
4107
+ });
4108
+ };
4109
+ }
4110
+ } catch (error) {}
4111
+ });
4112
+
4113
+ // node_modules/fetch-blob/index.js
4114
+ async function* toIterator(parts, clone = true) {
4115
+ for (const part of parts) {
4116
+ if ("stream" in part) {
4117
+ yield* part.stream();
4118
+ } else if (ArrayBuffer.isView(part)) {
4119
+ if (clone) {
4120
+ let position = part.byteOffset;
4121
+ const end = part.byteOffset + part.byteLength;
4122
+ while (position !== end) {
4123
+ const size = Math.min(end - position, POOL_SIZE);
4124
+ const chunk = part.buffer.slice(position, position + size);
4125
+ position += chunk.byteLength;
4126
+ yield new Uint8Array(chunk);
4127
+ }
4128
+ } else {
4129
+ yield part;
4130
+ }
4131
+ } else {
4132
+ let position = 0, b = part;
4133
+ while (position !== b.size) {
4134
+ const chunk = b.slice(position, Math.min(b.size, position + POOL_SIZE));
4135
+ const buffer = await chunk.arrayBuffer();
4136
+ position += buffer.byteLength;
4137
+ yield new Uint8Array(buffer);
4138
+ }
4139
+ }
4140
+ }
4141
+ }
4142
+ var import_streams, POOL_SIZE = 65536, _Blob, Blob2, fetch_blob_default;
4143
+ var init_fetch_blob = __esm(() => {
4144
+ import_streams = __toESM(require_streams(), 1);
4145
+ /*! fetch-blob. MIT License. Jimmy Wärting <https://jimmy.warting.se/opensource> */
4146
+ _Blob = class Blob {
4147
+ #parts = [];
4148
+ #type = "";
4149
+ #size = 0;
4150
+ #endings = "transparent";
4151
+ constructor(blobParts = [], options = {}) {
4152
+ if (typeof blobParts !== "object" || blobParts === null) {
4153
+ throw new TypeError("Failed to construct 'Blob': The provided value cannot be converted to a sequence.");
4154
+ }
4155
+ if (typeof blobParts[Symbol.iterator] !== "function") {
4156
+ throw new TypeError("Failed to construct 'Blob': The object must have a callable @@iterator property.");
4157
+ }
4158
+ if (typeof options !== "object" && typeof options !== "function") {
4159
+ throw new TypeError("Failed to construct 'Blob': parameter 2 cannot convert to dictionary.");
4160
+ }
4161
+ if (options === null)
4162
+ options = {};
4163
+ const encoder = new TextEncoder;
4164
+ for (const element of blobParts) {
4165
+ let part;
4166
+ if (ArrayBuffer.isView(element)) {
4167
+ part = new Uint8Array(element.buffer.slice(element.byteOffset, element.byteOffset + element.byteLength));
4168
+ } else if (element instanceof ArrayBuffer) {
4169
+ part = new Uint8Array(element.slice(0));
4170
+ } else if (element instanceof Blob) {
4171
+ part = element;
4172
+ } else {
4173
+ part = encoder.encode(`${element}`);
4174
+ }
4175
+ this.#size += ArrayBuffer.isView(part) ? part.byteLength : part.size;
4176
+ this.#parts.push(part);
4177
+ }
4178
+ this.#endings = `${options.endings === undefined ? "transparent" : options.endings}`;
4179
+ const type = options.type === undefined ? "" : String(options.type);
4180
+ this.#type = /^[\x20-\x7E]*$/.test(type) ? type : "";
4181
+ }
4182
+ get size() {
4183
+ return this.#size;
4184
+ }
4185
+ get type() {
4186
+ return this.#type;
4187
+ }
4188
+ async text() {
4189
+ const decoder = new TextDecoder;
4190
+ let str = "";
4191
+ for await (const part of toIterator(this.#parts, false)) {
4192
+ str += decoder.decode(part, { stream: true });
4193
+ }
4194
+ str += decoder.decode();
4195
+ return str;
4196
+ }
4197
+ async arrayBuffer() {
4198
+ const data = new Uint8Array(this.size);
4199
+ let offset = 0;
4200
+ for await (const chunk of toIterator(this.#parts, false)) {
4201
+ data.set(chunk, offset);
4202
+ offset += chunk.length;
4203
+ }
4204
+ return data.buffer;
4205
+ }
4206
+ stream() {
4207
+ const it = toIterator(this.#parts, true);
4208
+ return new globalThis.ReadableStream({
4209
+ type: "bytes",
4210
+ async pull(ctrl) {
4211
+ const chunk = await it.next();
4212
+ chunk.done ? ctrl.close() : ctrl.enqueue(chunk.value);
4213
+ },
4214
+ async cancel() {
4215
+ await it.return();
4216
+ }
4217
+ });
4218
+ }
4219
+ slice(start = 0, end = this.size, type = "") {
4220
+ const { size } = this;
4221
+ let relativeStart = start < 0 ? Math.max(size + start, 0) : Math.min(start, size);
4222
+ let relativeEnd = end < 0 ? Math.max(size + end, 0) : Math.min(end, size);
4223
+ const span = Math.max(relativeEnd - relativeStart, 0);
4224
+ const parts = this.#parts;
4225
+ const blobParts = [];
4226
+ let added = 0;
4227
+ for (const part of parts) {
4228
+ if (added >= span) {
4229
+ break;
4230
+ }
4231
+ const size2 = ArrayBuffer.isView(part) ? part.byteLength : part.size;
4232
+ if (relativeStart && size2 <= relativeStart) {
4233
+ relativeStart -= size2;
4234
+ relativeEnd -= size2;
4235
+ } else {
4236
+ let chunk;
4237
+ if (ArrayBuffer.isView(part)) {
4238
+ chunk = part.subarray(relativeStart, Math.min(size2, relativeEnd));
4239
+ added += chunk.byteLength;
4240
+ } else {
4241
+ chunk = part.slice(relativeStart, Math.min(size2, relativeEnd));
4242
+ added += chunk.size;
4243
+ }
4244
+ relativeEnd -= size2;
4245
+ blobParts.push(chunk);
4246
+ relativeStart = 0;
4247
+ }
4248
+ }
4249
+ const blob = new Blob([], { type: String(type).toLowerCase() });
4250
+ blob.#size = span;
4251
+ blob.#parts = blobParts;
4252
+ return blob;
4253
+ }
4254
+ get [Symbol.toStringTag]() {
4255
+ return "Blob";
4256
+ }
4257
+ static [Symbol.hasInstance](object) {
4258
+ return object && typeof object === "object" && typeof object.constructor === "function" && (typeof object.stream === "function" || typeof object.arrayBuffer === "function") && /^(Blob|File)$/.test(object[Symbol.toStringTag]);
4259
+ }
4260
+ };
4261
+ Object.defineProperties(_Blob.prototype, {
4262
+ size: { enumerable: true },
4263
+ type: { enumerable: true },
4264
+ slice: { enumerable: true }
4265
+ });
4266
+ Blob2 = _Blob;
4267
+ fetch_blob_default = Blob2;
4268
+ });
4269
+
4270
+ // node_modules/fetch-blob/file.js
4271
+ var _File, File2, file_default;
4272
+ var init_file = __esm(() => {
4273
+ init_fetch_blob();
4274
+ _File = class File extends fetch_blob_default {
4275
+ #lastModified = 0;
4276
+ #name = "";
4277
+ constructor(fileBits, fileName, options = {}) {
4278
+ if (arguments.length < 2) {
4279
+ throw new TypeError(`Failed to construct 'File': 2 arguments required, but only ${arguments.length} present.`);
4280
+ }
4281
+ super(fileBits, options);
4282
+ if (options === null)
4283
+ options = {};
4284
+ const lastModified = options.lastModified === undefined ? Date.now() : Number(options.lastModified);
4285
+ if (!Number.isNaN(lastModified)) {
4286
+ this.#lastModified = lastModified;
4287
+ }
4288
+ this.#name = String(fileName);
4289
+ }
4290
+ get name() {
4291
+ return this.#name;
4292
+ }
4293
+ get lastModified() {
4294
+ return this.#lastModified;
4295
+ }
4296
+ get [Symbol.toStringTag]() {
4297
+ return "File";
4298
+ }
4299
+ static [Symbol.hasInstance](object) {
4300
+ return !!object && object instanceof fetch_blob_default && /^(File)$/.test(object[Symbol.toStringTag]);
4301
+ }
4302
+ };
4303
+ File2 = _File;
4304
+ file_default = File2;
4305
+ });
4306
+
4307
+ // node_modules/formdata-polyfill/esm.min.js
4308
+ function formDataToBlob(F, B = fetch_blob_default) {
4309
+ var b = `${r()}${r()}`.replace(/\./g, "").slice(-28).padStart(32, "-"), c = [], p = `--${b}\r
4310
+ Content-Disposition: form-data; name="`;
4311
+ F.forEach((v, n) => typeof v == "string" ? c.push(p + e(n) + `"\r
4312
+ \r
4313
+ ${v.replace(/\r(?!\n)|(?<!\r)\n/g, `\r
4314
+ `)}\r
4315
+ `) : c.push(p + e(n) + `"; filename="${e(v.name, 1)}"\r
4316
+ Content-Type: ${v.type || "application/octet-stream"}\r
4317
+ \r
4318
+ `, v, `\r
4319
+ `));
4320
+ c.push(`--${b}--`);
4321
+ return new B(c, { type: "multipart/form-data; boundary=" + b });
4322
+ }
4323
+ var t, i, h, r, m, f = (a, b, c) => (a += "", /^(Blob|File)$/.test(b && b[t]) ? [(c = c !== undefined ? c + "" : b[t] == "File" ? b.name : "blob", a), b.name !== c || b[t] == "blob" ? new file_default([b], c, b) : b] : [a, b + ""]), e = (c, f2) => (f2 ? c : c.replace(/\r?\n|\r/g, `\r
4324
+ `)).replace(/\n/g, "%0A").replace(/\r/g, "%0D").replace(/"/g, "%22"), x = (n, a, e2) => {
4325
+ if (a.length < e2) {
4326
+ throw new TypeError(`Failed to execute '${n}' on 'FormData': ${e2} arguments required, but only ${a.length} present.`);
4327
+ }
4328
+ }, FormData;
4329
+ var init_esm_min = __esm(() => {
4330
+ init_fetch_blob();
4331
+ init_file();
4332
+ /*! formdata-polyfill. MIT License. Jimmy Wärting <https://jimmy.warting.se/opensource> */
4333
+ ({ toStringTag: t, iterator: i, hasInstance: h } = Symbol);
4334
+ r = Math.random;
4335
+ m = "append,set,get,getAll,delete,keys,values,entries,forEach,constructor".split(",");
4336
+ FormData = class FormData2 {
4337
+ #d = [];
4338
+ constructor(...a) {
4339
+ if (a.length)
4340
+ throw new TypeError(`Failed to construct 'FormData': parameter 1 is not of type 'HTMLFormElement'.`);
4341
+ }
4342
+ get [t]() {
4343
+ return "FormData";
4344
+ }
4345
+ [i]() {
4346
+ return this.entries();
4347
+ }
4348
+ static [h](o) {
4349
+ return o && typeof o === "object" && o[t] === "FormData" && !m.some((m2) => typeof o[m2] != "function");
4350
+ }
4351
+ append(...a) {
4352
+ x("append", arguments, 2);
4353
+ this.#d.push(f(...a));
4354
+ }
4355
+ delete(a) {
4356
+ x("delete", arguments, 1);
4357
+ a += "";
4358
+ this.#d = this.#d.filter(([b]) => b !== a);
4359
+ }
4360
+ get(a) {
4361
+ x("get", arguments, 1);
4362
+ a += "";
4363
+ for (var b = this.#d, l = b.length, c = 0;c < l; c++)
4364
+ if (b[c][0] === a)
4365
+ return b[c][1];
4366
+ return null;
4367
+ }
4368
+ getAll(a, b) {
4369
+ x("getAll", arguments, 1);
4370
+ b = [];
4371
+ a += "";
4372
+ this.#d.forEach((c) => c[0] === a && b.push(c[1]));
4373
+ return b;
4374
+ }
4375
+ has(a) {
4376
+ x("has", arguments, 1);
4377
+ a += "";
4378
+ return this.#d.some((b) => b[0] === a);
4379
+ }
4380
+ forEach(a, b) {
4381
+ x("forEach", arguments, 1);
4382
+ for (var [c, d] of this)
4383
+ a.call(b, d, c, this);
4384
+ }
4385
+ set(...a) {
4386
+ x("set", arguments, 2);
4387
+ var b = [], c = true;
4388
+ a = f(...a);
4389
+ this.#d.forEach((d) => {
4390
+ d[0] === a[0] ? c && (c = !b.push(a)) : b.push(d);
4391
+ });
4392
+ c && b.push(a);
4393
+ this.#d = b;
4394
+ }
4395
+ *entries() {
4396
+ yield* this.#d;
4397
+ }
4398
+ *keys() {
4399
+ for (var [a] of this)
4400
+ yield a;
4401
+ }
4402
+ *values() {
4403
+ for (var [, a] of this)
4404
+ yield a;
4405
+ }
4406
+ };
4407
+ });
4408
+
4409
+ // node_modules/node-domexception/index.js
4410
+ var require_node_domexception = __commonJS((exports, module) => {
4411
+ /*! node-domexception. MIT License. Jimmy Wärting <https://jimmy.warting.se/opensource> */
4412
+ if (!globalThis.DOMException) {
4413
+ try {
4414
+ const { MessageChannel } = __require("worker_threads"), port = new MessageChannel().port1, ab = new ArrayBuffer;
4415
+ port.postMessage(ab, [ab, ab]);
4416
+ } catch (err) {
4417
+ err.constructor.name === "DOMException" && (globalThis.DOMException = err.constructor);
4418
+ }
4419
+ }
4420
+ module.exports = globalThis.DOMException;
4421
+ });
4422
+
4423
+ // node_modules/fetch-blob/from.js
4424
+ import { statSync, createReadStream, promises as fs } from "node:fs";
4425
+ import { basename } from "node:path";
4426
+ var import_node_domexception, stat, blobFromSync = (path, type) => fromBlob(statSync(path), path, type), blobFrom = (path, type) => stat(path).then((stat2) => fromBlob(stat2, path, type)), fileFrom = (path, type) => stat(path).then((stat2) => fromFile(stat2, path, type)), fileFromSync = (path, type) => fromFile(statSync(path), path, type), fromBlob = (stat2, path, type = "") => new fetch_blob_default([new BlobDataItem({
4427
+ path,
4428
+ size: stat2.size,
4429
+ lastModified: stat2.mtimeMs,
4430
+ start: 0
4431
+ })], { type }), fromFile = (stat2, path, type = "") => new file_default([new BlobDataItem({
4432
+ path,
4433
+ size: stat2.size,
4434
+ lastModified: stat2.mtimeMs,
4435
+ start: 0
4436
+ })], basename(path), { type, lastModified: stat2.mtimeMs }), BlobDataItem;
4437
+ var init_from = __esm(() => {
4438
+ init_file();
4439
+ init_fetch_blob();
4440
+ import_node_domexception = __toESM(require_node_domexception(), 1);
4441
+ ({ stat } = fs);
4442
+ BlobDataItem = class BlobDataItem {
4443
+ #path;
4444
+ #start;
4445
+ constructor(options) {
4446
+ this.#path = options.path;
4447
+ this.#start = options.start;
4448
+ this.size = options.size;
4449
+ this.lastModified = options.lastModified;
4450
+ }
4451
+ slice(start, end) {
4452
+ return new BlobDataItem({
4453
+ path: this.#path,
4454
+ lastModified: this.lastModified,
4455
+ size: end - start,
4456
+ start: this.#start + start
4457
+ });
4458
+ }
4459
+ async* stream() {
4460
+ const { mtimeMs } = await stat(this.#path);
4461
+ if (mtimeMs > this.lastModified) {
4462
+ throw new import_node_domexception.default("The requested file could not be read, typically due to permission problems that have occurred after a reference to a file was acquired.", "NotReadableError");
4463
+ }
4464
+ yield* createReadStream(this.#path, {
4465
+ start: this.#start,
4466
+ end: this.#start + this.size - 1
4467
+ });
4468
+ }
4469
+ get [Symbol.toStringTag]() {
4470
+ return "Blob";
4471
+ }
4472
+ };
4473
+ });
4474
+
4475
+ export { fetch_blob_default, init_fetch_blob, file_default, FormData, formDataToBlob, init_esm_min, blobFromSync, blobFrom, fileFrom, fileFromSync, init_from };