Re: [streams] Clarify how/whether Stream/TransformStream may read/write "messages" (#249)

Thanks for the clarification!

The text for #chunk looks pretty good, for the question I have. It might be
useful to point out how the type is identified, e.g. via metadata where the
stream is produced, or chunks may have "envelopes" if mixed types are
allowed.

It may also be useful to add the JSON and WS use cases to "2.3 Transform
Streams" as the current examples are all towards byte-streams.

P.S. it would be nice if there is a set of common terminologies for
describing streams, messages, chunks .. across different languages,
protocols v.s. APIs ... ;)


to clarify if the stream API may be used to send/receive atomic messages,
> in addition to byte-arrays.
>
> Ah! That is indeed explicitly supported:
> https://streams.spec.whatwg.org/#chunk
>
> Response C-T is application/json. The server is streaming a list of
> "entities" as a JSON array to the client application. Then, could I install
> a custom or predefined Transform function so that each chunk as delivered
> by the Stream API will represent a valid JSON element (or any array of
> elements).
>
> Yep, this is exactly the envisioned way for streams to work. You might get
> a raw byte stream representing the HTTP response body from fetch(), but
> then you could pipe it through a transform stream that transforms it into
> streams of JavaScript objects, one per each JSON object or similar. In code:
>
> var byteStream = fetch("https://example.com/newline-delimited-json").body;var transform = new NewlineDelimitedJSONTransform();var jsObjectStream = byteStream.pipeThrough(transform);
>
> (An example of something similar to NewlineDelimitedJSONTransform, albeit
> for Node.js streams instead of the streams described in this spec, is
> https://github.com/maxogden/ndjson)
>
> 1.1 states that we should respect any wire-level message framing, as in
> the case of WebSocket.
>
> Yeah, this is definitely the intent. The implementer of a (for-now
> hypothetical) WebSocketStream would use the framing information to
> determine what data to enqueue in the stream, or whether to enqueue an
> error or close the stream.
>
> —
> Reply to this email directly or view it on GitHub
> <https://github.com/whatwg/streams/issues/249#issuecomment-66810921>.
>

---
Reply to this email directly or view it on GitHub:
https://github.com/whatwg/streams/issues/249#issuecomment-67584988

Received on Friday, 19 December 2014 01:13:02 UTC