- From: Domenic Denicola <notifications@github.com>
- Date: Fri, 12 Dec 2014 10:11:44 -0800
- To: whatwg/streams <streams@noreply.github.com>
- Message-ID: <whatwg/streams/issues/249/66810921@github.com>
(Sorry for the delay in the response.) > 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: ```js 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
Received on Friday, 12 December 2014 18:12:22 UTC