Framer v0.1.0 Framer View Source

Module contains helper functions to resize iodata streams and lists.

The two main functions are:

Examples

Resizing a iodata stream:

iex> stream = ["The brown", " fox", ["that ", "jumped"], " up."]
iex> Framer.resize_stream(stream, 5) |> Enum.to_list()
[["The b"], ["rown", " "], ["fox", "th"], ["at ", "ju"], ["mped", " "], ["up."]]

Resizing an iolist:

iex> enum = ["Hello ", "World"]
iex> Framer.resize(enum, 4)
[["Hell"], ["o ", "Wo"], ["rld"]]

Link to this section Summary

Functions

Returns a tuple containing the first frame of frame_size taken off the iolist and the reminder of the list.

Resizes an iolist into a new iolist with elements of frame_size.

Resizes an iodata stream into a stream of equally sized frames.

Returns the first n bytes with the remainder of a binary.

Link to this section Functions

Link to this function

next_frame(iolist, frame_size)

View Source
next_frame(iolist(), pos_integer()) :: {[any()], iolist()}

Returns a tuple containing the first frame of frame_size taken off the iolist and the reminder of the list.

Example

iex> iolist = [?h, "el", ["l", [?o]], "world"]
iex> Framer.next_frame(iolist, 3)
{["h", "el"], [["l", [?o]], "world"]}

When the whole iolist fits into a frame, return the io list with an empty remainder.

iex> iolist = ["h", "ello"]
iex> Framer.next_frame(iolist, 10)
{["h", "ello"], []}
Link to this function

resize(iolist, frame_size)

View Source
resize(iolist(), pos_integer()) :: Enumerable.t()

Resizes an iolist into a new iolist with elements of frame_size.

Returns a new iolist.

Example

iex> iolist = [?h, "el", ["l", [?o]], "world"]
iex> Framer.resize(iolist, 3)
[["h", "el"], ["l", "o", "w"], ["orl"], ["d"]]
Link to this function

resize_stream(iodata, frame_size)

View Source
resize_stream(iodata(), pos_integer()) :: Enumerable.t()

Resizes an iodata stream into a stream of equally sized frames.

The last frame might be smaller.

Returns an iodata stream.

Example

iex> stream = ["The brown", " fox", ["that ", "jumped"], " up."]
iex> Framer.resize_stream(stream, 5) |> Enum.to_list()
[["The b"], ["rown", " "], ["fox", "th"], ["at ", "ju"], ["mped", " "], ["up."]]
Link to this function

split_binary(binary, length_in_bytes)

View Source
split_binary(binary(), pos_integer()) :: {binary(), nil | binary()}

Returns the first n bytes with the remainder of a binary.

Example

iex> Framer.split_binary("Hello World", 4)
{"Hell", "o World"}

iex> Framer.split_binary("Hello", 10)
{"Hello", nil}