# `Bunch.Binary`
[🔗](https://github.com/membraneframework/bunch/blob/v1.6.4/lib/bunch/binary.ex#L1)

A bunch of helpers for manipulating binaries.

# `chunk_every`

```elixir
@spec chunk_every(binary(), pos_integer()) :: [binary()]
```

Chunks given binary into parts of given size.

Remaining part is cut off.

## Examples

    iex> <<1, 2, 3, 4, 5, 6>> |> Bunch.Binary.chunk_every(2)
    [<<1, 2>>, <<3, 4>>, <<5, 6>>]
    iex> <<1, 2, 3, 4, 5, 6, 7>> |> Bunch.Binary.chunk_every(2)
    [<<1, 2>>, <<3, 4>>, <<5, 6>>]

# `chunk_every_rem`

```elixir
@spec chunk_every_rem(binary(), chunk_size :: pos_integer()) ::
  {[binary()], remainder :: binary()}
```

Chunks given binary into parts of given size.

Returns list of chunks and remainder.

## Examples

    iex> <<1, 2, 3, 4, 5, 6>> |> Bunch.Binary.chunk_every_rem(2)
    {[<<1, 2>>, <<3, 4>>, <<5, 6>>], <<>>}
    iex> <<1, 2, 3, 4, 5, 6, 7>> |> Bunch.Binary.chunk_every_rem(2)
    {[<<1, 2>>, <<3, 4>>, <<5, 6>>], <<7>>}

# `split_int_part`

```elixir
@spec split_int_part(binary(), pos_integer()) :: {binary(), binary()}
```

Returns a 2-tuple, where the first element is the result of `take_int_part(binary, i)`,
and the second is the rest of `binary`.

## Examples

    iex> import Bunch.Binary
    iex> split_int_part(<<1,2,3,4,5,6,7,8>>, 3)
    {<<1,2,3,4,5,6>>, <<7,8>>}
    iex> split_int_part(<<1,2,3,4,5,6,7,8>>, 4)
    {<<1,2,3,4,5,6,7,8>>, <<>>}

# `take_int_part`

```elixir
@spec take_int_part(binary(), pos_integer()) :: binary()
```

Cuts off the smallest possible chunk from the end of `binary`, so that the
size of returned binary is an integer multiple of `i`.

## Examples

    iex> import Bunch.Binary
    iex> take_int_part(<<1,2,3,4,5,6,7,8>>, 3)
    <<1,2,3,4,5,6>>
    iex> take_int_part(<<1,2,3,4,5,6,7,8>>, 4)
    <<1,2,3,4,5,6,7,8>>

---

*Consult [api-reference.md](api-reference.md) for complete listing*
