Binary v0.0.2 Binary
Functions to operate on binaries.
Summary
Functions
Returns byte at given position. Numbering starts with 0
Create a binary with the binary content repeated n times
Returns the first byte of the binary as an integer
Convert list of bytes into binary
Returns the last byte of the binary as an integer
Pad with the provided byte at the beginning of the binary until provided length is achieved
Pad end of the binary with the provided byte until provided length is achieved
Reverse bytes order in the binary
Splits a binary into two at the specified position. Returns a tuple
Converts binary to a list of bytes
Removes all spcefied leading bytes from the binary
Removes all specified trailing bytes from the the binary
Functions
Returns byte at given position. Numbering starts with 0.
Position can be negative to make it relative to the end of the binary.
Returns nil if position is outside the binary (following Enum and String behavior)
Examples
iex> <<1, 2, 3>> |> Binary.at(1)
2
iex> <<1, 2, 3>> |> Binary.at(3)
nil
iex> <<1, 2, 3>> |> Binary.at(-1)
3
Create a binary with the binary content repeated n times.
Pad with the provided byte at the beginning of the binary until provided length is achieved.
Pad end of the binary with the provided byte until provided length is achieved.
Examples
iex> <<3, 7>> |> Binary.pad_trailing(5)
<<3, 7, 0, 0, 0>>
Splits a binary into two at the specified position. Returns a tuple.
When position is negative it’s counted from the end of the binary.
Examples
iex> <<1, 2, 3>> |> Binary.split_at(1)
{<<1>>, <<2, 3>>}
iex> <<1, 2, 3, 4>> |> Binary.split_at(-1)
{<<1, 2, 3>>, <<4>>}
iex> <<1, 2, 3>> |> Binary.split_at(10)
{<<1, 2, 3>>, <<>>}
Removes all spcefied leading bytes from the binary.