lib/tracksperanto/buffer_io.rb in tracksperanto-1.8.4 vs lib/tracksperanto/buffer_io.rb in tracksperanto-1.9.0

- old
+ new

@@ -3,11 +3,11 @@ # BufferIO is used for writing big segments of text. When the segment is bigger than a certain number of bytes, # the underlying memory buffer will be swapped with a tempfile class Tracksperanto::BufferIO < DelegateClass(IO) include Tracksperanto::Returning - IN_MEMORY_SIZE_LIMIT = 100_000 + MAX_IN_MEM_BYTES = 100_000 def initialize __setobj__(StringIO.new) end @@ -35,14 +35,13 @@ private def replace_with_tempfile_if_needed return if @tempfile_in io = __getobj__ - if io.pos > IN_MEMORY_SIZE_LIMIT - @tempfile_in = true + if io.pos > MAX_IN_MEM_BYTES tf = Tempfile.new("tracksperanto-xbuf") - io.rewind - tf.write(io.read) until io.eof? + tf.write(io.string) __setobj__(tf) + @tempfile_in = true end end end \ No newline at end of file