Class: EXIFR::TIFF::Data

Inherits:
Object
  • Object
show all
Defined in:
lib/exifr/tiff.rb

Overview

:nodoc:

Instance Attribute Summary (collapse)

Class Method Summary (collapse)

Instance Method Summary (collapse)

Constructor Details

- (Data) initialize(file)



603
604
605
606
607
608
609
610
611
612
613
614
# File 'lib/exifr/tiff.rb', line 603

def initialize(file)
  @io = file.respond_to?(:read) ? file : (@file = File.open(file, 'rb'))
  @buffer = ''
  @pos = 0

  case self[0..1]
  when 'II'; @short, @long = 'v', 'V'
  when 'MM'; @short, @long = 'n', 'N'
  else
    raise MalformedTIFF, "no byte order information found"
  end
end

Instance Attribute Details

- (Object) file (readonly)

Returns the value of attribute file



601
602
603
# File 'lib/exifr/tiff.rb', line 601

def file
  @file
end

- (Object) long (readonly)

Returns the value of attribute long



601
602
603
# File 'lib/exifr/tiff.rb', line 601

def long
  @long
end

- (Object) short (readonly)

Returns the value of attribute short



601
602
603
# File 'lib/exifr/tiff.rb', line 601

def short
  @short
end

Class Method Details

+ (Object) open(file, &block)



616
617
618
619
620
621
# File 'lib/exifr/tiff.rb', line 616

def self.open(file, &block)
  data = new(file)
  yield data
ensure
  data && data.file && data.file.close
end

Instance Method Details

- (Object) [](pos)



623
624
625
626
627
628
629
630
631
632
633
# File 'lib/exifr/tiff.rb', line 623

def [](pos)
  unless pos.respond_to?(:begin) && pos.respond_to?(:end)
    pos = pos..pos
  end

  if pos.begin < @pos || pos.end >= @pos + @buffer.size
    read_for(pos)
  end

  @buffer && @buffer[(pos.begin - @pos)..(pos.end - @pos)]
end

- (Object) readlong(pos)



639
640
641
# File 'lib/exifr/tiff.rb', line 639

def readlong(pos)
  self[pos..(pos + 3)].unpack(@long)[0]
end

- (Object) readshort(pos)



635
636
637
# File 'lib/exifr/tiff.rb', line 635

def readshort(pos)
  self[pos..(pos + 1)].unpack(@short)[0]
end

- (Object) size



643
644
645
646
# File 'lib/exifr/tiff.rb', line 643

def size
  @io.seek(0, IO::SEEK_END)
  @io.pos
end