File Size v1.3.0 FileSize.Formatter View Source

A module that provides functions to convert file sizes to human-readable strings.

Link to this section Summary

Functions

Formats a file size in a human-readable format, allowing customization of the formatting.

Formats the given size ignoring all user configuration. The result of this function can be passed back to FileSize.parse/1 and is also used by the implementations of the Inspect and String.Chars protocols.

Link to this section Functions

Link to this function

format(size, opts \\ []) View Source
format(FileSize.t(), Keyword.t()) :: String.t()

Formats a file size in a human-readable format, allowing customization of the formatting.

Options

  • :symbols - Allows using your own unit symbols. Must be a map that contains the unit names as keys (as defined by FileSize.unit/0) and the unit symbol strings as values. Missing entries in the map are filled with the internal unit symbols from FileSize.Units.unit_infos/0.

Other options customize the number format and are forwarded to Number.Delimit.number_to_delimited/2. The default precision for numbers is 0.

Global Configuration

You can also define your custom symbols globally.

config :file_size, :symbols, %{b: "Byte", kb: "KB"}

The same is possible for number formatting.

config :file_size, :number_format, precision: 2, delimiter: ",", separator: "."

Or globally for the number library.

config :number, delimit: [precision: 2, delimiter: ",", separator: "."]
Link to this function

format_simple(size) View Source
format_simple(FileSize.t()) :: String.t()

Formats the given size ignoring all user configuration. The result of this function can be passed back to FileSize.parse/1 and is also used by the implementations of the Inspect and String.Chars protocols.