The `clojure.data.xml/emit` function will stream xml to a Writer. To hook
it up to `piped-input-stream` requires a little bit of book keeping work.
`piped-input-stream` provides an OutputStream and we need to convert that
to a Writer. Luckily `clojure.java.io/writer` can handle that for us.
Additionally, we'll need to `flush` at the end in order to make sure this
intermediate writer is not buffering any data before `piped-input-stream`
closes the OutputStream. All together, a ring response could be generated
like:
```
(response/response
(ring-io/piped-input-stream
#(->> (io/make-writer % {})
(xml/emit (data))
.flush)))
```
A complete example is available at https://www.refheap.com/99829. When I
run the jetty server and use curl, going to http://localhost:8080/stream
begins streaming "quickly", where as http://localhost:8080 waits until the
entire response is generated.
-
Nelson
On Mon, Apr 20, 2015 at 11:40 AM, Herwig Hochleitner <[email protected]
> wrote:
> The way enlive does it, is to create a lazy sequence of strings. A
> response body such as that can be immediately be used by ring. However, I
> don't know from the top of my head how to generate it from data.xml.
> I'll be glad to get some input on that, otherwise I'll think about this
> more, the next time I come around to hacking on it.
>
> --
> You received this message because you are subscribed to the Google
> Groups "Clojure" group.
> To post to this group, send email to [email protected]
> Note that posts from new members are moderated - please be patient with
> your first post.
> To unsubscribe from this group, send email to
> [email protected]
> For more options, visit this group at
> http://groups.google.com/group/clojure?hl=en
> ---
> You received this message because you are subscribed to the Google Groups
> "Clojure" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to [email protected].
> For more options, visit https://groups.google.com/d/optout.
>
--
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to [email protected]
Note that posts from new members are moderated - please be patient with your
first post.
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
---
You received this message because you are subscribed to the Google Groups
"Clojure" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/d/optout.