structured_io v0.9.0 StructuredIO.Deprecated View Source

Provides deprecated functions to StructuredIO.

Encoding

Mixing the use of binary mode and Unicode mode results in a StructuredIO.error/0.

Link to this section Summary

Functions

Reads data from the specified structured_io beginning with the specified left and ending with the specified right, inclusive

Reads data from the specified structured_io beginning with the specified left and ending with the specified right, exclusive

Reads data from the specified structured_io if and until the specified right is encountered, including right

Reads data from the specified structured_io if and until the specified right is encountered, excluding right

Writes the specified iodata to the specified structured_io

Reads data from the specified structured_io beginning with the specified left and ending with the specified right, inclusive

Reads data from the specified structured_io beginning with the specified left and ending with the specified right, exclusive

Reads data from the specified structured_io if and until the specified right is encountered, including right

Reads data from the specified structured_io if and until the specified right is encountered, excluding right

Starts a StructuredIO process without links (outside a supervision tree)

Starts a StructuredIO process linked to the current process

Link to this section Functions

Link to this function binread_across(structured_io, left, right, timeout \\ 5000) View Source

Reads data from the specified structured_io beginning with the specified left and ending with the specified right, inclusive.

If the data read does not begin with left, the result is an empty binary (""). Likewise, if right 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>>
""

iex> {:ok,
...>  structured_io} = StructuredIO.start_link
iex> StructuredIO.binwrite structured_io,
...>                       "<elem>"
:ok
iex> <<fragment1::binary-size(3), fragment2::binary>> = "😕"
iex> StructuredIO.binwrite structured_io,
...>                       fragment1
:ok
iex> StructuredIO.binread_across structured_io,
...>                             "<elem>",
...>                             "</elem>"
""
iex> StructuredIO.binwrite structured_io,
...>                       fragment2
:ok
iex> StructuredIO.binwrite structured_io,
...>                       "</elem>"
:ok
iex> StructuredIO.binread_across structured_io,
...>                             "<elem>",
...>                             "</elem>"
"<elem>😕</elem>"
iex> StructuredIO.binread_across structured_io,
...>                             "<elem>",
...>                             "</elem>"
""
Link to this function binread_between(structured_io, left, right, timeout \\ 5000) View Source

Reads data from the specified structured_io beginning with the specified left and ending with the specified right, exclusive.

If the data read does not begin with left, the result is an empty binary (""). Likewise, if right 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_between 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_between structured_io,
...>                              <<0, 0, 0>>,
...>                              <<255, 255, 255>>
<<1, 2, 3>>
iex> StructuredIO.binread_between structured_io,
...>                              <<0, 0, 0>>,
...>                              <<255, 255, 255>>
<<4, 5, 6>>
iex> StructuredIO.binread_between structured_io,
...>                              <<0, 0, 0>>,
...>                              <<255, 255, 255>>
""

iex> {:ok,
...>  structured_io} = StructuredIO.start_link
iex> StructuredIO.binwrite structured_io,
...>                       "<elem>"
:ok
iex> <<fragment1::binary-size(3), fragment2::binary>> = "😕"
iex> StructuredIO.binwrite structured_io,
...>                       fragment1
:ok
iex> StructuredIO.binread_between structured_io,
...>                              "<elem>",
...>                              "</elem>"
""
iex> StructuredIO.binwrite structured_io,
...>                       fragment2
:ok
iex> StructuredIO.binwrite structured_io,
...>                       "</elem>"
:ok
iex> StructuredIO.binread_between structured_io,
...>                              "<elem>",
...>                              "</elem>"
"😕"
iex> StructuredIO.binread_between structured_io,
...>                              "<elem>",
...>                              "</elem>"
""
Link to this function binread_through(structured_io, right, timeout \\ 5000) View Source

Reads data from the specified structured_io if and until the specified right is encountered, including right.

If right 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>>
""

iex> {:ok,
...>  structured_io} = StructuredIO.start_link
iex> <<fragment1::binary-size(3), fragment2::binary>> = "😕"
iex> StructuredIO.binwrite structured_io,
...>                       fragment1
:ok
iex> StructuredIO.binread_through structured_io,
...>                              "<br/>"
""
iex> StructuredIO.binwrite structured_io,
...>                       fragment2
:ok
iex> StructuredIO.binwrite structured_io,
...>                       "<br/>"
:ok
iex> StructuredIO.binread_through structured_io,
...>                              "<br/>"
"😕<br/>"
iex> StructuredIO.binread_through structured_io,
...>                              "<br/>"
""
Link to this function binread_to(structured_io, right, timeout \\ 5000) View Source

Reads data from the specified structured_io if and until the specified right is encountered, excluding right.

If right 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_to structured_io,
...>                         <<255, 255, 255>>
""
iex> StructuredIO.binwrite structured_io,
...>                       <<255, 4, 5, 6, 255, 255, 255>>
:ok
iex> StructuredIO.binread_to structured_io,
...>                         <<255, 255, 255>>
<<1, 2, 3>>
iex> StructuredIO.binread_through structured_io,
...>                              <<255, 255, 255>>
<<255, 255, 255>>
iex> StructuredIO.binread_to structured_io,
...>                         <<255, 255, 255>>
<<4, 5, 6>>
iex> StructuredIO.binread_to structured_io,
...>                         <<255, 255, 255>>
""

iex> {:ok,
...>  structured_io} = StructuredIO.start_link
iex> <<fragment1::binary-size(3), fragment2::binary>> = "😕"
iex> StructuredIO.binwrite structured_io,
...>                       fragment1
:ok
iex> StructuredIO.binread_to structured_io,
...>                         "<br/>"
""
iex> StructuredIO.binwrite structured_io,
...>                       fragment2
:ok
iex> StructuredIO.binwrite structured_io,
...>                       "<br/>"
:ok
iex> StructuredIO.binread_to structured_io,
...>                         "<br/>"
"😕"
iex> StructuredIO.binread_to structured_io,
...>                         "<br/>"
""
Link to this function binwrite(structured_io, iodata) View Source
binwrite(GenServer.server(), iodata()) :: :ok | StructuredIO.error()

Writes the specified iodata to the specified structured_io.

See the binread_* functions for examples.

Link to this function read_across(structured_io, left, right, timeout \\ 5000) View Source

Reads data from the specified structured_io beginning with the specified left and ending with the specified right, inclusive.

If the data read does not begin with left, the result is an empty binary (""). Likewise, if right 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>"
""

iex> {:ok,
...>  structured_io} = StructuredIO.start_link
iex> StructuredIO.write structured_io,
...>                    "<elem>"
:ok
iex> <<fragment1::binary-size(3), fragment2::binary>> = "😕"
iex> StructuredIO.write structured_io,
...>                    fragment1
:ok
iex> StructuredIO.read_across structured_io,
...>                          "<elem>",
...>                          "</elem>"
{:error,
 "UnicodeConversionError: incomplete encoding starting at #{inspect fragment1}"}
iex> StructuredIO.write structured_io,
...>                    fragment2
:ok
iex> StructuredIO.write structured_io,
...>                    "</elem>"
:ok
iex> StructuredIO.read_across structured_io,
...>                          "<elem>",
...>                          "</elem>"
"<elem>😕</elem>"
iex> StructuredIO.read_across structured_io,
...>                          "<elem>",
...>                          "</elem>"
""
Link to this function read_between(structured_io, left, right, timeout \\ 5000) View Source

Reads data from the specified structured_io beginning with the specified left and ending with the specified right, exclusive.

If the data read does not begin with left, the result is an empty binary (""). Likewise, if right 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_between structured_io,
...>                           "<elem>",
...>                           "</elem>"
""
iex> StructuredIO.write structured_io,
...>                    "><elem>bar</elem>"
:ok
iex> StructuredIO.read_between structured_io,
...>                           "<elem>",
...>                           "</elem>"
"foo"
iex> StructuredIO.read_between structured_io,
...>                           "<elem>",
...>                           "</elem>"
"bar"
iex> StructuredIO.read_between structured_io,
...>                           "<elem>",
...>                           "</elem>"
""

iex> {:ok,
...>  structured_io} = StructuredIO.start_link
iex> StructuredIO.write structured_io,
...>                    "<elem>"
:ok
iex> <<fragment1::binary-size(3), fragment2::binary>> = "😕"
iex> StructuredIO.write structured_io,
...>                    fragment1
:ok
iex> StructuredIO.read_between structured_io,
...>                           "<elem>",
...>                           "</elem>"
{:error,
 "UnicodeConversionError: incomplete encoding starting at #{inspect fragment1}"}
iex> StructuredIO.write structured_io,
...>                    fragment2
:ok
iex> StructuredIO.write structured_io,
...>                    "</elem>"
:ok
iex> StructuredIO.read_between structured_io,
...>                           "<elem>",
...>                           "</elem>"
"😕"
iex> StructuredIO.read_between structured_io,
...>                           "<elem>",
...>                           "</elem>"
""
Link to this function read_through(structured_io, right, timeout \\ 5000) View Source

Reads data from the specified structured_io if and until the specified right is encountered, including right.

If right 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/>"
""

iex> {:ok,
...>  structured_io} = StructuredIO.start_link
iex> <<fragment1::binary-size(3), fragment2::binary>> = "😕"
iex> StructuredIO.write structured_io,
...>                    fragment1
:ok
iex> StructuredIO.read_through structured_io,
...>                           "<br/>"
{:error,
 "UnicodeConversionError: incomplete encoding starting at #{inspect fragment1}"}
iex> StructuredIO.write structured_io,
...>                    fragment2
:ok
iex> StructuredIO.write structured_io,
...>                    "<br/>"
:ok
iex> StructuredIO.read_through structured_io,
...>                           "<br/>"
"😕<br/>"
iex> StructuredIO.read_through structured_io,
...>                           "<br/>"
""
Link to this function read_to(structured_io, right, timeout \\ 5000) View Source

Reads data from the specified structured_io if and until the specified right is encountered, excluding right.

If right 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_to structured_io,
...>                      "<br/>"
""
iex> StructuredIO.write structured_io,
...>                    ">bar<br/>"
:ok
iex> StructuredIO.read_to structured_io,
...>                      "<br/>"
"foo"
iex> StructuredIO.read_through structured_io,
...>                           "<br/>"
"<br/>"
iex> StructuredIO.read_to structured_io,
...>                      "<br/>"
"bar"
iex> StructuredIO.read_to structured_io,
...>                      "<br/>"
""

iex> {:ok,
...>  structured_io} = StructuredIO.start_link
iex> <<fragment1::binary-size(3), fragment2::binary>> = "😕"
iex> StructuredIO.write structured_io,
...>                    fragment1
:ok
iex> StructuredIO.read_to structured_io,
...>                      "<br/>"
{:error,
 "UnicodeConversionError: incomplete encoding starting at #{inspect fragment1}"}
iex> StructuredIO.write structured_io,
...>                    fragment2
:ok
iex> StructuredIO.write structured_io,
...>                    "<br/>"
:ok
iex> StructuredIO.read_to structured_io,
...>                      "<br/>"
"😕"
iex> StructuredIO.read_to structured_io,
...>                      "<br/>"
""

Starts a StructuredIO process without links (outside a supervision tree).

See start_link/0.

Starts a StructuredIO process linked to the current process.

See the binread_* and read_* functions for examples.