Class: Rack::Multipart::Parser::BoundedIO
- Inherits:
-
Object
- Object
- Rack::Multipart::Parser::BoundedIO
- Defined in:
- lib/rack/multipart/parser.rb
Overview
:nodoc:
Instance Method Summary collapse
-
#initialize(io, content_length) ⇒ BoundedIO
constructor
A new instance of BoundedIO.
- #read(size, outbuf = nil) ⇒ Object
- #rewind ⇒ Object
Constructor Details
#initialize(io, content_length) ⇒ BoundedIO
Returns a new instance of BoundedIO.
22 23 24 25 26 |
# File 'lib/rack/multipart/parser.rb', line 22 def initialize(io, content_length) @io = io @content_length = content_length @cursor = 0 end |
Instance Method Details
#read(size, outbuf = nil) ⇒ Object
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/rack/multipart/parser.rb', line 28 def read(size, outbuf = nil) return if @cursor >= @content_length left = @content_length - @cursor str = if left < size @io.read left, outbuf else @io.read size, outbuf end if str @cursor += str.bytesize else # Raise an error for mismatching Content-Length and actual contents raise EOFError, "bad content body" end str end |
#rewind ⇒ Object
49 50 51 |
# File 'lib/rack/multipart/parser.rb', line 49 def rewind @io.rewind end |