Class: ActionDispatch::Response::FileBody
- Inherits:
-
Object
- Object
- ActionDispatch::Response::FileBody
- Defined in:
- lib/action_dispatch/http/response.rb
Overview
Avoid having to pass an open file handle as the response body. Rack::Sendfile will usually intercept the response and uses the path directly, so there is no reason to open the file.
Instance Attribute Summary collapse
-
#to_path ⇒ Object
readonly
:nodoc:.
Instance Method Summary collapse
- #body ⇒ Object
-
#each ⇒ Object
Stream the file's contents if Rack::Sendfile isn't present.
-
#initialize(path) ⇒ FileBody
constructor
A new instance of FileBody.
Constructor Details
#initialize(path) ⇒ FileBody
Returns a new instance of FileBody.
329 330 331 |
# File 'lib/action_dispatch/http/response.rb', line 329 def initialize(path) @to_path = path end |
Instance Attribute Details
#to_path ⇒ Object (readonly)
:nodoc:
327 328 329 |
# File 'lib/action_dispatch/http/response.rb', line 327 def to_path @to_path end |
Instance Method Details
#body ⇒ Object
333 334 335 |
# File 'lib/action_dispatch/http/response.rb', line 333 def body File.binread(to_path) end |
#each ⇒ Object
Stream the file's contents if Rack::Sendfile isn't present.
338 339 340 341 342 343 344 |
# File 'lib/action_dispatch/http/response.rb', line 338 def each File.open(to_path, "rb") do |file| while chunk = file.read(16384) yield chunk end end end |