Class: EM::FastImage::FiberStream
- Inherits:
-
Object
- Object
- EM::FastImage::FiberStream
- Includes:
- StreamUtil
- Defined in:
- lib/em-fastimage.rb
Overview
:nodoc:
Instance Attribute Summary collapse
-
#pos ⇒ Object
readonly
Returns the value of attribute pos.
Instance Method Summary collapse
-
#initialize(read_fiber) ⇒ FiberStream
constructor
A new instance of FiberStream.
- #peek(n) ⇒ Object
- #read(n) ⇒ Object
Methods included from StreamUtil
Constructor Details
#initialize(read_fiber) ⇒ FiberStream
Returns a new instance of FiberStream.
332 333 334 335 336 337 |
# File 'lib/em-fastimage.rb', line 332 def initialize(read_fiber) @read_fiber = read_fiber @pos = 0 @strpos = 0 @str = '' end |
Instance Attribute Details
#pos ⇒ Object (readonly)
Returns the value of attribute pos.
330 331 332 |
# File 'lib/em-fastimage.rb', line 330 def pos @pos end |
Instance Method Details
#peek(n) ⇒ Object
339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 |
# File 'lib/em-fastimage.rb', line 339 def peek(n) while @strpos + n - 1 >= @str.size unused_str = @str[@strpos..-1] new_string = @read_fiber.resume raise CannotParseImage if !new_string # we are dealing with bytes here, so force the encoding new_string.force_encoding("ASCII-8BIT") if String.method_defined? :force_encoding @str = unused_str + new_string @strpos = 0 end result = @str[@strpos..(@strpos + n - 1)] end |
#read(n) ⇒ Object
355 356 357 358 359 360 |
# File 'lib/em-fastimage.rb', line 355 def read(n) result = peek(n) @strpos += n @pos += n result end |