Current section

Files

Jump to
touch_grass src touch_grass@file_system@write_file.erl
Raw

src/touch_grass@file_system@write_file.erl

-module(touch_grass@file_system@write_file).
-compile([no_auto_import, nowarn_unused_vars, nowarn_unused_function, nowarn_nomatch, inline]).
-define(FILEPATH, "src/touch_grass/file_system/write_file.gleam").
-export([decode/1, encode/1]).
-export_type([input/0]).
-if(?OTP_RELEASE >= 27).
-define(MODULEDOC(Str), -moduledoc(Str)).
-define(DOC(Str), -doc(Str)).
-else.
-define(MODULEDOC(Str), -compile([])).
-define(DOC(Str), -compile([])).
-endif.
?MODULEDOC(
" Write a file or overwrite an existing file.\n"
" \n"
" The platform will decide if intermediate files will be created.\n"
).
-type input() :: {input, binary(), bitstring()}.
-file("src/touch_grass/file_system/write_file.gleam", 13).
-spec decode(eyg@interpreter@value:value(KRK, KRL)) -> {ok, input()} |
{error, eyg@interpreter@break:reason(KRK, KRL)}.
decode(Input) ->
gleam@result:'try'(
eyg@interpreter@cast:field(
<<"path"/utf8>>,
fun eyg@interpreter@cast:as_string/1,
Input
),
fun(Path) ->
gleam@result:'try'(
eyg@interpreter@cast:field(
<<"contents"/utf8>>,
fun eyg@interpreter@cast:as_binary/1,
Input
),
fun(Contents) -> {ok, {input, Path, Contents}} end
)
end
).
-file("src/touch_grass/file_system/write_file.gleam", 19).
-spec encode({ok, nil} | {error, binary()}) -> eyg@interpreter@value:value(any(), any()).
encode(Result) ->
case Result of
{ok, nil} ->
eyg@interpreter@value:ok(eyg@interpreter@value:unit());
{error, Reason} ->
eyg@interpreter@value:error({string, Reason})
end.