Class: MongoHTTPSync::Parser::ReadpartialWorkaround

Inherits:
Object
  • Object
show all
Defined in:
lib/mongo_http_sync/parser.rb

Instance Method Summary collapse

Constructor Details

#initialize(target) ⇒ ReadpartialWorkaround

Returns a new instance of ReadpartialWorkaround.



50
51
52
# File 'lib/mongo_http_sync/parser.rb', line 50

def initialize(target)
  @target = target
end

Instance Method Details

#readpartial(maxlen) ⇒ Object



53
54
55
56
57
58
59
60
61
62
63
64
65
# File 'lib/mongo_http_sync/parser.rb', line 53

def readpartial(maxlen)
  if @buffer and @buffer.length > 0
    buff = @buffer[0..maxlen-1]
    @buffer = @buffer[maxlen..-1]
    return buff
  end
  r = @target.readpartial(maxlen)
  if r.dup.bytesize > maxlen
    @buffer = r[maxlen..-1]
    r = r[0..maxlen-1]
  end
  r
end