Class: ImageSize::URIReader::RangeReader

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

Overview

:nodoc:

Instance Method Summary collapse

Methods included from HTTPChunkyReader

#chunk_range_header

Methods included from ChunkyReader

#[], #chunk_size

Methods included from Reader

#fetch, open_with_uri, #stream, #unpack, #unpack1

Constructor Details

#initialize(http, request_uri, chunk0) ⇒ RangeReader

Returns a new instance of RangeReader.



49
50
51
52
53
# File 'lib/image_size/uri_reader.rb', line 49

def initialize(http, request_uri, chunk0)
  @http = http
  @request_uri = request_uri
  @chunks = { 0 => chunk0 }
end

Instance Method Details

#chunk(i) ⇒ Object



55
56
57
58
59
60
61
62
63
64
65
66
67
# File 'lib/image_size/uri_reader.rb', line 55

def chunk(i)
  unless @chunks.key?(i)
    response = @http.get(@request_uri, chunk_range_header(i))
    case response
    when Net::HTTPPartialContent
      @chunks[i] = response.body
    else
      raise "Unexpected response: #{response}"
    end
  end

  @chunks[i]
end