Class: ImageVise::FileResponse
- Inherits:
-
Object
- Object
- ImageVise::FileResponse
- Defined in:
- lib/image_vise/file_response.rb
Overview
Wrappers a given Tempfile for a Rack response. Will close and unlink the Tempfile it contains.
Constant Summary collapse
- ONE_CHUNK_BYTES =
1024 * 1024 * 2
Instance Method Summary collapse
- #close ⇒ Object
- #each ⇒ Object
-
#initialize(file) ⇒ FileResponse
constructor
A new instance of FileResponse.
Constructor Details
#initialize(file) ⇒ FileResponse
Returns a new instance of FileResponse.
5 6 7 |
# File 'lib/image_vise/file_response.rb', line 5 def initialize(file) @file = file end |
Instance Method Details
#close ⇒ Object
19 20 21 |
# File 'lib/image_vise/file_response.rb', line 19 def close ImageVise.close_and_unlink(@file) end |
#each ⇒ Object
9 10 11 12 13 14 15 16 17 |
# File 'lib/image_vise/file_response.rb', line 9 def each @file.flush # Make sure all the writes have been synchronized # We can easily open another file descriptor File.open(@file.path, 'rb') do |my_file_descriptor| while data = my_file_descriptor.read(ONE_CHUNK_BYTES) yield(data) end end end |