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


110
111
112
113
# File 'lib/rack/file.rb', line 110

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


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

def path
  @path
end

#rangeObject (readonly)

Returns the value of attribute range


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

def range
  @range
end

Instance Method Details

#closeObject


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

def close; end

#eachObject


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

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