Class: MinHttp::Chunk
- Inherits:
-
Object
- Object
- MinHttp::Chunk
- Defined in:
- lib/chunk.rb
Instance Method Summary collapse
-
#initialize(body) ⇒ Chunk
constructor
A new instance of Chunk.
- #parse ⇒ Object
- #read_chunk ⇒ Object
- #read_chunk_size ⇒ Object
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
#parse ⇒ Object
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_chunk ⇒ Object
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_size ⇒ Object
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 |