RaftEx.Lib
(raft_ex v0.1.0)
View Source
General-purpose utilities used across the RaftEx codebase.
Covers type coercions, UID generation, file helpers, parallel execution, and string/path utilities.
Summary
Functions
Prepend item to list.
Derive a safe string from s by keeping only URL-safe base64 characters,
truncated to num characters.
Ensure the parent directory of path exists.
Return true iff path exists (any type).
Return true iff path is an existing directory.
Return true iff path is an existing regular file.
Shuffle a list using Fisher-Yates (via random sort keys).
Create dir and all parent directories; treat :eexist as success.
Generate a random UID with no prefix.
Generate a UID with an optional binary prefix.
Apply fun to each element of elements in parallel, collecting results
into {:ok, successes, failures}.
Extract the node from a server id, defaulting to node() for bare atoms.
Extract the local registered name from a {name, node} server id.
Recursively delete dir. Raises on failure.
Return true iff str contains only URL-safe base64 characters.
Write io_data to name.
Zero-pad num to a 16-character uppercase hex string.
Functions
Prepend item to list.
@spec derive_safe_string(binary(), pos_integer()) :: binary()
Derive a safe string from s by keeping only URL-safe base64 characters,
truncated to num characters.
Ensure the parent directory of path exists.
Return true iff path exists (any type).
Return true iff path is an existing directory.
Return true iff path is an existing regular file.
Shuffle a list using Fisher-Yates (via random sort keys).
Create dir and all parent directories; treat :eexist as success.
@spec make_uid() :: binary()
Generate a random UID with no prefix.
Generate a UID with an optional binary prefix.
The prefix is prepended as-is; a random 12-character
alphanumeric suffix is appended.
@spec partition_parallel((term() -> boolean()), list(), timeout()) :: {:ok, list(), list()} | {:error, term()}
Apply fun to each element of elements in parallel, collecting results
into {:ok, successes, failures}.
fun must return true (success) or false (failure).
Fails with {:error, {:partition_parallel_timeout, ...}} if timeout ms elapses.
@spec ra_server_id_node(RaftEx.Types.server_id() | atom()) :: node()
Extract the node from a server id, defaulting to node() for bare atoms.
@spec ra_server_id_to_local_name(RaftEx.Types.server_id() | atom()) :: atom()
Extract the local registered name from a {name, node} server id.
@spec recursive_delete(Path.t()) :: :ok
Recursively delete dir. Raises on failure.
Return true iff str contains only URL-safe base64 characters.
Write io_data to name.
When sync is true (default), the file is fsynced after writing to
ensure data reaches durable storage.
@spec zpad_extract_num(binary()) :: non_neg_integer()
@spec zpad_filename(binary(), binary(), non_neg_integer()) :: binary()
@spec zpad_hex(non_neg_integer()) :: binary()
Zero-pad num to a 16-character uppercase hex string.