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