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.



15
16
17
18
19
# File 'lib/rack/multipart/parser.rb', line 15

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

Instance Method Details

#eof?Boolean

Returns:

  • (Boolean)


42
# File 'lib/rack/multipart/parser.rb', line 42

def eof?; @content_length == @cursor; end

#read(size) ⇒ Object



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/rack/multipart/parser.rb', line 21

def read(size)
  return if @cursor >= @content_length

  left = @content_length - @cursor

  str = if left < size
          @io.read left
        else
          @io.read size
        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

#rewindObject



44
45
46
# File 'lib/rack/multipart/parser.rb', line 44

def rewind
  @io.rewind
end