Class: Riak::Util::Multipart::StreamParser
- Inherits:
-
Object
- Object
- Riak::Util::Multipart::StreamParser
- Includes:
- Riak::Util::Multipart, Translation
- Defined in:
- riak-client/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).
Constant Summary
- CAPTURE_BOUNDARY =
/^--([A-Za-z0-9\'()+_,-.\/:=?]+)\r?\n/
Instance Method Summary (collapse)
-
- (Object) accept(chunk)
Accepts a chunk of the HTTP response stream, and yields to the block when appropriate.
-
- (StreamParser) initialize {|Hash| ... }
constructor
Creates a new StreamParser.
-
- (Object) to_proc
Returns a Proc that can be passed to an HTTP request method.
Methods included from Translation
Methods included from Riak::Util::Multipart
Constructor Details
- (StreamParser) initialize {|Hash| ... }
Creates a new StreamParser.
Example usage:
http.get(200, "/riak", "foo", {}, &StreamParser.new {|part| ... })
33 34 35 36 37 38 |
# File 'riak-client/lib/riak/util/multipart/stream_parser.rb', line 33 def initialize(&block) raise ArgumentError, t('missing_block') unless block_given? @buffer = "" @block = block @state = :get_boundary end |
Instance Method Details
- (Object) accept(chunk)
Accepts a chunk of the HTTP response stream, and yields to the block when appropriate.
42 43 44 45 |
# File 'riak-client/lib/riak/util/multipart/stream_parser.rb', line 42 def accept(chunk) @buffer << chunk @state = send(@state) end |
- (Object) to_proc
Returns a Proc that can be passed to an HTTP request method.
48 49 50 |
# File 'riak-client/lib/riak/util/multipart/stream_parser.rb', line 48 def to_proc method(:accept).to_proc end |