Receive multiple chunks
This commit is contained in:
parent
18da6d23e1
commit
37864e9f11
|
@ -21,13 +21,25 @@ defmodule Gemini do
|
||||||
{:ok, sock} ->
|
{:ok, sock} ->
|
||||||
Socket.Stream.send(sock, "#{URI.to_string(uri)}\r\n")
|
Socket.Stream.send(sock, "#{URI.to_string(uri)}\r\n")
|
||||||
|
|
||||||
case Socket.Stream.recv(sock) do
|
sock
|
||||||
{:error, reason} ->
|
|> receive_loop()
|
||||||
{:error, reason}
|
|> Gemini.Response.parse()
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
defp receive_loop(sock, acc \\ []) do
|
||||||
|
res = Socket.Stream.recv(sock)
|
||||||
|
|
||||||
|
case res do
|
||||||
|
{:ok, nil} ->
|
||||||
|
Socket.Stream.close!(sock)
|
||||||
|
|
||||||
|
acc
|
||||||
|
|> Enum.reverse()
|
||||||
|
|> IO.iodata_to_binary()
|
||||||
|
|
||||||
{:ok, data} ->
|
{:ok, data} ->
|
||||||
Gemini.Response.parse(data)
|
receive_loop(sock, [data | acc])
|
||||||
end
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue