Class: Riak::Util::Multipart::StreamParser
- Inherits:
-
Object
- Object
- 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).
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| ... })
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
- (Object) accept(chunk)
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 |
- (Object) to_proc
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 |