structured_io v0.2.0 StructuredIO View Source

A process for performing I/O of structured data, such as markup or binary-encoded data.

Link to this section Summary

Types

An error result

Functions

Reads data from the specified structured_io beginning with the specified from and ending with the specified through, using the specified timeout (defaults to 5,000 milliseconds). The operation is Unicode-unsafe

Reads data from the specified structured_io if and until the specified through is encountered, including through, using the specified timeout (defaults to 5,000 milliseconds). The operation is Unicode-unsafe

Reads data from the specified structured_io if and until the specified to is encountered, excluding to, using the specified timeout (defaults to 5,000 milliseconds). The operation is Unicode-unsafe

Asynchronously writes the specified iodata as a binary to the specified structured_io. The operation is Unicode-unsafe

Reads data from the specified structured_io beginning with the specified from and ending with the specified through, using the specified timeout (defaults to 5,000 milliseconds)

Reads data from the specified structured_io if and until the specified through is encountered, including through, using the specified timeout (defaults to 5,000 milliseconds)

Reads data from the specified structured_io if and until the specified to is encountered, excluding to, using the specified timeout (defaults to 5,000 milliseconds)

Starts a StructuredIO process without links (outside a supervision tree) with the specified options

Starts a StructuredIO process linked to the current process with the specified options

Synchronously stops the specified structured_io process with the specified reason (defaults to :normal) and timeout (defaults to infinity)

Asynchronously writes the specified chardata as a binary to the specified structured_io

Link to this section Types

Link to this type error() View Source
error() :: {:error, atom() | binary()}

An error result.

Link to this section Functions

Link to this function binread_across(structured_io, from, through, timeout \\ 5000) View Source
binread_across(GenServer.server(), binary(), binary(), timeout()) :: StructuredIO.Scanner.match()

Reads data from the specified structured_io beginning with the specified from and ending with the specified through, using the specified timeout (defaults to 5,000 milliseconds). The operation is Unicode-unsafe.

If the data read does not begin with from, the result is an empty binary (""). Likewise, if through is not encountered, the result is an empty binary ("").

Examples

iex> {:ok, structured_io} = StructuredIO.start_link
iex> StructuredIO.binwrite structured_io,
...>                       <<0, 0, 0, 1, 2, 3, 255, 255>>
:ok
iex> StructuredIO.binread_across structured_io,
...>                             <<0, 0, 0>>,
...>                             <<255, 255, 255>>
""
iex> StructuredIO.binwrite structured_io,
...>                       <<255, 0, 0, 0, 4, 5, 6, 255, 255, 255>>
:ok
iex> StructuredIO.binread_across structured_io,
...>                             <<0, 0, 0>>,
...>                             <<255, 255, 255>>
<<0, 0, 0, 1, 2, 3, 255, 255, 255>>
iex> StructuredIO.binread_across structured_io,
...>                             <<0, 0, 0>>,
...>                             <<255, 255, 255>>
<<0, 0, 0, 4, 5, 6, 255, 255, 255>>
iex> StructuredIO.binread_across structured_io,
...>                             <<0, 0, 0>>,
...>                             <<255, 255, 255>>
""
Link to this function binread_through(structured_io, through, timeout \\ 5000) View Source
binread_through(GenServer.server(), binary(), timeout()) :: StructuredIO.Scanner.match()

Reads data from the specified structured_io if and until the specified through is encountered, including through, using the specified timeout (defaults to 5,000 milliseconds). The operation is Unicode-unsafe.

If through is not encountered, the result is an empty binary ("").

Examples

iex> {:ok, structured_io} = StructuredIO.start_link
iex> StructuredIO.binwrite structured_io,
...>                       <<1, 2, 3, 255, 255>>
:ok
iex> StructuredIO.binread_through structured_io,
...>                              <<255, 255, 255>>
""
iex> StructuredIO.binwrite structured_io,
...>                       <<255, 4, 5, 6, 255, 255, 255>>
:ok
iex> StructuredIO.binread_through structured_io,
...>                              <<255, 255, 255>>
<<1, 2, 3, 255, 255, 255>>
iex> StructuredIO.binread_through structured_io,
...>                              <<255, 255, 255>>
<<4, 5, 6, 255, 255, 255>>
iex> StructuredIO.binread_through structured_io,
...>                              <<255, 255, 255>>
""
Link to this function binread_to(structured_io, to, timeout \\ 5000) View Source
binread_to(GenServer.server(), binary(), timeout()) :: StructuredIO.Scanner.match()

Reads data from the specified structured_io if and until the specified to is encountered, excluding to, using the specified timeout (defaults to 5,000 milliseconds). The operation is Unicode-unsafe.

If to is not encountered, the result is an empty binary ("").

Examples

iex> {:ok, structured_io} = StructuredIO.start_link
iex> StructuredIO.binwrite structured_io,
...>                       <<1, 2, 3, 255, 255, 255, 0, 0>>
:ok
iex> StructuredIO.binread_to structured_io,
...>                         <<0, 0, 0>>
""
iex> StructuredIO.binwrite structured_io,
...>                       <<0, 4, 5, 6, 255, 255, 255, 0, 0, 0, 7, 8, 9>>
:ok
iex> StructuredIO.binread_to structured_io,
...>                         <<0, 0, 0>>
<<1, 2, 3, 255, 255, 255>>
iex> StructuredIO.binread_to structured_io,
...>                         <<0, 0, 0>>
""
iex> StructuredIO.binread_through structured_io,
...>                              <<0, 0, 0>>
<<0, 0, 0>>
iex> StructuredIO.binread_to structured_io,
...>                         <<0, 0, 0>>
<<4, 5, 6, 255, 255, 255>>
iex> StructuredIO.binread_to structured_io,
...>                         <<0, 0, 0>>
""
Link to this function binwrite(structured_io, iodata) View Source
binwrite(GenServer.server(), iodata()) :: :ok | error()

Asynchronously writes the specified iodata as a binary to the specified structured_io. The operation is Unicode-unsafe.

See StructuredIO.binread_across/3, StructuredIO.binread_through/2, and StructuredIO.binread_to/2 for examples.

Link to this function read_across(structured_io, from, through, timeout \\ 5000) View Source
read_across(GenServer.server(), binary(), binary(), timeout()) :: binary()

Reads data from the specified structured_io beginning with the specified from and ending with the specified through, using the specified timeout (defaults to 5,000 milliseconds).

If the data read does not begin with from, the result is an empty binary (""). Likewise, if through is not encountered, the result is an empty binary ("").

Examples

iex> {:ok, structured_io} = StructuredIO.start_link
iex> StructuredIO.write structured_io,
...>                    "<elem>foo</elem"
:ok
iex> StructuredIO.read_across structured_io,
...>                          "<elem>",
...>                          "</elem>"
""
iex> StructuredIO.write structured_io,
...>                    "><elem>bar</elem>"
:ok
iex> StructuredIO.read_across structured_io,
...>                          "<elem>",
...>                          "</elem>"
"<elem>foo</elem>"
iex> StructuredIO.read_across structured_io,
...>                          "<elem>",
...>                          "</elem>"
"<elem>bar</elem>"
iex> StructuredIO.read_across structured_io,
...>                          "<elem>",
...>                          "</elem>"
""
Link to this function read_through(structured_io, through, timeout \\ 5000) View Source
read_through(GenServer.server(), binary(), timeout()) :: binary()

Reads data from the specified structured_io if and until the specified through is encountered, including through, using the specified timeout (defaults to 5,000 milliseconds).

If through is not encountered, the result is an empty binary ("").

Examples

iex> {:ok, structured_io} = StructuredIO.start_link
iex> StructuredIO.write structured_io,
...>                    "foo<br /"
:ok
iex> StructuredIO.read_through structured_io,
...>                           "<br />"
""
iex> StructuredIO.write structured_io,
...>                    ">bar<br />"
:ok
iex> StructuredIO.read_through structured_io,
...>                           "<br />"
"foo<br />"
iex> StructuredIO.read_through structured_io,
...>                           "<br />"
"bar<br />"
iex> StructuredIO.read_through structured_io,
...>                           "<br />"
""
Link to this function read_to(structured_io, to, timeout \\ 5000) View Source
read_to(GenServer.server(), binary(), timeout()) :: binary()

Reads data from the specified structured_io if and until the specified to is encountered, excluding to, using the specified timeout (defaults to 5,000 milliseconds).

If through is not encountered, the result is an empty binary ("").

Examples

iex> {:ok, structured_io} = StructuredIO.start_link
iex> StructuredIO.write structured_io,
...>                    "foo</elem><elem"
:ok
iex> StructuredIO.read_to structured_io,
...>                      "<elem>"
""
iex> StructuredIO.write structured_io,
...>                    ">bar</elem><elem>baz"
:ok
iex> StructuredIO.read_to structured_io,
...>                      "<elem>"
"foo</elem>"
iex> StructuredIO.read_to structured_io,
...>                      "<elem>"
""
iex> StructuredIO.read_through structured_io,
...>                           "<elem>"
"<elem>"
iex> StructuredIO.read_to structured_io,
...>                      "<elem>"
"bar</elem>"
iex> StructuredIO.read_to structured_io,
...>                      "<elem>"
""

Starts a StructuredIO process without links (outside a supervision tree) with the specified options.

See StructuredIO.start_link/2.

Link to this function stop(structured_io, reason \\ :normal, timeout \\ :infinity) View Source
stop(GenServer.server(), term(), timeout()) :: :ok

Synchronously stops the specified structured_io process with the specified reason (defaults to :normal) and timeout (defaults to infinity).

Link to this function write(structured_io, chardata) View Source
write(GenServer.server(), IO.chardata() | String.Chars.t()) ::
  :ok |
  error()

Asynchronously writes the specified chardata as a binary to the specified structured_io.

See StructuredIO.read_across/3, StructuredIO.read_through/2, and StructuredIO.read_to/2 for examples.