Class: Rack::Multipart::Parser::BoundedIO

Inherits:
Object
  • Object
show all
Defined in:
lib/rack/multipart/parser.rb

Overview

:nodoc:

Instance Method Summary collapse

Constructor Details

#initialize(io, content_length) ⇒ BoundedIO

Returns a new instance of BoundedIO.



49
50
51
52
53
# File 'lib/rack/multipart/parser.rb', line 49

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

Instance Method Details

#read(size, outbuf = nil) ⇒ Object



55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
# File 'lib/rack/multipart/parser.rb', line 55

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