Class: WEBrick::ChunkedStream
- Inherits:
-
Object
- Object
- WEBrick::ChunkedStream
- Defined in:
- lib/driq/webrick.rb
Instance Method Summary collapse
- #close ⇒ Object
-
#initialize(stream) ⇒ ChunkedStream
constructor
A new instance of ChunkedStream.
- #next_chunk ⇒ Object
- #readpartial(size, buf = '') ⇒ Object
Constructor Details
#initialize(stream) ⇒ ChunkedStream
Returns a new instance of ChunkedStream.
5 6 7 8 9 |
# File 'lib/driq/webrick.rb', line 5 def initialize(stream) @data = nil @cursor = 0 @stream = stream end |
Instance Method Details
#close ⇒ Object
17 18 19 |
# File 'lib/driq/webrick.rb', line 17 def close @stream.close end |
#next_chunk ⇒ Object
11 12 13 14 15 |
# File 'lib/driq/webrick.rb', line 11 def next_chunk @stream.pop rescue raise EOFError end |
#readpartial(size, buf = '') ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/driq/webrick.rb', line 21 def readpartial(size, buf='') buf.clear unless @data @cursor = 0 @data = next_chunk @data.force_encoding("ascii-8bit") end if @data.bytesize <= size buf << @data @data = nil else slice = @data.byteslice(@cursor, size) @cursor += slice.bytesize buf << slice if @data.bytesize <= @cursor @data = nil end end buf end |