aleph 2022-07-12

hello, wanted to ask if there is any interest in having an option (in byte-stream I imagine) to convert only a part of the stream to string. The use case is that I would like to limit the number of processed bytes to a specific manageable size: 1-10k and avoid processing the whole buffer. One simple application of this is that in case of errors I get a body back and I would like to print a "preview" of that buffer: first 1-2k characters. I can do it like this:

(when-let [body (-> (:body (ex-data e))
                      bs/to-string)]
    (log/error "With body" body))
but I still get to process the WHOLE body. In theory that could be 1GB of data. What do you think? I could solve this in a number of ways. One option would be somthing like the SizeLimit InputStream https://zditect.com/code/java/size-limit-inputstream--inputstreamnbsplaquonbspfile-input-outputnbsplaquonbspjava.html . But they all fall a bit short in one way or another.

@eugen.stan bs/to-string is one of the few operations thatโ€™s going to try and consume everything. Iโ€™m not sure what your source is made of, but most of the alternatives are lazier. Consider using to-reader, to-line-seq, or to-char-sequence instead. You can read only as much data as you feel like, and then convert that to a string.

๐Ÿ‘ 1

Is there a way to detect that client disconnected from websocket server?

how do you guys deal with stale websocket connections? Do you manually clear them or leave it to garbage collection?