Class: FileStreamer

Inherits:
Object
  • Object
show all
Defined in:
lib/file_streamer.rb

Overview

:nodoc:

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(path) ⇒ FileStreamer


4
5
6
# File 'lib/file_streamer.rb', line 4

def initialize(path)
  @to_path = path
end

Instance Attribute Details

#to_pathObject (readonly)

Returns the value of attribute to_path


2
3
4
# File 'lib/file_streamer.rb', line 2

def to_path
  @to_path
end

Instance Method Details

#eachObject

Stream the file's contents if Rack::Sendfile isn't present.


9
10
11
12
13
14
15
# File 'lib/file_streamer.rb', line 9

def each
  File.open(to_path, 'rb') do |file|
    while chunk = file.read(16384)
      yield chunk
    end
  end
end