Module: WahWah::LazyRead

Included in:
Asf::Object, Flac::Block, ID3::Frame, Mp4::Atom, Riff::Chunk
Defined in:
lib/wahwah/lazy_read.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.prepended(base) ⇒ Object



5
6
7
8
9
# File 'lib/wahwah/lazy_read.rb', line 5

def self.prepended(base)
  base.class_eval do
    attr_reader :size
  end
end

Instance Method Details

#dataObject



18
19
20
21
22
23
24
25
26
# 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

#initialize(file_io, *arg) ⇒ Object



11
12
13
14
15
16
# 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

#skipObject



28
29
30
31
# File 'lib/wahwah/lazy_read.rb', line 28

def skip
  @file_io.seek(@position)
  @file_io.seek(size, IO::SEEK_CUR)
end