Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
|
|
@ -0,0 +1,23 @@
|
|||
defmodule FileReader do
|
||||
# Create a File.Stream and inspect each line
|
||||
def by_line(path) do
|
||||
File.stream!(path)
|
||||
|> Stream.map(&(IO.inspect(&1)))
|
||||
|> Stream.run
|
||||
end
|
||||
|
||||
def bin_line(path) do
|
||||
# Build the stream in binary instead for performance increase
|
||||
case File.open(path) do
|
||||
# File returns a tuple, {:ok,file}, if successful
|
||||
{:ok, file} ->
|
||||
IO.binstream(file, :line)
|
||||
|> Stream.map(&(IO.inspect(&1)))
|
||||
|> Stream.run
|
||||
# And returns {:error,reason} if unsuccessful
|
||||
{:error,reason} ->
|
||||
# Use Erlang's format_error to return an error string
|
||||
:file.format_error(reason)
|
||||
end
|
||||
end
|
||||
end
|
||||
Loading…
Add table
Add a link
Reference in a new issue