ExBin v0.2.0 ExBin View Source

Documentation for ExBin.

Link to this section Summary

Functions

Returns the bit at a specific index. If the index exceeds the length of the bitstring, {:error, :index_out_of_bounds} is returned

Creates a stream for fetching bits from a bitstring in a lazily evaluated manner

Converts the given bitstr into a list of bits (integers)

Retrives the byte at index index (zero-based) from binary

Creates a stream for fetching bytes within a binary. Ideal for large volumes of bytes, or large binaries

Link to this section Functions

Returns the bit at a specific index. If the index exceeds the length of the bitstring, {:error, :index_out_of_bounds} is returned.

Examples

iex> ExBin.bit_at(<<0b1011 :: size(4)>>, 2)
1

iex> ExBin.bit_at(<<0b1011 :: size(4)>>, 10)
{:error, :index_out_of_bounds}

Creates a stream for fetching bits from a bitstring in a lazily evaluated manner.

Examples

iex> ExBin.bit_stream(<<0xa5,0x93>>) |> Enum.take(16)
[1, 0, 1, 0, 0, 1, 0, 1, 1, 0, 0, 1, 0, 0, 1, 1]

Converts the given bitstr into a list of bits (integers).

Examples:

iex> ExBin.bits(<<0xa5, 0x93>>)
[1, 0, 1, 0, 0, 1, 0, 1, 1, 0, 0, 1, 0, 0, 1, 1]

Retrives the byte at index index (zero-based) from binary.

If the binary is empty, or already exhausted, byte_at will return {:error, :index_out_of_bounds}.

Examples

iex> ExBin.byte_at(<<0x0b, 0xc4, 0x3f>>, 1)
196

iex> ExBin.byte_at(<<0x0b, 0xc4, 0x3f>>, 7)
{:error, :index_out_of_bounds}

Creates a stream for fetching bytes within a binary. Ideal for large volumes of bytes, or large binaries.

Examples

iex> ExBin.byte_stream(<<0x01, 0x02, 0x03>>) |> Enum.take(2)
[1, 2]