Move human_bytes to utilities
This commit is contained in:
parent
b8ac3dcb7b
commit
5f6f40e299
2 changed files with 24 additions and 20 deletions
|
@ -243,26 +243,6 @@ defmodule Nulform.Plugins.URLAnalyzer do
|
|||
:httpc.request mode, {url, @headers}, @http_options, @base_options
|
||||
end
|
||||
|
||||
def human_bytes(size) do
|
||||
human_bytes size, 1000
|
||||
end
|
||||
|
||||
def human_bytes(size, factor) do
|
||||
human_bytes size, factor, 2
|
||||
end
|
||||
|
||||
def human_bytes(size, factor, decimals) do
|
||||
human_bytes size, factor, decimals, ["B", "kB", "MB", "GB", "TP", "PB"]
|
||||
end
|
||||
|
||||
def human_bytes(size, factor, decimals, [ext | rest]) when size >= factor do
|
||||
human_bytes size / factor, factor, decimals, rest
|
||||
end
|
||||
|
||||
def human_bytes(size, factor, decimals, [ext | rest]) do
|
||||
float_to_binary(:erlang.float(size), [decimals: decimals]) <> " " <> ext
|
||||
end
|
||||
|
||||
defp parse_content_type(header) do
|
||||
Enum.at String.split(to_binary(header), ";"), 0
|
||||
end
|
||||
|
|
|
@ -29,4 +29,28 @@ defmodule Nulform.Utilities do
|
|||
def latin1_to_utf8(string) do
|
||||
:unicode.characters_to_binary string, :latin1, :utf8
|
||||
end
|
||||
|
||||
|
||||
@doc """
|
||||
Convert a number of bytes into a human readable binary.
|
||||
"""
|
||||
def human_bytes(size) do
|
||||
human_bytes size, 1000
|
||||
end
|
||||
|
||||
def human_bytes(size, factor) do
|
||||
human_bytes size, factor, 2
|
||||
end
|
||||
|
||||
def human_bytes(size, factor, decimals) do
|
||||
human_bytes size, factor, decimals, ["B", "kB", "MB", "GB", "TP", "PB"]
|
||||
end
|
||||
|
||||
def human_bytes(size, factor, decimals, [ext | rest]) when size >= factor do
|
||||
human_bytes size / factor, factor, decimals, rest
|
||||
end
|
||||
|
||||
def human_bytes(size, factor, decimals, [ext | rest]) do
|
||||
float_to_binary(:erlang.float(size), [decimals: decimals]) <> " " <> ext
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue