class Rack::Multipart::Parser::BoundedIO

:nodoc:

def initialize(io, content_length)

:nodoc:
def initialize(io, content_length)
  @io             = io
  @content_length = content_length
  @cursor = 0
end

def read(size, outbuf = nil)

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