Elixir v1.2.6 StringIO
This module provides an IO device that wraps a string.
Examples
iex> {:ok, pid} = StringIO.open("foo")
iex> IO.read(pid, 2)
"fo"
Summary
Functions
Stops the IO device and returns remaining buffers
Returns current buffers
Flushes output buffer
Creates an IO device
Functions
Stops the IO device and returns remaining buffers.
Examples
iex> {:ok, pid} = StringIO.open("in")
iex> IO.write(pid, "out")
iex> StringIO.close(pid)
{:ok, {"in", "out"}}
Returns current buffers.
Examples
iex> {:ok, pid} = StringIO.open("in")
iex> IO.write(pid, "out")
iex> StringIO.contents(pid)
{"in", "out"}
Flushes output buffer.
Examples
iex> {:ok, pid} = StringIO.open("in")
iex> IO.write(pid, "out")
iex> StringIO.flush(pid)
"out"
iex> StringIO.contents(pid)
{"in", ""}
Creates an IO device.
If the :capture_prompt
option is set to true
,
prompts (specified as arguments to IO.get*
functions)
are captured.
Examples
iex> {:ok, pid} = StringIO.open("foo")
iex> IO.gets(pid, ">")
"foo"
iex> StringIO.contents(pid)
{"", ""}
iex> {:ok, pid} = StringIO.open("foo", capture_prompt: true)
iex> IO.gets(pid, ">")
"foo"
iex> StringIO.contents(pid)
{"", ">"}