Class: ImageSize::URIReader::BodyReader
- Inherits:
-
Object
- Object
- ImageSize::URIReader::BodyReader
- Includes:
- ChunkyReader
- Defined in:
- lib/image_size/uri_reader.rb
Overview
:nodoc:
Instance Attribute Summary collapse
-
#byte_size ⇒ Object
readonly
Returns the value of attribute byte_size.
Instance Method Summary collapse
- #[](offset, length) ⇒ Object
-
#initialize(response) ⇒ BodyReader
constructor
A new instance of BodyReader.
Methods included from ChunkyReader
Methods included from Reader
#fetch, open_with_uri, #stream, #unpack, #unpack1
Constructor Details
#initialize(response) ⇒ BodyReader
Returns a new instance of BodyReader.
34 35 36 37 38 |
# File 'lib/image_size/uri_reader.rb', line 34 def initialize(response) @body = String.new @body_reader = response.to_enum(:read_body) @byte_size = response.content_length end |
Instance Attribute Details
#byte_size ⇒ Object (readonly)
Returns the value of attribute byte_size.
32 33 34 |
# File 'lib/image_size/uri_reader.rb', line 32 def byte_size @byte_size end |
Instance Method Details
#[](offset, length) ⇒ Object
40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/image_size/uri_reader.rb', line 40 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 |