Current section
Files
Jump to
Current section
Files
src/yodel@input.erl
-module(yodel@input).
-compile([no_auto_import, nowarn_unused_vars, nowarn_unused_function, nowarn_nomatch, inline]).
-define(FILEPATH, "src/yodel/input.gleam").
-export([detect_input/1, get_extension_from_path/1, read_file/1, get_content/1]).
-export_type([input/0]).
-type input() :: {file, binary()} | {content, binary()}.
-file("src/yodel/input.gleam", 21).
-spec detect_input(binary()) -> input().
detect_input(Input) ->
case begin
_pipe = gleam@string:trim(Input),
simplifile_erl:is_file(_pipe)
end of
{ok, true} ->
{file, Input};
_ ->
{content, Input}
end.
-file("src/yodel/input.gleam", 28).
-spec get_extension_from_path(binary()) -> binary().
get_extension_from_path(Path) ->
case begin
_pipe = Path,
_pipe@1 = gleam@string:trim(_pipe),
_pipe@2 = string:lowercase(_pipe@1),
_pipe@3 = gleam@string:split(_pipe@2, <<"."/utf8>>),
gleam@list:last(_pipe@3)
end of
{ok, Ext} ->
string:lowercase(Ext);
_ ->
<<""/utf8>>
end.
-file("src/yodel/input.gleam", 42).
-spec map_simplifile_error(simplifile:file_error()) -> yodel@errors:config_error().
map_simplifile_error(Error) ->
{file_error, case Error of
eacces ->
{file_permission_denied, simplifile:describe_error(Error)};
enoent ->
{file_not_found, simplifile:describe_error(Error)};
_ ->
{file_read_error, simplifile:describe_error(Error)}
end}.
-file("src/yodel/input.gleam", 37).
-spec read_file(binary()) -> {ok, binary()} |
{error, yodel@errors:config_error()}.
read_file(Path) ->
_pipe = simplifile:read(Path),
gleam@result:map_error(_pipe, fun(Err) -> map_simplifile_error(Err) end).
-file("src/yodel/input.gleam", 14).
-spec get_content(binary()) -> {ok, binary()} |
{error, yodel@errors:config_error()}.
get_content(Input) ->
case begin
_pipe = Input,
detect_input(_pipe)
end of
{file, Path} ->
read_file(Path);
{content, Content} ->
{ok, Content}
end.