aleph

Eugen 2022-07-12T09:37:58.781149Z

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.

Matthew Davidson 2022-07-13T06:34:30.527519Z

@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
Eugen 2022-07-13T09:23:57.188929Z

made a PR https://github.com/clj-commons/byte-streams/pull/57. I think it's good info.

๐Ÿ‘ 1
lepistane 2022-07-12T11:29:29.930539Z

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

lepistane 2022-07-12T18:14:39.731599Z

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