Class: Riak::Util::Multipart::StreamParser
- Includes:
- Riak::Util::Multipart, Translation
- Defined in:
- lib/riak/util/multipart/stream_parser.rb
Overview
This class is parses chunked/streamed multipart HTTP streams. It is used by streaming MapReduce queries, and in the future streaming key-lists (once implemented on the Riak side).
Instance Method Summary collapse
-
#accept(chunk) ⇒ Object
Accepts a chunk of the HTTP response stream, and yields to the block when appropriate.
-
#initialize {|Hash| ... } ⇒ StreamParser
constructor
Creates a new StreamParser.
-
#to_proc ⇒ Object
Returns a Proc that can be passed to an HTTP request method.
Methods included from Translation
Methods included from Riak::Util::Multipart
Constructor Details
#initialize {|Hash| ... } ⇒ StreamParser
Creates a new StreamParser.
Example usage:
http.get(200, "/riak", "foo", {}, &StreamParser.new {|part| ... })
20 21 22 23 24 25 |
# File 'lib/riak/util/multipart/stream_parser.rb', line 20 def initialize(&block) raise ArgumentError, t('missing_block') unless block_given? @buffer = "" @block = block @state = :get_boundary end |
Instance Method Details
#accept(chunk) ⇒ Object
Accepts a chunk of the HTTP response stream, and yields to the block when appropriate.
29 30 31 32 |
# File 'lib/riak/util/multipart/stream_parser.rb', line 29 def accept(chunk) @buffer << chunk @state = send(@state) end |
#to_proc ⇒ Object
Returns a Proc that can be passed to an HTTP request method.
35 36 37 |
# File 'lib/riak/util/multipart/stream_parser.rb', line 35 def to_proc method(:accept).to_proc end |