Class: MinHttp::Chunk

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

Instance Method Summary collapse

Constructor Details

#initialize(body) ⇒ Chunk

Returns a new instance of Chunk.



3
4
5
6
# File 'lib/chunk.rb', line 3

def initialize(body)
  @body = body
  @newbody = ""
end

Instance Method Details

#parseObject



19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/chunk.rb', line 19

def parse
  @length = 0
  @chunk_size = read_chunk_size

  while (@chunk_size > 0)
    read_chunk
    @length = @length + @chunk_size
    @chunk_size = read_chunk_size
  end

  return @newbody
end

#read_chunkObject



13
14
15
16
17
# File 'lib/chunk.rb', line 13

def read_chunk
  @newbody << @body[0, @chunk_size]
  new_body_len =  @body.length - @chunk_size
  @body = @body[@chunk_size+2, new_body_len-2]
end

#read_chunk_sizeObject



8
9
10
11
# File 'lib/chunk.rb', line 8

def read_chunk_size
  chunk_info, @body = @body.split("\r\n", 2)
  chunk_info.to_i(16)
end