Skip to content

Commit 763543c

Browse files
committed
Document \r\n normalization, closes #13717
1 parent 7a90b59 commit 763543c

File tree

1 file changed

+16
-8
lines changed

1 file changed

+16
-8
lines changed

lib/elixir/lib/io.ex

+16-8
Original file line numberDiff line numberDiff line change
@@ -131,9 +131,11 @@ defmodule IO do
131131
The `device` is iterated as specified by the `line_or_chars` argument:
132132
133133
* if `line_or_chars` is an integer, it represents a number of bytes. The device is
134-
iterated by that number of bytes.
134+
iterated by that number of bytes. This should be the preferred mode for reading
135+
non-textual inputs.
135136
136137
* if `line_or_chars` is `:line`, the device is iterated line by line.
138+
CRFL newlines ("\r\n") are automatically normalized to "\n".
137139
138140
* if `line_or_chars` is `:eof` (since v1.13), the device is iterated until `:eof`.
139141
If the device is already at the end, it returns `:eof` itself.
@@ -184,9 +186,11 @@ defmodule IO do
184186
The `device` is iterated as specified by the `line_or_chars` argument:
185187
186188
* if `line_or_chars` is an integer, it represents a number of bytes. The device is
187-
iterated by that number of bytes.
189+
iterated by that number of bytes. This should be the preferred mode for reading
190+
non-textual inputs.
188191
189192
* if `line_or_chars` is `:line`, the device is iterated line by line.
193+
CRFL newlines ("\r\n") are automatically normalized to "\n".
190194
191195
* if `line_or_chars` is `:eof` (since v1.13), the device is iterated until `:eof`.
192196
If the device is already at the end, it returns `:eof` itself.
@@ -596,8 +600,9 @@ defmodule IO do
596600
`Collectable`, allowing it to be used for both read
597601
and write.
598602
599-
The `device` is iterated by the given number of characters or line by line if
600-
`:line` is given.
603+
The `device` is iterated by the given number of characters
604+
or line by line if `:line` is given. In case `:line` is given,
605+
"\r\n" is automatically normalized to "\n".
601606
602607
This reads from the IO as UTF-8. Check out
603608
`IO.binstream/2` to handle the IO as a raw binary.
@@ -650,14 +655,17 @@ defmodule IO do
650655
`Collectable`, allowing it to be used for both read
651656
and write.
652657
653-
The `device` is iterated by the given number of bytes or line by line if
654-
`:line` is given. This reads from the IO device as a raw binary.
658+
The `device` is iterated by the given number of bytes or line
659+
by line if `:line` is given. In case `:line` is given, "\r\n"
660+
is automatically normalized to "\n". Passing the number of bytes
661+
should be the preferred mode for reading non-textual inputs.
655662
656663
Note that an IO stream has side effects and every time
657664
you go over the stream you may get different results.
658665
659-
Finally, do not use this function on IO devices in Unicode
660-
mode as it will return the wrong result.
666+
This reads from the IO device as a raw binary. Therefore,
667+
do not use this function on IO devices in Unicode mode as
668+
it will return the wrong result.
661669
662670
`binstream/0` has been introduced in Elixir v1.12.0,
663671
while `binstream/2` has been available since v1.0.0.

0 commit comments

Comments
 (0)