Framer v0.2.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 iodata:

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 iodata and the reminder of the list.

Similar to resize2 except that it returns a tuple with the frames and remainder

Resizes iodata into a new iolist with elements of size frame_size.

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

Link to this section Functions

Link to this function

next_frame(iodata, frame_size)

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

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

Example

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

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

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

next_frames(iodata, frame_size)

View Source
next_frames(iodata(), pos_integer()) :: {iolist(), iodata()}

Similar to resize2 except that it returns a tuple with the frames and remainder

Example

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

resize(iodata, frame_size)

View Source
resize(iodata(), pos_integer()) :: iolist()

Resizes iodata into a new iolist with elements of size frame_size.

Returns a new iolist.

Example

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

resize_stream(iodata, frame_size)

View Source
resize_stream(Enumerable.t(), 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."]]