Class: ImageVise::FileResponse

Inherits:
Object
  • Object
show all
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

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

#closeObject



19
20
21
# File 'lib/image_vise/file_response.rb', line 19

def close
  ImageVise.close_and_unlink(@file)
end

#eachObject



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