Skip to content

Commit c799fcd

Browse files
committed
Return :eof for read(dev, :eof) and there is no data
1 parent 7693b05 commit c799fcd

File tree

1 file changed

+4
-12
lines changed

1 file changed

+4
-12
lines changed

lib/elixir/lib/io.ex

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -483,22 +483,14 @@ defmodule IO do
483483
defp getn_eof(device, prompt, acc) do
484484
case :io.get_line(device, prompt) do
485485
line when is_binary(line) or is_list(line) -> getn_eof(device, '', [line | acc])
486-
:eof -> read_eof(device, :lists.reverse(acc))
486+
:eof -> wrap_eof(:lists.reverse(acc))
487487
other -> other
488488
end
489489
end
490490

491-
defp read_eof(_device, [h | _] = acc) when is_binary(h), do: IO.iodata_to_binary(acc)
492-
defp read_eof(_device, [h | _] = acc) when is_list(h), do: :lists.flatten(acc)
493-
494-
defp read_eof(device, []) do
495-
with [_ | _] = opts <- :io.getopts(device),
496-
false <- Keyword.get(opts, :binary, true) do
497-
''
498-
else
499-
_ -> ""
500-
end
501-
end
491+
defp wrap_eof([h | _] = acc) when is_binary(h), do: IO.iodata_to_binary(acc)
492+
defp wrap_eof([h | _] = acc) when is_list(h), do: :lists.flatten(acc)
493+
defp wrap_eof([]), do: :eof
502494

503495
@doc ~S"""
504496
Reads a line from the IO `device`.

0 commit comments

Comments
 (0)