web-streams-polyfill 4.4.0 → 4.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,784 @@
1
+ /**
2
+ * {@inheritDoc QueuingStrategy.size}
3
+ * @public
4
+ */
5
+ type QueuingStrategySizeCallback<T = any> = (chunk: T) => number;
6
+ /**
7
+ * @public
8
+ */
9
+ interface QueuingStrategyInit {
10
+ /**
11
+ * {@inheritDoc QueuingStrategy.highWaterMark}
12
+ */
13
+ highWaterMark: number;
14
+ }
15
+ /**
16
+ * A queuing strategy.
17
+ *
18
+ * @public
19
+ */
20
+ interface QueuingStrategy<T = any> {
21
+ /**
22
+ * A non-negative number indicating the high water mark of the stream using this queuing strategy.
23
+ */
24
+ highWaterMark?: number;
25
+ /**
26
+ * A function that computes and returns the finite non-negative size of the given chunk value.
27
+ */
28
+ size?: QueuingStrategySizeCallback<T>;
29
+ }
30
+ /**
31
+ * A result returned by {@link ReadableStreamDefaultReader.read}.
32
+ *
33
+ * @public
34
+ */
35
+ type ReadableStreamDefaultReadResult<T> = {
36
+ done: false;
37
+ value: T;
38
+ } | {
39
+ done: true;
40
+ value: undefined;
41
+ };
42
+ /**
43
+ * A default reader vended by a {@link ReadableStream}.
44
+ *
45
+ * @public
46
+ */
47
+ export declare class ReadableStreamDefaultReader<R = any> {
48
+ constructor(stream: ReadableStream<R>);
49
+ /**
50
+ * Returns a promise that will be fulfilled when the stream becomes closed,
51
+ * or rejected if the stream ever errors or the reader's lock is released before the stream finishes closing.
52
+ */
53
+ get closed(): Promise<undefined>;
54
+ /**
55
+ * If the reader is active, behaves the same as {@link ReadableStream.cancel | stream.cancel(reason)}.
56
+ */
57
+ cancel(reason?: any): Promise<void>;
58
+ /**
59
+ * Returns a promise that allows access to the next chunk from the stream's internal queue, if available.
60
+ *
61
+ * If reading a chunk causes the queue to become empty, more data will be pulled from the underlying source.
62
+ */
63
+ read(): Promise<ReadableStreamDefaultReadResult<R>>;
64
+ /**
65
+ * Releases the reader's lock on the corresponding stream. After the lock is released, the reader is no longer active.
66
+ * If the associated stream is errored when the lock is released, the reader will appear errored in the same way
67
+ * from now on; otherwise, the reader will appear closed.
68
+ *
69
+ * A reader's lock cannot be released while it still has a pending read request, i.e., if a promise returned by
70
+ * the reader's {@link ReadableStreamDefaultReader.read | read()} method has not yet been settled. Attempting to
71
+ * do so will throw a `TypeError` and leave the reader locked to the stream.
72
+ */
73
+ releaseLock(): void;
74
+ }
75
+ /**
76
+ * An async iterator returned by {@link ReadableStream.values}.
77
+ *
78
+ * @public
79
+ */
80
+ interface ReadableStreamAsyncIterator<R> extends AsyncIterableIterator<R> {
81
+ next(): Promise<IteratorResult<R, undefined>>;
82
+ return(value?: any): Promise<IteratorResult<any>>;
83
+ }
84
+ /**
85
+ * Options for {@link ReadableStream.(getReader:2)}.
86
+ *
87
+ * @public
88
+ */
89
+ interface ReadableStreamGetReaderOptions {
90
+ mode?: 'byob';
91
+ }
92
+ /**
93
+ * Options for {@link ReadableStreamBYOBReader.read | reading} a stream
94
+ * with a {@link ReadableStreamBYOBReader | BYOB reader}.
95
+ *
96
+ * @public
97
+ */
98
+ interface ReadableStreamBYOBReaderReadOptions {
99
+ min?: number;
100
+ }
101
+ /**
102
+ * A result returned by {@link ReadableStreamBYOBReader.read}.
103
+ *
104
+ * @public
105
+ */
106
+ type ReadableStreamBYOBReadResult<T extends ArrayBufferView> = {
107
+ done: false;
108
+ value: T;
109
+ } | {
110
+ done: true;
111
+ value: T | undefined;
112
+ };
113
+ /**
114
+ * A BYOB reader vended by a {@link ReadableStream}.
115
+ *
116
+ * @public
117
+ */
118
+ export declare class ReadableStreamBYOBReader {
119
+ constructor(stream: ReadableStream<Uint8Array>);
120
+ /**
121
+ * Returns a promise that will be fulfilled when the stream becomes closed, or rejected if the stream ever errors or
122
+ * the reader's lock is released before the stream finishes closing.
123
+ */
124
+ get closed(): Promise<undefined>;
125
+ /**
126
+ * If the reader is active, behaves the same as {@link ReadableStream.cancel | stream.cancel(reason)}.
127
+ */
128
+ cancel(reason?: any): Promise<void>;
129
+ /**
130
+ * Attempts to reads bytes into view, and returns a promise resolved with the result.
131
+ *
132
+ * If reading a chunk causes the queue to become empty, more data will be pulled from the underlying source.
133
+ */
134
+ read<T extends ArrayBufferView>(view: T, options?: ReadableStreamBYOBReaderReadOptions): Promise<ReadableStreamBYOBReadResult<T>>;
135
+ /**
136
+ * Releases the reader's lock on the corresponding stream. After the lock is released, the reader is no longer active.
137
+ * If the associated stream is errored when the lock is released, the reader will appear errored in the same way
138
+ * from now on; otherwise, the reader will appear closed.
139
+ *
140
+ * A reader's lock cannot be released while it still has a pending read request, i.e., if a promise returned by
141
+ * the reader's {@link ReadableStreamBYOBReader.read | read()} method has not yet been settled. Attempting to
142
+ * do so will throw a `TypeError` and leave the reader locked to the stream.
143
+ */
144
+ releaseLock(): void;
145
+ }
146
+ /** @public */
147
+ type UnderlyingSinkStartCallback = (controller: WritableStreamDefaultController) => void | PromiseLike<void>;
148
+ /** @public */
149
+ type UnderlyingSinkWriteCallback<W> = (chunk: W, controller: WritableStreamDefaultController) => void | PromiseLike<void>;
150
+ /** @public */
151
+ type UnderlyingSinkCloseCallback = () => void | PromiseLike<void>;
152
+ /** @public */
153
+ type UnderlyingSinkAbortCallback = (reason: any) => void | PromiseLike<void>;
154
+ /**
155
+ * An underlying sink for constructing a {@link WritableStream}.
156
+ *
157
+ * @public
158
+ */
159
+ interface UnderlyingSink<W = any> {
160
+ /**
161
+ * A function that is called immediately during creation of the {@link WritableStream}.
162
+ */
163
+ start?: UnderlyingSinkStartCallback;
164
+ /**
165
+ * A function that is called when a new chunk of data is ready to be written to the underlying sink. The stream
166
+ * implementation guarantees that this function will be called only after previous writes have succeeded, and never
167
+ * before {@link UnderlyingSink.start | start()} has succeeded or after {@link UnderlyingSink.close | close()} or
168
+ * {@link UnderlyingSink.abort | abort()} have been called.
169
+ *
170
+ * This function is used to actually send the data to the resource presented by the underlying sink, for example by
171
+ * calling a lower-level API.
172
+ */
173
+ write?: UnderlyingSinkWriteCallback<W>;
174
+ /**
175
+ * A function that is called after the producer signals, via
176
+ * {@link WritableStreamDefaultWriter.close | writer.close()}, that they are done writing chunks to the stream, and
177
+ * subsequently all queued-up writes have successfully completed.
178
+ *
179
+ * This function can perform any actions necessary to finalize or flush writes to the underlying sink, and release
180
+ * access to any held resources.
181
+ */
182
+ close?: UnderlyingSinkCloseCallback;
183
+ /**
184
+ * A function that is called after the producer signals, via {@link WritableStream.abort | stream.abort()} or
185
+ * {@link WritableStreamDefaultWriter.abort | writer.abort()}, that they wish to abort the stream. It takes as its
186
+ * argument the same value as was passed to those methods by the producer.
187
+ *
188
+ * Writable streams can additionally be aborted under certain conditions during piping; see the definition of the
189
+ * {@link ReadableStream.pipeTo | pipeTo()} method for more details.
190
+ *
191
+ * This function can clean up any held resources, much like {@link UnderlyingSink.close | close()}, but perhaps with
192
+ * some custom handling.
193
+ */
194
+ abort?: UnderlyingSinkAbortCallback;
195
+ type?: undefined;
196
+ }
197
+ /**
198
+ * A signal object that allows you to communicate with a request and abort it if required
199
+ * via its associated `AbortController` object.
200
+ *
201
+ * @remarks
202
+ * This is equivalent to the `AbortSignal` interface defined in TypeScript's DOM types or `@types/node`.
203
+ *
204
+ * @public
205
+ */
206
+ type AbortSignal = typeof globalThis extends {
207
+ AbortSignal: {
208
+ prototype: infer T;
209
+ };
210
+ } ? T : {
211
+ aborted: boolean;
212
+ readonly reason?: any;
213
+ addEventListener(type: 'abort', listener: () => void): void;
214
+ removeEventListener(type: 'abort', listener: () => void): void;
215
+ };
216
+ /**
217
+ * A writable stream represents a destination for data, into which you can write.
218
+ *
219
+ * @public
220
+ */
221
+ declare class WritableStream<W = any> {
222
+ constructor(underlyingSink?: UnderlyingSink<W>, strategy?: QueuingStrategy<W>);
223
+ /**
224
+ * Returns whether or not the writable stream is locked to a writer.
225
+ */
226
+ get locked(): boolean;
227
+ /**
228
+ * Aborts the stream, signaling that the producer can no longer successfully write to the stream and it is to be
229
+ * immediately moved to an errored state, with any queued-up writes discarded. This will also execute any abort
230
+ * mechanism of the underlying sink.
231
+ *
232
+ * The returned promise will fulfill if the stream shuts down successfully, or reject if the underlying sink signaled
233
+ * that there was an error doing so. Additionally, it will reject with a `TypeError` (without attempting to cancel
234
+ * the stream) if the stream is currently locked.
235
+ */
236
+ abort(reason?: any): Promise<void>;
237
+ /**
238
+ * Closes the stream. The underlying sink will finish processing any previously-written chunks, before invoking its
239
+ * close behavior. During this time any further attempts to write will fail (without erroring the stream).
240
+ *
241
+ * The method returns a promise that will fulfill if all remaining chunks are successfully written and the stream
242
+ * successfully closes, or rejects if an error is encountered during this process. Additionally, it will reject with
243
+ * a `TypeError` (without attempting to cancel the stream) if the stream is currently locked.
244
+ */
245
+ close(): Promise<undefined>;
246
+ /**
247
+ * Creates a {@link WritableStreamDefaultWriter | writer} and locks the stream to the new writer. While the stream
248
+ * is locked, no other writer can be acquired until this one is released.
249
+ *
250
+ * This functionality is especially useful for creating abstractions that desire the ability to write to a stream
251
+ * without interruption or interleaving. By getting a writer for the stream, you can ensure nobody else can write at
252
+ * the same time, which would cause the resulting written data to be unpredictable and probably useless.
253
+ */
254
+ getWriter(): WritableStreamDefaultWriter<W>;
255
+ }
256
+ /**
257
+ * A default writer vended by a {@link WritableStream}.
258
+ *
259
+ * @public
260
+ */
261
+ export declare class WritableStreamDefaultWriter<W = any> {
262
+ constructor(stream: WritableStream<W>);
263
+ /**
264
+ * Returns a promise that will be fulfilled when the stream becomes closed, or rejected if the stream ever errors or
265
+ * the writer’s lock is released before the stream finishes closing.
266
+ */
267
+ get closed(): Promise<undefined>;
268
+ /**
269
+ * Returns the desired size to fill the stream’s internal queue. It can be negative, if the queue is over-full.
270
+ * A producer can use this information to determine the right amount of data to write.
271
+ *
272
+ * It will be `null` if the stream cannot be successfully written to (due to either being errored, or having an abort
273
+ * queued up). It will return zero if the stream is closed. And the getter will throw an exception if invoked when
274
+ * the writer’s lock is released.
275
+ */
276
+ get desiredSize(): number | null;
277
+ /**
278
+ * Returns a promise that will be fulfilled when the desired size to fill the stream’s internal queue transitions
279
+ * from non-positive to positive, signaling that it is no longer applying backpressure. Once the desired size dips
280
+ * back to zero or below, the getter will return a new promise that stays pending until the next transition.
281
+ *
282
+ * If the stream becomes errored or aborted, or the writer’s lock is released, the returned promise will become
283
+ * rejected.
284
+ */
285
+ get ready(): Promise<undefined>;
286
+ /**
287
+ * If the reader is active, behaves the same as {@link WritableStream.abort | stream.abort(reason)}.
288
+ */
289
+ abort(reason?: any): Promise<void>;
290
+ /**
291
+ * If the reader is active, behaves the same as {@link WritableStream.close | stream.close()}.
292
+ */
293
+ close(): Promise<void>;
294
+ /**
295
+ * Releases the writer’s lock on the corresponding stream. After the lock is released, the writer is no longer active.
296
+ * If the associated stream is errored when the lock is released, the writer will appear errored in the same way from
297
+ * now on; otherwise, the writer will appear closed.
298
+ *
299
+ * Note that the lock can still be released even if some ongoing writes have not yet finished (i.e. even if the
300
+ * promises returned from previous calls to {@link WritableStreamDefaultWriter.write | write()} have not yet settled).
301
+ * It’s not necessary to hold the lock on the writer for the duration of the write; the lock instead simply prevents
302
+ * other producers from writing in an interleaved manner.
303
+ */
304
+ releaseLock(): void;
305
+ /**
306
+ * Writes the given chunk to the writable stream, by waiting until any previous writes have finished successfully,
307
+ * and then sending the chunk to the underlying sink's {@link UnderlyingSink.write | write()} method. It will return
308
+ * a promise that fulfills with undefined upon a successful write, or rejects if the write fails or stream becomes
309
+ * errored before the writing process is initiated.
310
+ *
311
+ * Note that what "success" means is up to the underlying sink; it might indicate simply that the chunk has been
312
+ * accepted, and not necessarily that it is safely saved to its ultimate destination.
313
+ */
314
+ write(chunk: W): Promise<void>;
315
+ }
316
+ /**
317
+ * Allows control of a {@link WritableStream | writable stream}'s state and internal queue.
318
+ *
319
+ * @public
320
+ */
321
+ export declare class WritableStreamDefaultController<W = any> {
322
+ private constructor();
323
+ /**
324
+ * The reason which was passed to `WritableStream.abort(reason)` when the stream was aborted.
325
+ *
326
+ * @deprecated
327
+ * This property has been removed from the specification, see https://github.com/whatwg/streams/pull/1177.
328
+ * Use {@link WritableStreamDefaultController.signal}'s `reason` instead.
329
+ */
330
+ get abortReason(): any;
331
+ /**
332
+ * An `AbortSignal` that can be used to abort the pending write or close operation when the stream is aborted.
333
+ */
334
+ get signal(): AbortSignal;
335
+ /**
336
+ * Closes the controlled writable stream, making all future interactions with it fail with the given error `e`.
337
+ *
338
+ * This method is rarely used, since usually it suffices to return a rejected promise from one of the underlying
339
+ * sink's methods. However, it can be useful for suddenly shutting down a stream in response to an event outside the
340
+ * normal lifecycle of interactions with the underlying sink.
341
+ */
342
+ error(e?: any): void;
343
+ }
344
+ /**
345
+ * Allows control of a {@link ReadableStream | readable stream}'s state and internal queue.
346
+ *
347
+ * @public
348
+ */
349
+ export declare class ReadableStreamDefaultController<R> {
350
+ private constructor();
351
+ /**
352
+ * Returns the desired size to fill the controlled stream's internal queue. It can be negative, if the queue is
353
+ * over-full. An underlying source ought to use this information to determine when and how to apply backpressure.
354
+ */
355
+ get desiredSize(): number | null;
356
+ /**
357
+ * Closes the controlled readable stream. Consumers will still be able to read any previously-enqueued chunks from
358
+ * the stream, but once those are read, the stream will become closed.
359
+ */
360
+ close(): void;
361
+ /**
362
+ * Enqueues the given chunk `chunk` in the controlled readable stream.
363
+ */
364
+ enqueue(chunk: R): void;
365
+ /**
366
+ * Errors the controlled readable stream, making all future interactions with it fail with the given error `e`.
367
+ */
368
+ error(e?: any): void;
369
+ }
370
+ /** @public */
371
+ type UnderlyingSourceStartCallback<R> = (controller: ReadableStreamDefaultController<R>) => void | PromiseLike<void>;
372
+ /** @public */
373
+ type UnderlyingSourcePullCallback<R> = (controller: ReadableStreamDefaultController<R>) => void | PromiseLike<void>;
374
+ /** @public */
375
+ type UnderlyingByteSourceStartCallback = (controller: ReadableByteStreamController) => void | PromiseLike<void>;
376
+ /** @public */
377
+ type UnderlyingByteSourcePullCallback = (controller: ReadableByteStreamController) => void | PromiseLike<void>;
378
+ /** @public */
379
+ type UnderlyingSourceCancelCallback = (reason: any) => void | PromiseLike<void>;
380
+ /**
381
+ * An underlying source for constructing a {@link ReadableStream}.
382
+ *
383
+ * @public
384
+ */
385
+ interface UnderlyingSource<R = any> {
386
+ /**
387
+ * A function that is called immediately during creation of the {@link ReadableStream}.
388
+ */
389
+ start?: UnderlyingSourceStartCallback<R>;
390
+ /**
391
+ * A function that is called whenever the stream’s internal queue of chunks becomes not full,
392
+ * i.e. whenever the queue’s desired size becomes positive. Generally, it will be called repeatedly
393
+ * until the queue reaches its high water mark (i.e. until the desired size becomes non-positive).
394
+ */
395
+ pull?: UnderlyingSourcePullCallback<R>;
396
+ /**
397
+ * A function that is called whenever the consumer cancels the stream, via
398
+ * {@link ReadableStream.cancel | stream.cancel()},
399
+ * {@link ReadableStreamDefaultReader.cancel | defaultReader.cancel()}, or
400
+ * {@link ReadableStreamBYOBReader.cancel | byobReader.cancel()}.
401
+ * It takes as its argument the same value as was passed to those methods by the consumer.
402
+ */
403
+ cancel?: UnderlyingSourceCancelCallback;
404
+ type?: undefined;
405
+ }
406
+ /**
407
+ * An underlying byte source for constructing a {@link ReadableStream}.
408
+ *
409
+ * @public
410
+ */
411
+ interface UnderlyingByteSource {
412
+ /**
413
+ * {@inheritDoc UnderlyingSource.start}
414
+ */
415
+ start?: UnderlyingByteSourceStartCallback;
416
+ /**
417
+ * {@inheritDoc UnderlyingSource.pull}
418
+ */
419
+ pull?: UnderlyingByteSourcePullCallback;
420
+ /**
421
+ * {@inheritDoc UnderlyingSource.cancel}
422
+ */
423
+ cancel?: UnderlyingSourceCancelCallback;
424
+ /**
425
+ * Can be set to "bytes" to signal that the constructed {@link ReadableStream} is a readable byte stream.
426
+ * This ensures that the resulting {@link ReadableStream} will successfully be able to vend BYOB readers via its
427
+ * {@link ReadableStream.(getReader:1) | getReader()} method.
428
+ * It also affects the controller argument passed to the {@link UnderlyingByteSource.start | start()}
429
+ * and {@link UnderlyingByteSource.pull | pull()} methods.
430
+ */
431
+ type: 'bytes';
432
+ /**
433
+ * Can be set to a positive integer to cause the implementation to automatically allocate buffers for the
434
+ * underlying source code to write into. In this case, when a consumer is using a default reader, the stream
435
+ * implementation will automatically allocate an ArrayBuffer of the given size, so that
436
+ * {@link ReadableByteStreamController.byobRequest | controller.byobRequest} is always present,
437
+ * as if the consumer was using a BYOB reader.
438
+ */
439
+ autoAllocateChunkSize?: number;
440
+ }
441
+ /**
442
+ * A pull-into request in a {@link ReadableByteStreamController}.
443
+ *
444
+ * @public
445
+ */
446
+ export declare class ReadableStreamBYOBRequest {
447
+ private constructor();
448
+ /**
449
+ * Returns the view for writing in to, or `null` if the BYOB request has already been responded to.
450
+ */
451
+ get view(): ArrayBufferView<ArrayBuffer> | null;
452
+ /**
453
+ * Indicates to the associated readable byte stream that `bytesWritten` bytes were written into
454
+ * {@link ReadableStreamBYOBRequest.view | view}, causing the result be surfaced to the consumer.
455
+ *
456
+ * After this method is called, {@link ReadableStreamBYOBRequest.view | view} will be transferred and no longer
457
+ * modifiable.
458
+ */
459
+ respond(bytesWritten: number): void;
460
+ /**
461
+ * Indicates to the associated readable byte stream that instead of writing into
462
+ * {@link ReadableStreamBYOBRequest.view | view}, the underlying byte source is providing a new `ArrayBufferView`,
463
+ * which will be given to the consumer of the readable byte stream.
464
+ *
465
+ * After this method is called, `view` will be transferred and no longer modifiable.
466
+ */
467
+ respondWithNewView(view: ArrayBufferView): void;
468
+ }
469
+ /**
470
+ * Allows control of a {@link ReadableStream | readable byte stream}'s state and internal queue.
471
+ *
472
+ * @public
473
+ */
474
+ export declare class ReadableByteStreamController {
475
+ private constructor();
476
+ /**
477
+ * Returns the current BYOB pull request, or `null` if there isn't one.
478
+ */
479
+ get byobRequest(): ReadableStreamBYOBRequest | null;
480
+ /**
481
+ * Returns the desired size to fill the controlled stream's internal queue. It can be negative, if the queue is
482
+ * over-full. An underlying byte source ought to use this information to determine when and how to apply backpressure.
483
+ */
484
+ get desiredSize(): number | null;
485
+ /**
486
+ * Closes the controlled readable stream. Consumers will still be able to read any previously-enqueued chunks from
487
+ * the stream, but once those are read, the stream will become closed.
488
+ */
489
+ close(): void;
490
+ /**
491
+ * Enqueues the given chunk chunk in the controlled readable stream.
492
+ * The chunk has to be an `ArrayBufferView` instance, or else a `TypeError` will be thrown.
493
+ */
494
+ enqueue(chunk: ArrayBufferView): void;
495
+ /**
496
+ * Errors the controlled readable stream, making all future interactions with it fail with the given error `e`.
497
+ */
498
+ error(e?: any): void;
499
+ }
500
+ /**
501
+ * Options for {@link ReadableStream.pipeTo | piping} a stream.
502
+ *
503
+ * @public
504
+ */
505
+ interface StreamPipeOptions {
506
+ /**
507
+ * If set to true, {@link ReadableStream.pipeTo} will not abort the writable stream if the readable stream errors.
508
+ */
509
+ preventAbort?: boolean;
510
+ /**
511
+ * If set to true, {@link ReadableStream.pipeTo} will not cancel the readable stream if the writable stream closes
512
+ * or errors.
513
+ */
514
+ preventCancel?: boolean;
515
+ /**
516
+ * If set to true, {@link ReadableStream.pipeTo} will not close the writable stream if the readable stream closes.
517
+ */
518
+ preventClose?: boolean;
519
+ /**
520
+ * Can be set to an {@link AbortSignal} to allow aborting an ongoing pipe operation via the corresponding
521
+ * `AbortController`. In this case, the source readable stream will be canceled, and the destination writable stream
522
+ * aborted, unless the respective options `preventCancel` or `preventAbort` are set.
523
+ */
524
+ signal?: AbortSignal;
525
+ }
526
+ /**
527
+ * Options for {@link ReadableStream.values | async iterating} a stream.
528
+ *
529
+ * @public
530
+ */
531
+ interface ReadableStreamIteratorOptions {
532
+ preventCancel?: boolean;
533
+ }
534
+ /**
535
+ * A pair of a {@link ReadableStream | readable stream} and {@link WritableStream | writable stream} that can be passed
536
+ * to {@link ReadableStream.pipeThrough}.
537
+ *
538
+ * @public
539
+ */
540
+ interface ReadableWritablePair<R, W> {
541
+ readable: ReadableStream<R>;
542
+ writable: WritableStream<W>;
543
+ }
544
+ /**
545
+ * A common interface for a `ReadadableStream` implementation.
546
+ *
547
+ * @public
548
+ */
549
+ interface ReadableStreamLike<R = any> {
550
+ readonly locked: boolean;
551
+ getReader(): ReadableStreamDefaultReaderLike<R>;
552
+ }
553
+ /**
554
+ * A common interface for a `ReadableStreamDefaultReader` implementation.
555
+ *
556
+ * @public
557
+ */
558
+ interface ReadableStreamDefaultReaderLike<R = any> {
559
+ readonly closed: Promise<undefined>;
560
+ cancel(reason?: any): Promise<void>;
561
+ read(): Promise<ReadableStreamDefaultReadResult<R>>;
562
+ releaseLock(): void;
563
+ }
564
+ /**
565
+ * A readable stream represents a source of data, from which you can read.
566
+ *
567
+ * @public
568
+ */
569
+ export declare class ReadableStream<R = any> implements AsyncIterable<R> {
570
+ constructor(underlyingSource: UnderlyingByteSource, strategy?: {
571
+ highWaterMark?: number;
572
+ size?: undefined;
573
+ });
574
+ constructor(underlyingSource?: UnderlyingSource<R>, strategy?: QueuingStrategy<R>);
575
+ /**
576
+ * Whether or not the readable stream is locked to a {@link ReadableStreamDefaultReader | reader}.
577
+ */
578
+ get locked(): boolean;
579
+ /**
580
+ * Cancels the stream, signaling a loss of interest in the stream by a consumer.
581
+ *
582
+ * The supplied `reason` argument will be given to the underlying source's {@link UnderlyingSource.cancel | cancel()}
583
+ * method, which might or might not use it.
584
+ */
585
+ cancel(reason?: any): Promise<void>;
586
+ /**
587
+ * Creates a {@link ReadableStreamBYOBReader} and locks the stream to the new reader.
588
+ *
589
+ * This call behaves the same way as the no-argument variant, except that it only works on readable byte streams,
590
+ * i.e. streams which were constructed specifically with the ability to handle "bring your own buffer" reading.
591
+ * The returned BYOB reader provides the ability to directly read individual chunks from the stream via its
592
+ * {@link ReadableStreamBYOBReader.read | read()} method, into developer-supplied buffers, allowing more precise
593
+ * control over allocation.
594
+ */
595
+ getReader(options: {
596
+ mode: 'byob';
597
+ }): ReadableStreamBYOBReader;
598
+ /**
599
+ * Creates a {@link ReadableStreamDefaultReader} and locks the stream to the new reader.
600
+ * While the stream is locked, no other reader can be acquired until this one is released.
601
+ *
602
+ * This functionality is especially useful for creating abstractions that desire the ability to consume a stream
603
+ * in its entirety. By getting a reader for the stream, you can ensure nobody else can interleave reads with yours
604
+ * or cancel the stream, which would interfere with your abstraction.
605
+ */
606
+ getReader(): ReadableStreamDefaultReader<R>;
607
+ /**
608
+ * Creates a {@link ReadableStreamReader} and locks the stream to the new reader.
609
+ */
610
+ getReader(options?: ReadableStreamGetReaderOptions | undefined): ReadableStreamReader<R>;
611
+ /**
612
+ * Provides a convenient, chainable way of piping this readable stream through a transform stream
613
+ * (or any other `{ writable, readable }` pair). It simply {@link ReadableStream.pipeTo | pipes} the stream
614
+ * into the writable side of the supplied pair, and returns the readable side for further use.
615
+ *
616
+ * Piping a stream will lock it for the duration of the pipe, preventing any other consumer from acquiring a reader.
617
+ */
618
+ pipeThrough<RS extends ReadableStream>(transform: {
619
+ readable: RS;
620
+ writable: WritableStream<R>;
621
+ }, options?: StreamPipeOptions): RS;
622
+ /**
623
+ * Pipes this readable stream to a given writable stream. The way in which the piping process behaves under
624
+ * various error conditions can be customized with a number of passed options. It returns a promise that fulfills
625
+ * when the piping process completes successfully, or rejects if any errors were encountered.
626
+ *
627
+ * Piping a stream will lock it for the duration of the pipe, preventing any other consumer from acquiring a reader.
628
+ */
629
+ pipeTo(destination: WritableStream<R>, options?: StreamPipeOptions): Promise<void>;
630
+ /**
631
+ * Tees this readable stream, returning a two-element array containing the two resulting branches as
632
+ * new {@link ReadableStream} instances.
633
+ *
634
+ * Teeing a stream will lock it, preventing any other consumer from acquiring a reader.
635
+ * To cancel the stream, cancel both of the resulting branches; a composite cancellation reason will then be
636
+ * propagated to the stream's underlying source.
637
+ *
638
+ * Note that the chunks seen in each branch will be the same object. If the chunks are not immutable,
639
+ * this could allow interference between the two branches.
640
+ */
641
+ tee(): [ReadableStream<R>, ReadableStream<R>];
642
+ /**
643
+ * Asynchronously iterates over the chunks in the stream's internal queue.
644
+ *
645
+ * Asynchronously iterating over the stream will lock it, preventing any other consumer from acquiring a reader.
646
+ * The lock will be released if the async iterator's {@link ReadableStreamAsyncIterator.return | return()} method
647
+ * is called, e.g. by breaking out of the loop.
648
+ *
649
+ * By default, calling the async iterator's {@link ReadableStreamAsyncIterator.return | return()} method will also
650
+ * cancel the stream. To prevent this, use the stream's {@link ReadableStream.values | values()} method, passing
651
+ * `true` for the `preventCancel` option.
652
+ */
653
+ values(options?: ReadableStreamIteratorOptions): ReadableStreamAsyncIterator<R>;
654
+ /**
655
+ * {@inheritDoc ReadableStream.values}
656
+ */
657
+ [Symbol.asyncIterator](options?: ReadableStreamIteratorOptions): ReadableStreamAsyncIterator<R>;
658
+ /**
659
+ * Creates a new ReadableStream wrapping the provided iterable or async iterable.
660
+ *
661
+ * This can be used to adapt various kinds of objects into a readable stream,
662
+ * such as an array, an async generator, or a Node.js readable stream.
663
+ */
664
+ static from<R>(asyncIterable: Iterable<R> | AsyncIterable<R> | ReadableStreamLike<R>): ReadableStream<R>;
665
+ }
666
+ /**
667
+ * A reader vended by a {@link ReadableStream}.
668
+ *
669
+ * @public
670
+ */
671
+ type ReadableStreamReader<R> = ReadableStreamDefaultReader<R> | ReadableStreamBYOBReader;
672
+ /**
673
+ * A queuing strategy that counts the number of bytes in each chunk.
674
+ *
675
+ * @public
676
+ */
677
+ declare class ByteLengthQueuingStrategy implements QueuingStrategy<ArrayBufferView> {
678
+ constructor(options: QueuingStrategyInit);
679
+ /**
680
+ * Returns the high water mark provided to the constructor.
681
+ */
682
+ get highWaterMark(): number;
683
+ /**
684
+ * Measures the size of `chunk` by returning the value of its `byteLength` property.
685
+ */
686
+ get size(): (chunk: ArrayBufferView) => number;
687
+ }
688
+ /**
689
+ * A queuing strategy that counts the number of chunks.
690
+ *
691
+ * @public
692
+ */
693
+ declare class CountQueuingStrategy implements QueuingStrategy<any> {
694
+ constructor(options: QueuingStrategyInit);
695
+ /**
696
+ * Returns the high water mark provided to the constructor.
697
+ */
698
+ get highWaterMark(): number;
699
+ /**
700
+ * Measures the size of `chunk` by always returning 1.
701
+ * This ensures that the total queue size is a count of the number of chunks in the queue.
702
+ */
703
+ get size(): (chunk: any) => 1;
704
+ }
705
+ /** @public */
706
+ type TransformerStartCallback<O> = (controller: TransformStreamDefaultController<O>) => void | PromiseLike<void>;
707
+ /** @public */
708
+ type TransformerFlushCallback<O> = (controller: TransformStreamDefaultController<O>) => void | PromiseLike<void>;
709
+ /** @public */
710
+ type TransformerTransformCallback<I, O> = (chunk: I, controller: TransformStreamDefaultController<O>) => void | PromiseLike<void>;
711
+ /** @public */
712
+ type TransformerCancelCallback = (reason: any) => void | PromiseLike<void>;
713
+ /**
714
+ * A transformer for constructing a {@link TransformStream}.
715
+ *
716
+ * @public
717
+ */
718
+ interface Transformer<I = any, O = any> {
719
+ /**
720
+ * A function that is called immediately during creation of the {@link TransformStream}.
721
+ */
722
+ start?: TransformerStartCallback<O>;
723
+ /**
724
+ * A function called when a new chunk originally written to the writable side is ready to be transformed.
725
+ */
726
+ transform?: TransformerTransformCallback<I, O>;
727
+ /**
728
+ * A function called after all chunks written to the writable side have been transformed by successfully passing
729
+ * through {@link Transformer.transform | transform()}, and the writable side is about to be closed.
730
+ */
731
+ flush?: TransformerFlushCallback<O>;
732
+ /**
733
+ * A function called when the readable side is cancelled, or when the writable side is aborted.
734
+ */
735
+ cancel?: TransformerCancelCallback;
736
+ readableType?: undefined;
737
+ writableType?: undefined;
738
+ }
739
+ /**
740
+ * A transform stream consists of a pair of streams: a {@link WritableStream | writable stream},
741
+ * known as its writable side, and a {@link ReadableStream | readable stream}, known as its readable side.
742
+ * In a manner specific to the transform stream in question, writes to the writable side result in new data being
743
+ * made available for reading from the readable side.
744
+ *
745
+ * @public
746
+ */
747
+ export declare class TransformStream<I = any, O = any> {
748
+ constructor(transformer?: Transformer<I, O>, writableStrategy?: QueuingStrategy<I>, readableStrategy?: QueuingStrategy<O>);
749
+ /**
750
+ * The readable side of the transform stream.
751
+ */
752
+ get readable(): ReadableStream<O>;
753
+ /**
754
+ * The writable side of the transform stream.
755
+ */
756
+ get writable(): WritableStream<I>;
757
+ }
758
+ /**
759
+ * Allows control of the {@link ReadableStream} and {@link WritableStream} of the associated {@link TransformStream}.
760
+ *
761
+ * @public
762
+ */
763
+ export declare class TransformStreamDefaultController<O> {
764
+ private constructor();
765
+ /**
766
+ * Returns the desired size to fill the readable side’s internal queue. It can be negative, if the queue is over-full.
767
+ */
768
+ get desiredSize(): number | null;
769
+ /**
770
+ * Enqueues the given chunk `chunk` in the readable side of the controlled transform stream.
771
+ */
772
+ enqueue(chunk: O): void;
773
+ /**
774
+ * Errors both the readable side and the writable side of the controlled transform stream, making all future
775
+ * interactions with it fail with the given error `e`. Any chunks queued for transformation will be discarded.
776
+ */
777
+ error(reason?: any): void;
778
+ /**
779
+ * Closes the readable side and errors the writable side of the controlled transform stream. This is useful when the
780
+ * transformer only needs to consume a portion of the chunks written to the writable side.
781
+ */
782
+ terminate(): void;
783
+ }
784
+ export { type AbortSignal, ByteLengthQueuingStrategy, CountQueuingStrategy, type QueuingStrategy, type QueuingStrategyInit, type QueuingStrategySizeCallback, type ReadableStreamAsyncIterator, type ReadableStreamBYOBReadResult, type ReadableStreamBYOBReaderReadOptions, type ReadableStreamDefaultReadResult, type ReadableStreamDefaultReaderLike, type ReadableStreamGetReaderOptions, type ReadableStreamIteratorOptions, type ReadableStreamLike, type ReadableStreamReader, type ReadableWritablePair, type StreamPipeOptions, type Transformer, type TransformerCancelCallback, type TransformerFlushCallback, type TransformerStartCallback, type TransformerTransformCallback, type UnderlyingByteSource, type UnderlyingByteSourcePullCallback, type UnderlyingByteSourceStartCallback, type UnderlyingSink, type UnderlyingSinkAbortCallback, type UnderlyingSinkCloseCallback, type UnderlyingSinkStartCallback, type UnderlyingSinkWriteCallback, type UnderlyingSource, type UnderlyingSourceCancelCallback, type UnderlyingSourcePullCallback, type UnderlyingSourceStartCallback, WritableStream };