Class: OpenURI::Buffer

Inherits:
Object
  • Object
show all
Defined in:
lib/open-uri.rb

Overview

:nodoc: all

Constant Summary collapse

StringMax =
10240

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeBuffer

Returns a new instance of Buffer.


402
403
404
405
# File 'lib/open-uri.rb', line 402

def initialize
  @io = StringIO.new
  @size = 0
end

Instance Attribute Details

#sizeObject (readonly)

Returns the value of attribute size.


406
407
408
# File 'lib/open-uri.rb', line 406

def size
  @size
end

Instance Method Details

#<<(str) ⇒ Object


409
410
411
412
413
414
415
416
417
418
419
420
# File 'lib/open-uri.rb', line 409

def <<(str)
  @io << str
  @size += str.length
  if StringIO === @io && StringMax < @size
    require 'tempfile'
    io = Tempfile.new('open-uri')
    io.binmode
    Meta.init io, @io if Meta === @io
    io << @io.string
    @io = io
  end
end

#ioObject


422
423
424
425
# File 'lib/open-uri.rb', line 422

def io
  Meta.init @io unless Meta === @io
  @io
end