Class: Riddl::Protocols::HTTP::StreamingBody

Inherits:
Object
  • Object
show all
Defined in:
lib/ruby/riddl/protocols/http/generator.rb

Constant Summary collapse

CHUNK_SIZE =

64 KiB

1 << 16

Instance Method Summary collapse

Constructor Details

#initialize(parts) ⇒ StreamingBody

Returns a new instance of StreamingBody.



12
13
14
# File 'lib/ruby/riddl/protocols/http/generator.rb', line 12

def initialize(parts)
  @parts = parts
end

Instance Method Details

#closeObject



27
28
29
30
31
# File 'lib/ruby/riddl/protocols/http/generator.rb', line 27

def close
  @parts.each do |part|
    part.close if part.respond_to?(:close) && !part.is_a?(String)
  end
end

#eachObject



16
17
18
19
20
21
22
23
24
25
# File 'lib/ruby/riddl/protocols/http/generator.rb', line 16

def each
  @parts.each do |part|
    if part.respond_to?(:read)
      part.rewind if part.respond_to?(:rewind)
      yield chunk while (chunk = part.read(CHUNK_SIZE))
    else
      yield part.to_s
    end
  end
end