Class: Rack::File::Iterator

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(path, range) ⇒ Iterator

Returns a new instance of Iterator


108
109
110
111
# File 'lib/rack/file.rb', line 108

def initialize path, range
  @path  = path
  @range = range
end

Instance Attribute Details

#pathObject (readonly) Also known as: to_path

Returns the value of attribute path


105
106
107
# File 'lib/rack/file.rb', line 105

def path
  @path
end

#rangeObject (readonly)

Returns the value of attribute range


105
106
107
# File 'lib/rack/file.rb', line 105

def range
  @range
end

Instance Method Details

#closeObject


127
# File 'lib/rack/file.rb', line 127

def close; end

#eachObject


113
114
115
116
117
118
119
120
121
122
123
124
125
# File 'lib/rack/file.rb', line 113

def each
  ::File.open(path, "rb") do |file|
    file.seek(range.begin)
    remaining_len = range.end-range.begin+1
    while remaining_len > 0
      part = file.read([8192, remaining_len].min)
      break unless part
      remaining_len -= part.length

      yield part
    end
  end
end