Current section

Files

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

src/touch_grass@file_system@append_file.erl

-module(touch_grass@file_system@append_file).
-compile([no_auto_import, nowarn_unused_vars, nowarn_unused_function, nowarn_nomatch, inline]).
-define(FILEPATH, "src/touch_grass/file_system/append_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(
" Append contents to a file, starts at beginning if file is empty or does not exist.\n"
" Should be safe for concurrent appends.\n"
).
-type input() :: {input, binary(), bitstring()}.
-file("src/touch_grass/file_system/append_file.gleam", 12).
-spec decode(eyg@interpreter@value:value(OOR, OOS)) -> {ok, input()} |
{error, eyg@interpreter@break:reason(OOR, OOS)}.
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/append_file.gleam", 18).
-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.