# class Rack::Files::BaseIterator

### Attributes

options[R]
path[R]
ranges[R]

### Public Class Methods

new(path, ranges, options) click to toggle source

    # File lib/rack/files.rb, line 126
    def initialize(path, ranges, options)
      @path = path
      @ranges = ranges
      @options = options
    end

### Public Instance Methods

bytesize() click to toggle source

    # File lib/rack/files.rb, line 146
    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() click to toggle source

    # File lib/rack/files.rb, line 155
    def close; end

each() { |multipart_heading(range)| ... } click to toggle source

    # File lib/rack/files.rb, line 132
    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

### Private Instance Methods

each_range_part(file, range) { |part| ... } click to toggle source

    # File lib/rack/files.rb, line 173
    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?() click to toggle source

    # File lib/rack/files.rb, line 159
    def multipart?
      ranges.size > 1
    end

multipart_heading(range) click to toggle source

    # File lib/rack/files.rb, line 163
          def multipart_heading(range)
    <<-EOF
    \r
    --#{MULTIPART_BOUNDARY}\r
    Content-Type: #{options[:mime_type]}\r
    Content-Range: bytes #{range.begin}-#{range.end}/#{options[:size]}\r
    \r
    EOF
          end