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

Inherits:
Object
  • Object
show all
Defined in:
lib/ruby/riddl/protocols/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/generator.rb', line 12

def initialize(parts)
  @parts = parts
end

Instance Method Details

#closeObject



29
30
31
32
33
# File 'lib/ruby/riddl/protocols/generator.rb', line 29

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
26
27
# File 'lib/ruby/riddl/protocols/generator.rb', line 16

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