Class: Rack::Files::BaseIterator
| Relationships & Source Files | |
| Extension / Inclusion / Inheritance Descendants | |
| Subclasses: | |
| Inherits: | Object | 
| Defined in: | lib/rack/files.rb | 
Class Method Summary
- .new(path, ranges, options) ⇒ BaseIterator constructor
Instance Attribute Summary
- #options readonly
- #path (also: #to_path) readonly
- #ranges readonly
- #multipart? ⇒ Boolean readonly private
Instance Method Summary
- #bytesize
- #close
- #each
- #each_range_part(file, range) private
- #multipart_heading(range) private
Constructor Details
    .new(path, ranges, options)  ⇒ BaseIterator 
  
Instance Attribute Details
    #multipart?  ⇒ Boolean  (readonly, private)
  
  [ GitHub ]
# File 'lib/rack/files.rb', line 165
def multipart? ranges.size > 1 end
#options (readonly)
[ GitHub ]#path (readonly) Also known as: #to_path
[ GitHub ]# File 'lib/rack/files.rb', line 130
attr_reader :path, :ranges, :
#ranges (readonly)
[ GitHub ]# File 'lib/rack/files.rb', line 130
attr_reader :path, :ranges, :
Instance Method Details
#bytesize
[ GitHub ]# 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
#close
[ GitHub ]# File 'lib/rack/files.rb', line 161
def close; end
#each
[ GitHub ]# 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
#each_range_part(file, range) (private)
[ GitHub ]# File 'lib/rack/files.rb', line 179
def each_range_part(file, range) 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
#multipart_heading(range) (private)
[ GitHub ]# File 'lib/rack/files.rb', line 169
def multipart_heading(range) <<-EOF \r --#{MULTIPART_BOUNDARY}\r content-type: #{[:mime_type]}\r content-range: bytes #{range.begin}-#{range.end}/#{[:size]}\r \r EOF end