class GifInfo::Body

Decoder and holder of block-encoded GIF data.

Public Class Methods

new(io) click to toggle source

Constructor. @param [IO] io IO object

# File lib/gif-info/body.rb, line 39
def initialize(io)
    @io = io
    @position = io.pos
end

Public Instance Methods

bytesize() click to toggle source

Returns bytesize of the data body. @return [Integer] length in bytes

# File lib/gif-info/body.rb, line 101
def bytesize
    self.data.bytesize
end
data(&block) click to toggle source

Returns data. If block given, streams it, in otherwise returns full value.

@yield [String] chunk in size of one data block of the raw data @return [String] full data content

# File lib/gif-info/body.rb, line 52
def data(&block)
    if not @data.nil?
        return @data
    end
    
    self.prepare!     # seeks to block position
    
    if not block.nil?
        loop do
            size = @io.getbyte
            break if size <= 0
            block.call(@io.read(size))
        end
    else
        data = ""
        self.data do |chunk|
            data << chunk
        end
        @data = data
        
        return @data
    end
end
prepare!() click to toggle source

Prepares for reading.

# File lib/gif-info/body.rb, line 92
def prepare!
    @io.seek(@position)
end
skip!() click to toggle source

Skips the body content in stream.

# File lib/gif-info/body.rb, line 80
def skip!
    loop do
        size = @io.getbyte
        break if size <= 0
        @io.seek(size, IO::SEEK_CUR)
    end
end