web-streams-polyfill 3.0.3 → 4.0.0-beta.1

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