whatwg / streams

Streams Standard
https://streams.spec.whatwg.org/
Other
1.35k stars 161 forks source link

createStream method #36

Closed Ayms closed 11 years ago

Ayms commented 11 years ago

Copy of Domenic's reply to the createStream proposal:

Regarding cryptoStreams, I have proposed something like (idea coming from node): crypto.subtle.encrypt(xxx).createStream

I do not think these factory functions are a very good interface. Nobody is going to be generically testing to see "does this random thing, which might be crypto-related or might be XHR or might be filesystem, have a createStream method?" And of course it fails to distinguish between readable and writable. Instead, I think there are a few general ways streams will be produced:

  • With constructors, e.g. new StreamingWebSocket(endpoint)
  • Duplex streams as constructable objects with in and out properties (probably), e.g. new SerialPort(path).
  • As returned from async operations, e.g. http.get("url").then((responseStream) => ...).

Letting each API provide what is natural seems better than trying to create a uniform interface that is not useful to people anyway. And anyway,

you don't have to modify the spec and just say that it is supporting the Streams API (and its createStream method)

seems like a pipe dream, as you would of course have to give details on how the data streams. E.g., what is the default high water mark for a given readable or writable stream? Is it customizable? What type of objects stream---ArrayBuffers, strings, parsed JSON objects, CanvasPixelDataArrays, or whatever the user passes in, as in e.g. the case of web workers as duplex streams? What type of errors can be communicated, and how? What does calling abort do in terms of the underlying protocol? Does creating the stream have any side effects (in terms of used resources like sockets etc.)?

As an analogy, it would be very silly for the promises spec to propose a createPromise API, and say that you don't have to modify a spec, you just just support the Promise API and its createPromise method. What would the promise even be for? How would it behave? Etc.

There are so many questions to answer when designing a streaming interface, and trying to abdicate responsibility for them under a single "you have createStream, that means you're streaming," seems very bad.

domenic commented 11 years ago

I didn't really see any response to this, so, closing.