This module provides an IO device that wraps a string.
Examples
iex> {:ok, pid} = StringIO.open("foo")
iex> IO.read(pid, 2)
"fo"
This module provides an IO device that wraps a string.
iex> {:ok, pid} = StringIO.open("foo")
iex> IO.read(pid, 2)
"fo"
close(pid) :: {:ok, {binary, binary}}
Stops the IO device and returns remaining buffers.
iex> {:ok, pid} = StringIO.open("in")
iex> IO.write(pid, "out")
iex> StringIO.close(pid)
{:ok, {"in", "out"}}
contents(pid) :: {binary, binary}
Returns current buffers.
iex> {:ok, pid} = StringIO.open("in")
iex> IO.write(pid, "out")
iex> StringIO.contents(pid)
{"in", "out"}
open(binary, Keyword.t) :: {:ok, pid}
Creates an IO device.
If the :capture_prompt
option is set to true
,
prompts (specified as arguments to IO.get*
functions)
are captured.
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)
{"", ">"}