Class: Grack::FileStreamer

Inherits:
IOStreamer show all
Defined in:
lib/grack/file_streamer.rb

Overview

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

Constant Summary

Constants inherited from IOStreamer

IOStreamer::READ_SIZE

Instance Method Summary collapse

Methods inherited from IOStreamer

#each

Constructor Details

#initialize(path) ⇒ FileStreamer

Creates a new instance of this object.

Parameters:

  • path (Pathname, String)

    a path to a file.



14
15
16
# File 'lib/grack/file_streamer.rb', line 14

def initialize(path)
  @path = Pathname.new(path).expand_path
end

Instance Method Details

#mtimeObject

The last modified time to report for the Rack response.



29
30
31
# File 'lib/grack/file_streamer.rb', line 29

def mtime
  @path.mtime
end

#to_pathString

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.

Returns:

  • (String)

    the path to the file.



23
24
25
# File 'lib/grack/file_streamer.rb', line 23

def to_path
  @path.to_s
end

#with_io {|io| ... } ⇒ Object (private)

Yield Parameters:

  • io (#read)

    the opened file.



37
38
39
# File 'lib/grack/file_streamer.rb', line 37

def with_io(&b)
  @path.open(&b)
end