ohler55 / ox

Ruby Optimized XML Parser
http://www.ohler.com/ox
MIT License
904 stars 76 forks source link

`StringIO` in `Ox::Builder` #293

Open Yegorov opened 2 years ago

Yegorov commented 2 years ago

Hello! It possible use StringIO in Ox::Builder?

require 'ox'
io = StringIO.new
b = Ox::Builder.io(io, indent: 2) # Here I get an exception: `io': expected an IO that has a fileno. (IOError)
10.times do
  b.element('node') do
    b.text('value')
  end
end
b.close
io.to_s
ohler55 commented 2 years ago

Currently only files are supported. I'll looking into supporting anything that can be written to. Sorry for being slow to respond.

ohler55 commented 2 years ago

It would be too much of a change to support StringIO with little gain. Did you know you can create a new Builder without and io and it will build a string? Line 1472 of the test.rb file is an example of that.