<FromGitter>
<Blacksmoke16> @skurhse why close your PR?
<FromGitter>
<oprypin:matrix.org> @Blacksmoke16: i think skurhse left for good
<FromGitter>
<Blacksmoke16> oh?
<FromGitter>
<oprypin:matrix.org> also self-deletions on forum
<FromGitter>
<Blacksmoke16> rip
<FromGitter>
<Blacksmoke16> oh well
ur5us has quit [Ping timeout: 240 seconds]
ur5us has joined #crystal-lang
ur5us has quit [Ping timeout: 240 seconds]
<FromGitter>
<confact> @jrei:matrix.org it is a third-party API that is pretty big that separates different JSON objects with EOF to say it is a end of file (obviously) or a new type below. So I needed a way to go through line by line and check if a line was an EOF. Now I check if it is an empty line, as EOF seems to be seen as no character and empty.
<FromGitter>
<confact> How is it meant to use URI.encode_path when URI.parse doesn't work as it is a space in the path that I need to encode? URI.encode works fine, but not URI.encode.
<FromGitter>
<confact> *but not URI.encode_path
<FromGitter>
<jrei:matrix.org> If you know the format in advance, you may be able to use a custom from_json
<FromGitter>
<oprypin:matrix.org> it's literally just newline-separated json entries
<FromGitter>
<confact> @oprypin:matrix.org @jrei:matrix.org Yea, I already figured it out with \n\n split or check if the string is empty :) I just told you guys how I got this <EOF> at all. :)
<FromGitter>
<oprypin:matrix.org> well i tell you how. you're telling it to parse an empty string and it says it expected some data, not immediately the end of the string when it just started
<FromGitter>
<oprypin:matrix.org> there's no such thing as "line is EOF" because there's no such thing as "EOF"
<FromGitter>
<jrei:matrix.org> Yes, EOF is EndOfFile, which means literally nothing after
<FromGitter>
<oprypin:matrix.org> i think you'd be better off with repeatedly calling `gets` - that way you'll not have to deal with the empty string you get from calling `split` with `\r\n`. ⏎ additionally you'd not have to read the whole thing into memory before splitting
<FromGitter>
<jrei:matrix.org> But if he know the whole structure in advance, I think he can use JSON::PullParser, then read this 2 characters between the documents
<FromGitter>
<oprypin:matrix.org> hmm even if that is possible, it's unnecessarily difficult
<FromGitter>
<moe:busyloop.net> hmm, matrix really has come a long way since i last looked. might win me over from IRC at last.
<FromGitter>
<confact> Appreciate the ideas. I will take some ideas to my code :) - The thing that makes it a bit hard is that each group of JSON objects (separated with \r\n) has an explainer of what kind of data it is below at the first line. So depending on that line, I want to take care of the data below differently. That's why I try split instead, to set them in some groups. I also want to use some Serializable classes.
<FromGitter>
<confact> It works fine now. So it is ok :)
<FromGitter>
<confact> Okay, when thinking a bit more, I do think it is better to stream it, as it can be huge bodies sometimes. I will probably use your ideas @oprypin:matrix.org , I can still group it up like I want, without split.
<FromGitter>
<jrei:matrix.org> oprypin (https://matrix.to/#/@oprypin:matrix.org): it assumes one line is a valid json document. Also, it uses JSON::Any even though one may know the mapping in advance
<FromGitter>
<jrei:matrix.org> I don't know what happens if a string includes a new line in your case
<FromGitter>
<oprypin:matrix.org> j8r (https://matrix.to/#/@jrei:matrix.org): > it assumes one line is a valid json document ⏎ ⏎ yes, that's how these streams are set up
<FromGitter>
<oprypin:matrix.org> dont mind the json any, you can change it to something else if you like
<FromGitter>
<jrei:matrix.org> It works in your case but it may not for others. Mainly depends of the delimiter
<FromGitter>
<jrei:matrix.org> And it is not that efficient you know
<FromGitter>
<jrei:matrix.org> Because for each line, an intermediate string is created. It is good enough though