Skip to content

Commit 0e8bac7

Browse files
author
José Valim
committed
IO.gets and IO.getb now return binaries when reading from stdio
1 parent bef8caf commit 0e8bac7

File tree

4 files changed

+18
-4
lines changed

4 files changed

+18
-4
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
* [Kernel] `List.member?/2` is deprecated in favor of `Enum.member?/2`
2121

2222
* backwards incompatible changes
23+
* [Kernel] `IO.gets` and `IO.getb` now return binaries when reading from stdio
2324
* [Mix] `mix escriptize` now receives arguments as binaries
2425

2526
# v0.8.2 (2013-04-20)

lib/elixir/lib/io.ex

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,20 @@ defmodule IO do
157157
for instance {:error, :estale} if reading from an
158158
NFS file system.
159159
"""
160-
def getb(device // group_leader(), prompt, count // 1) do
160+
def getb(prompt, count // 1)
161+
162+
def getb(prompt, count) when is_integer(count) do
163+
getb(group_leader, prompt, count)
164+
end
165+
166+
def getb(device, prompt) do
167+
getb(device, prompt, 1)
168+
end
169+
170+
@doc """
171+
Gets `count` bytes from the chosen IO device.
172+
"""
173+
def getb(device, prompt, count) do
161174
:io.get_chars(map_dev(device), to_iodata(prompt), count)
162175
end
163176

lib/elixir/src/elixir.erl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@ start(_Type, _Args) ->
2020
%% Set the shell to unicode so printing inside scripts work
2121
%% Those can take a while, so let's do it in a new process
2222
spawn(fun() ->
23-
io:setopts(standard_io, [{encoding,unicode}]),
24-
io:setopts(standard_error, [{encoding,unicode}])
23+
io:setopts(standard_io, [binary,{encoding,unicode}]),
24+
io:setopts(standard_error, [binary,{encoding,unicode}])
2525
end),
2626
elixir_sup:start_link([]).
2727

lib/iex/lib/iex.ex

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ defmodule IEx do
114114
expand_fun = IEx.Autocomplete.expand &1
115115
end
116116

117-
:io.setopts gl, [expand_fun: expand_fun]
117+
:io.setopts gl, [expand_fun: expand_fun, binary: true]
118118
end
119119

120120
defp ensure_module_exists(node, mod) do

0 commit comments

Comments
 (0)