mirror of
https://github.com/livebook-dev/livebook.git
synced 2025-10-30 07:16:04 +08:00
Doctests for format bytes (#921)
* Doctests for format bytes * Update lib/livebook/utils.ex Co-authored-by: Jonatan Kłosko <jonatanklosko@gmail.com> Co-authored-by: Jonatan Kłosko <jonatanklosko@gmail.com>
This commit is contained in:
parent
4f197698ae
commit
930b3293f0
1 changed files with 23 additions and 0 deletions
|
|
@ -369,6 +369,29 @@ defmodule Livebook.Utils do
|
|||
|> Enum.join("\n")
|
||||
end
|
||||
|
||||
@doc """
|
||||
Formats the given number of bytes into a human-friendly text.
|
||||
|
||||
## Examples
|
||||
|
||||
iex> Livebook.Utils.format_bytes(0)
|
||||
"0 B"
|
||||
|
||||
iex> Livebook.Utils.format_bytes(1000)
|
||||
"1000 B"
|
||||
|
||||
iex> Livebook.Utils.format_bytes(1100)
|
||||
"1.1 KB"
|
||||
|
||||
iex> Livebook.Utils.format_bytes(1_228_800)
|
||||
"1.2 MB"
|
||||
|
||||
iex> Livebook.Utils.format_bytes(1_363_148_800)
|
||||
"1.3 GB"
|
||||
|
||||
iex> Livebook.Utils.format_bytes(1_503_238_553_600)
|
||||
"1.4 TB"
|
||||
"""
|
||||
def format_bytes(bytes) when is_integer(bytes) do
|
||||
cond do
|
||||
bytes >= memory_unit(:TB) -> format_bytes(bytes, :TB)
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue