Class: ImageSize::URIReader::BodyReader

Inherits:
Object
  • Object
show all
Includes:
ChunkyReader
Defined in:
lib/image_size/uri_reader.rb

Overview

:nodoc:

Instance Method Summary collapse

Methods included from ChunkyReader

#chunk_size

Methods included from Reader

#fetch, open_with_uri, #unpack, #unpack1

Constructor Details

#initialize(response) ⇒ BodyReader

Returns a new instance of BodyReader.



27
28
29
30
# File 'lib/image_size/uri_reader.rb', line 27

def initialize(response)
  @body = String.new
  @body_reader = response.to_enum(:read_body)
end

Instance Method Details

#[](offset, length) ⇒ Object



32
33
34
35
36
37
38
39
40
41
42
# File 'lib/image_size/uri_reader.rb', line 32

def [](offset, length)
  if @body_reader
    begin
      @body << @body_reader.next while @body.length < offset + length
    rescue StopIteration, IOError
      @body_reader = nil
    end
  end

  @body[offset, length]
end