Proposal
- Add methods or properties to determine wether Stream instance is readable or writable.
- Add method or property to determine what amount of data has already written to/read from the stream.
- Add method or property to determine if Stream is canceled.
Explanation
Today ReadableStream and WritableStream classes have no properties or methods to determine are they alive, closed or disturbed on JS side. I found some opinions of core members that this behavior is unnecessary. In the same time it is using by browser itself for example in Response constructor. And I don’t see any reasonable explanation for this .
Such behavior makes impossible to implement some APIs which works with streams. Because a lack of this flags makes code unreliable and unpredictable.
I’m working on a web server compatible with WebAPI and it’s near to impossible to create Response object which could receive ReadableStream as constructor argument and to throw an exception if it was disturbed.
There is one hack which can be used to check if stream was disturbed by using Response’s constructor:
var stream = new ReadableStream()
stream.cancel()
try {
new Response(stream);
} catch (err) {
// Is disturbed
}
But I think it should be fixed in specification.