File Size v1.3.0 FileSize.Convertible protocol View Source

A protocol that defines functions to convert file sizes to other units.

Link to this section Summary

Functions

Converts the given file size to a given unit.

Puts the normalized value in the given file size struct, finalizing the struct creation.

Gets the normalized value from the given file size struct.

Link to this section Types

Link to this section Functions

Converts the given file size to a given unit.

Examples

iex> FileSize.convert(FileSize.new(2, :kb), :b)
#FileSize<"2000 B">

iex> FileSize.convert(FileSize.new(2000, :b), :kb)
#FileSize<"2.0 kB">

iex> FileSize.convert(FileSize.new(20, :kb), :kbit)
#FileSize<"160.0 kbit">

iex> FileSize.convert(FileSize.new(2000, :b), :unknown)
** (FileSize.InvalidUnitError) Invalid unit: :unknown
Link to this function

new(size, normalized_value) View Source

Puts the normalized value in the given file size struct, finalizing the struct creation.

Gets the normalized value from the given file size struct.