Appwrite. Utils. General
(appwrite v1.0.0)
View Source
General-purpose utilities used across the Appwrite SDK.
Provides unique ID generation (UUID v4 via :crypto) and human-readable
byte formatting.
Summary
Functions
Converts a byte count into a human-readable string.
Examples
iex> Appwrite.Utils.General.bytes_to_human_readable(512)
"512 Bytes"
iex> Appwrite.Utils.General.bytes_to_human_readable(2048)
"2.0 KB"
iex> Appwrite.Utils.General.bytes_to_human_readable(1_500_000)
"1.43 MB"
iex> Appwrite.Utils.General.bytes_to_human_readable(2_000_000_000)
"1.86 GB"
@spec generate_unique_id() :: String.t()
Generates a random UUID v4 string.
Uses Erlang's :crypto.strong_rand_bytes/1 — no external dependency required.
Examples
iex> uuid = Appwrite.Utils.General.generate_unique_id()
iex> String.match?(uuid, ~r/^[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/)
true