2017-06-16 12:21:12 +00:00
|
|
|
defmodule RDF.Reader do
|
2017-04-10 19:24:43 +00:00
|
|
|
|
|
|
|
def read(decoder, file_or_content, opts \\ []) do
|
|
|
|
if File.exists?(file_or_content) do
|
|
|
|
read_file(decoder, file_or_content, opts)
|
|
|
|
else
|
|
|
|
read_string(decoder, file_or_content, opts)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def read!(decoder, file_or_content, opts \\ []) do
|
|
|
|
case read(decoder, file_or_content, opts) do
|
|
|
|
{:ok, graph} -> graph
|
|
|
|
{:error, reason} -> raise reason
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def read_string(decoder, content, opts \\ []) do
|
|
|
|
decoder.decode(content, opts)
|
|
|
|
end
|
|
|
|
|
|
|
|
def read_string!(decoder, content, opts \\ []) do
|
|
|
|
decoder.decode!(content, opts)
|
|
|
|
end
|
|
|
|
|
|
|
|
def read_file(decoder, file, opts \\ []) do
|
|
|
|
case File.read(file) do
|
|
|
|
{:ok, content} -> read_string(decoder, content, opts)
|
|
|
|
{:error, reason} -> {:error, reason}
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def read_file!(decoder, file, opts \\ []) do
|
2017-05-15 20:48:55 +00:00
|
|
|
with content = File.read!(file) do
|
|
|
|
read_string!(decoder, content, opts)
|
2017-04-10 19:24:43 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|