ChanServ changed the topic of #crystal-lang to: The Crystal programming language | | Fund Crystal's development: | GH: | Docs: | Gitter:
<FromGitter> <Blacksmoke16> @skurhse why close your PR?
<FromGitter> <> @Blacksmoke16: i think skurhse left for good
<FromGitter> <Blacksmoke16> oh?
<FromGitter> <> 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> 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> <> If you know the format in advance, you may be able to use a custom from_json
<FromGitter> <> it's literally just newline-separated json entries
<FromGitter> <confact> 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> <> 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> <> there's no such thing as "line is EOF" because there's no such thing as "EOF"
<FromGitter> <> Yes, EOF is EndOfFile, which means literally nothing after
<FromGitter> <> 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> <> 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> <> hmm even if that is possible, it's unnecessarily difficult
<FromGitter> <> anyway this is the correct code to deal with such a stream ⏎
<FromGitter> <> 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 , I can still group it up like I want, without split.
<FromGitter> <> oprypin ( it assumes one line is a valid json document. Also, it uses JSON::Any even though one may know the mapping in advance
<FromGitter> <> I don't know what happens if a string includes a new line in your case
<FromGitter> <> j8r ( > it assumes one line is a valid json document ⏎ ⏎ yes, that's how these streams are set up
<FromGitter> <> dont mind the json any, you can change it to something else if you like
<FromGitter> <> It works in your case but it may not for others. Mainly depends of the delimiter
<FromGitter> <> And it is not that efficient you know
<FromGitter> <> Because for each line, an intermediate string is created. It is good enough though
wolfshappen has quit [Quit: later]
<FromGitter> <Blacksmoke16> Might be some helpful info in there
<FromGitter> <> mmm `IO::Delimited` is perfect
wolfshappen has joined #crystal-lang
wolfshappen has quit [Ping timeout: 256 seconds]
wolfshappen has joined #crystal-lang
ur5us has joined #crystal-lang
debayer948 has joined #crystal-lang
debayer948 has quit [Remote host closed the connection]
debayer948 has joined #crystal-lang
ur5us has quit [Ping timeout: 240 seconds]