Class: Async::HTTP::Body::Chunked
Instance Method Summary
collapse
Methods inherited from Readable
#each, #finish, #join, #length
Constructor Details
#initialize(protocol) ⇒ Chunked
Returns a new instance of Chunked.
27
28
29
30
31
32
33
|
# File 'lib/async/http/body/chunked.rb', line 27
def initialize(protocol)
@protocol = protocol
@finished = false
@length = 0
@count = 0
end
|
Instance Method Details
#close(error = nil) ⇒ Object
39
40
41
42
43
44
45
46
47
|
# File 'lib/async/http/body/chunked.rb', line 39
def close(error = nil)
unless @finished
@protocol.close
@finished = true
end
super
end
|
#empty? ⇒ Boolean
35
36
37
|
# File 'lib/async/http/body/chunked.rb', line 35
def empty?
@finished
end
|
#inspect ⇒ Object
70
71
72
|
# File 'lib/async/http/body/chunked.rb', line 70
def inspect
"\#<#{self.class} #{@length} bytes read in #{@count} chunks>"
end
|
#read ⇒ Object
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
|
# File 'lib/async/http/body/chunked.rb', line 49
def read
return nil if @finished
length = @protocol.read_line.to_i(16)
if length == 0
@finished = true
@protocol.read_line
return nil
end
chunk = @protocol.stream.read(length)
@protocol.read_line
@length += length
@count += 1
return chunk
end
|