class Grack::FileStreamer

A Rack body implementation that streams a given file in chunks for a Rack response.

Public Class Methods

new(path) click to toggle source

Creates a new instance of this object.

@param [Pathname, String] path a path to a file.

# File lib/grack/file_streamer.rb, line 14
def initialize(path)
  @path = Pathname.new(path).expand_path
end

Public Instance Methods

mtime() click to toggle source

The last modified time to report for the Rack response.

# File lib/grack/file_streamer.rb, line 29
def mtime
  @path.mtime
end
to_path() click to toggle source

In order to support X-Sendfile when available, this method returns the path to the file the web server would use to provide the content.

@return [String] the path to the file.

# File lib/grack/file_streamer.rb, line 23
def to_path
  @path.to_s
end

Private Instance Methods

with_io(&b) click to toggle source

@yieldparam [#read] io the opened file.

# File lib/grack/file_streamer.rb, line 37
def with_io(&b)
  @path.open(&b)
end