Class: Rack::Files::BaseIterator

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

Direct Known Subclasses

Iterator

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(path, ranges, options) ⇒ BaseIterator

Returns a new instance of BaseIterator.


132
133
134
135
136
# File 'lib/rack/files.rb', line 132

def initialize(path, ranges, options)
  @path = path
  @ranges = ranges
  @options = options
end

Instance Attribute Details

#optionsObject (readonly)

Returns the value of attribute options.


130
131
132
# File 'lib/rack/files.rb', line 130

def options
  @options
end

#pathObject (readonly)

Returns the value of attribute path.


130
131
132
# File 'lib/rack/files.rb', line 130

def path
  @path
end

#rangesObject (readonly)

Returns the value of attribute ranges.


130
131
132
# File 'lib/rack/files.rb', line 130

def ranges
  @ranges
end

Instance Method Details

#bytesizeObject


152
153
154
155
156
157
158
159
# File 'lib/rack/files.rb', line 152

def bytesize
  size = ranges.inject(0) do |sum, range|
    sum += multipart_heading(range).bytesize if multipart?
    sum += range.size
  end
  size += "\r\n--#{MULTIPART_BOUNDARY}--\r\n".bytesize if multipart?
  size
end

#closeObject


161
# File 'lib/rack/files.rb', line 161

def close; end

#eachObject


138
139
140
141
142
143
144
145
146
147
148
149
150
# File 'lib/rack/files.rb', line 138

def each
  ::File.open(path, "rb") do |file|
    ranges.each do |range|
      yield multipart_heading(range) if multipart?

      each_range_part(file, range) do |part|
        yield part
      end
    end

    yield "\r\n--#{MULTIPART_BOUNDARY}--\r\n" if multipart?
  end
end