-module(simplifile). -compile([no_auto_import, nowarn_unused_vars]). -export([read/1, write/2, delete/1, append/2, read_bits/1, write_bits/2, append_bits/2]). -export_type([file_error/0]). -type file_error() :: eacces | eagain | ebadf | ebadmsg | ebusy | edeadlk | edeadlock | edquot | eexist | efault | efbig | eftype | eintr | einval | eio | eisdir | eloop | emfile | emlink | emultihop | enametoolong | enfile | enobufs | enodev | enolck | enolink | enoent | enomem | enospc | enosr | enostr | enosys | enotblk | enotdir | enotsup | enxio | eopnotsupp | eoverflow | eperm | epipe | erange | erofs | espipe | esrch | estale | etxtbsy | exdev | not_utf8 | unknown. -spec cast_error({ok, FRG} | {error, gleam@erlang@file:reason()}) -> {ok, FRG} | {error, file_error()}. cast_error(Input) -> gleam@result:map_error(Input, fun(E) -> case E of eacces -> eacces; eagain -> eagain; ebadf -> ebadf; ebadmsg -> ebadmsg; ebusy -> ebusy; edeadlk -> edeadlk; edeadlock -> edeadlock; edquot -> edquot; eexist -> eexist; efault -> efault; efbig -> efbig; eftype -> eftype; eintr -> eintr; einval -> einval; eio -> eio; eisdir -> eisdir; eloop -> eloop; emfile -> emfile; emlink -> emlink; emultihop -> emultihop; enametoolong -> enametoolong; enfile -> enfile; enobufs -> enobufs; enodev -> enodev; enolck -> enolck; enolink -> enolink; enoent -> enoent; enomem -> enomem; enospc -> enospc; enosr -> enosr; enostr -> enostr; enosys -> enosys; enotblk -> enotblk; enotdir -> enotdir; enotsup -> enotsup; enxio -> enxio; eopnotsupp -> eopnotsupp; eoverflow -> eoverflow; eperm -> eperm; epipe -> epipe; erange -> erange; erofs -> erofs; espipe -> espipe; esrch -> esrch; estale -> estale; etxtbsy -> etxtbsy; exdev -> exdev; not_utf8 -> not_utf8 end end). -spec read(binary()) -> {ok, binary()} | {error, file_error()}. read(Filepath) -> _pipe = gleam@erlang@file:read(Filepath), cast_error(_pipe). -spec write(binary(), binary()) -> {ok, nil} | {error, file_error()}. write(Contents, Filepath) -> _pipe = gleam@erlang@file:write(Contents, Filepath), cast_error(_pipe). -spec delete(binary()) -> {ok, nil} | {error, file_error()}. delete(Filepath) -> _pipe = gleam_erlang_ffi:delete_file(Filepath), cast_error(_pipe). -spec append(binary(), binary()) -> {ok, nil} | {error, file_error()}. append(Contents, Filepath) -> _pipe = gleam@erlang@file:append(Contents, Filepath), cast_error(_pipe). -spec read_bits(binary()) -> {ok, bitstring()} | {error, file_error()}. read_bits(Filepath) -> _pipe = gleam@erlang@file:read_bits(Filepath), cast_error(_pipe). -spec write_bits(bitstring(), binary()) -> {ok, nil} | {error, file_error()}. write_bits(Bits, Filepath) -> _pipe = gleam@erlang@file:write_bits(Bits, Filepath), cast_error(_pipe). -spec append_bits(bitstring(), binary()) -> {ok, nil} | {error, file_error()}. append_bits(Bits, Filepath) -> _pipe = gleam@erlang@file:append_bits(Bits, Filepath), cast_error(_pipe).