Skip to content

Commit

Permalink
Merge pull request #99 from MattiasBuelens/rewrite-pipe
Browse files Browse the repository at this point in the history
Rewrite ReadableStream.pipeTo() using the public API
  • Loading branch information
MattiasBuelens authored Oct 27, 2021
2 parents fc843b9 + 4903491 commit 4d0d23f
Show file tree
Hide file tree
Showing 8 changed files with 418 additions and 101 deletions.
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,9 @@ It aims to pass all tests, although it allows some exceptions for practical reas
* The tests [with patched globals][wpt-rs-patched-global] and [with `Object.prototype.then`][wpt-then-interception].
These tests are meant for browsers to ensure user-land modifications cannot affect the internal logic of `pipeTo()` and `tee()`.
However, it's not reasonable or desirable for a user-land polyfill to try and isolate itself completely from using the global `Object`.
* Certain `pipeTo()` tests that require synchronous inspection of the stream's state ([1][wpt-pipe-sync-state-1], [2][wpt-pipe-sync-state-2]).
Because the polyfill uses the public `getReader()` and `getWriter()` API to implement `pipeTo()`, it can only *asynchronously* observe if and when a stream becomes closed or errored.
Therefore, when the readable and the writable end become errored *at the exact same time*, it's difficult for the polyfill to observe these state changes in exactly the same order.
* The ES5 variant passes the same tests as the ES2015 variant, except for various tests about specific characteristics of the constructors, properties and methods.
These test failures do not affect the run-time behavior of the polyfill.
For example:
Expand Down Expand Up @@ -127,4 +130,6 @@ Thanks to these people for their work on [the original polyfill][creatorrr-polyf
[stub-async-iterator-prototype]: https://github.com/MattiasBuelens/web-streams-polyfill/blob/v4.0.0-beta.1/src/lib/readable-stream/async-iterator.ts#L153-L161
[wpt-rs-patched-global]: https://github.com/web-platform-tests/wpt/blob/887350c2f46def5b01c4dd1f8d2eee35dfb9c5bb/streams/readable-streams/patched-global.any.js
[wpt-then-interception]: https://github.com/web-platform-tests/wpt/blob/cf33f00596af295ee0f207c88e23b5f8b0791307/streams/piping/then-interception.any.js
[wpt-pipe-sync-state-1]: https://github.com/web-platform-tests/wpt/blob/e1e713c842e54ea0a9410ddc988b63d0e1d31973/streams/piping/multiple-propagation.any.js#L30-L53
[wpt-pipe-sync-state-2]: https://github.com/web-platform-tests/wpt/blob/e1e713c842e54ea0a9410ddc988b63d0e1d31973/streams/piping/multiple-propagation.any.js#L114-L138
[creatorrr-polyfill]: https://github.com/creatorrr/web-streams-polyfill
2 changes: 1 addition & 1 deletion src/lib/readable-stream.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ export type ReadableByteStream = ReadableStream<Uint8Array> & {
_readableStreamController: ReadableByteStreamController
};

type ReadableStreamState = 'readable' | 'closed' | 'errored';
export type ReadableStreamState = 'readable' | 'closed' | 'errored';

/**
* A readable stream represents a source of data, from which you can read.
Expand Down
Loading

0 comments on commit 4d0d23f

Please sign in to comment.