lib/tracksperanto/buffer_io.rb in tracksperanto-4.1.3 vs lib/tracksperanto/buffer_io.rb in tracksperanto-4.2.0
- old
+ new
@@ -10,29 +10,28 @@
# BufferIO is used for writing big segments of text. It works like a StringIO, but when the size
# of the underlying string buffer exceeds MAX_IN_MEM_BYTES the string will be flushed to disk
# and it automagically becomes a Tempfile
class Tracksperanto::BufferIO < Tracksperanto::IOWrapper
- include Tracksperanto::Returning
MAX_IN_MEM_BYTES = 5_000_000
def initialize
@backing_buffer = StringIO.new
end
def write(s)
- returning(super) { replace_with_tempfile_if_needed }
+ super.tap { replace_with_tempfile_if_needed }
end
alias_method :<<, :write
def puts(s)
- returning(super) { replace_with_tempfile_if_needed }
+ super.tap { replace_with_tempfile_if_needed }
end
def putc(c)
- returning(super) { replace_with_tempfile_if_needed }
+ super.tap { replace_with_tempfile_if_needed }
end
def close!
@backing_buffer.close! if @tempfile_in
@backing_buffer = nil
@@ -57,10 +56,10 @@
sio = @backing_buffer
tf = Tempfile.new("tracksperanto-xbuf")
tf.set_encoding(Encoding::BINARY) if @rewindable_io.respond_to?(:set_encoding)
tf.binmode
tf.write(sio.string)
- tf.flush # Needed of we will reopen this file soon from another thread/loop
+ tf.flush # Needed if we are going to reopen this file soon from another thread/loop
sio.string = ""
GC.start
@backing_buffer = tf
@tempfile_in = true