@@ -208,15 +208,18 @@ defmodule StringIO do
208208
209209  @ impl  true 
210210  def  handle_call ( :contents ,  _from ,  % { input:  input ,  output:  output }  =  state )  do 
211-     { :reply ,  { input ,  output } ,  state } 
211+     # output is built as iodata, and converted before we need to cross the process boundary 
212+     output  =  IO . iodata_to_binary ( output ) 
213+     { :reply ,  { input ,  output } ,  % { state  |  output:  output } } 
212214  end 
213215
214216  def  handle_call ( :flush ,  _from ,  % { output:  output }  =  state )  do 
215-     { :reply ,  output ,  % { state  |  output:  "" } } 
217+     { :reply ,  IO . iodata_to_binary ( output ) ,  % { state  |  output:  "" } } 
216218  end 
217219
218220  def  handle_call ( :close ,  _from ,  % { input:  input ,  output:  output }  =  state )  do 
219-     { :stop ,  :normal ,  { :ok ,  { input ,  output } } ,  state } 
221+     output  =  IO . iodata_to_binary ( output ) 
222+     { :stop ,  :normal ,  { :ok ,  { input ,  output } } ,  % { state  |  output:  output } } 
220223  end 
221224
222225  defp  io_request ( from ,  reply_as ,  req ,  state )  do 
@@ -302,7 +305,8 @@ defmodule StringIO do
302305  defp  put_chars ( encoding ,  chars ,  req ,  state )  do 
303306    case  :unicode . characters_to_binary ( chars ,  encoding ,  state . encoding )  do 
304307      string  when  is_binary ( string )  -> 
305-         { :ok ,  % { state  |  output:  state . output  <>  string } } 
308+         # we build output as iodata internally 
309+         { :ok ,  % { state  |  output:  [ state . output  |  string ] } } 
306310
307311      { _ ,  _ ,  _ }  -> 
308312        { { :error ,  { :no_translation ,  encoding ,  state . encoding } } ,  state } 
@@ -455,6 +459,7 @@ defmodule StringIO do
455459  end 
456460
457461  defp  state_after_read ( % { capture_prompt:  true ,  output:  output }  =  state ,  remainder ,  prompt ,  count )  do 
462+     output  =  IO . iodata_to_binary ( output ) 
458463    output  =  << output :: binary ,  :binary . copy ( IO . chardata_to_string ( prompt ) ,  count ) :: binary >> 
459464    % { state  |  input:  remainder ,  output:  output } 
460465  end 
0 commit comments