Skip to content

Add support for [:raw] opts in File.read#15172

Merged
sabiwara merged 1 commit intoelixir-lang:mainfrom
sabiwara:file-read-raw
Mar 10, 2026
Merged

Add support for [:raw] opts in File.read#15172
sabiwara merged 1 commit intoelixir-lang:mainfrom
sabiwara:file-read-raw

Conversation

@sabiwara
Copy link
Contributor

@sabiwara sabiwara commented Mar 10, 2026

From #12857

{:ok, binary} | {:error, posix | :badarg | :terminated | :system_limit}
when exists_option: :raw
def read(path, opts \\ []) do
:file.read_file(IO.chardata_to_string(path), opts)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I went with the easy solution of using the default argument (and consistent with other existing functions), but should I split the /1 and /2 arity implementations?

Or possibly:

Suggested change
:file.read_file(IO.chardata_to_string(path), opts)
case opts do
[] -> :file.read_file(IO.chardata_to_string(path))
_ -> :file.read_file(IO.chardata_to_string(path), opts)
end

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Erlang is already doing the change you propose, so I think this fine as is.

@sabiwara sabiwara merged commit 78a5151 into elixir-lang:main Mar 10, 2026
15 checks passed
@sabiwara sabiwara deleted the file-read-raw branch March 10, 2026 11:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

2 participants