module WahWah::LazyRead

Public Class Methods

new(file_io, *arg) click to toggle source
Calls superclass method
# File lib/wahwah/lazy_read.rb, line 11
def initialize(file_io, *arg)
  @file_io = file_io
  super(*arg)
  @position = @file_io.pos
  @data = get_data if @file_io.is_a?(StringIO)
end
prepended(base) click to toggle source
# File lib/wahwah/lazy_read.rb, line 5
def self.prepended(base)
  base.class_eval do
    attr_reader :size
  end
end

Public Instance Methods

data() click to toggle source
# File lib/wahwah/lazy_read.rb, line 18
def data
  if @file_io.closed? && @file_io.is_a?(File)
    @file_io = File.open(@file_io.path)
    @data = get_data
    @file_io.close
  end

  @data ||= get_data
end
skip() click to toggle source
# File lib/wahwah/lazy_read.rb, line 28
def skip
  @file_io.seek(@position)
  @file_io.seek(size, IO::SEEK_CUR)
end

Private Instance Methods

get_data() click to toggle source
# File lib/wahwah/lazy_read.rb, line 34
def get_data
  @file_io.seek(@position)
  @file_io.read(size)
end