Class: Rainbows::Sendfile::Body

Inherits:
Struct
  • Object
show all
Defined in:
lib/rainbows/sendfile.rb

Overview

Body wrapper, this allows us to fall back gracefully to each in case a given concurrency model does not optimize to_path calls.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#to_pathObject

Returns the value of attribute to_path

Returns:

  • (Object)

    the current value of to_path



54
55
56
# File 'lib/rainbows/sendfile.rb', line 54

def to_path
  @to_path
end

Class Method Details

.new(path, headers) ⇒ Object



55
56
57
58
59
60
61
# File 'lib/rainbows/sendfile.rb', line 55

def self.new(path, headers)
  unless headers['Content-Length'.freeze]
    stat = File.stat(path)
    headers['Content-Length'.freeze] = stat.size.to_s if stat.file?
  end
  super(path)
end

Instance Method Details

#eachObject

fallback in case our to_path doesn’t get handled for whatever reason



64
65
66
67
68
69
# File 'lib/rainbows/sendfile.rb', line 64

def each
  buf = ''
  File.open(to_path) do |fp|
    yield buf while fp.read(0x4000, buf)
  end
end