Class: IntervalResponse::LazyFile

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

Overview

Used so that if a sequence of files gets served out, the files should not be kept open during the entire response output - as this might exhaust the file descriptor table

Instance Method Summary collapse

Constructor Details

#initialize(filesystem_path) ⇒ LazyFile

Returns a new instance of LazyFile.



6
7
8
# File 'lib/interval_response/lazy_file.rb', line 6

def initialize(filesystem_path)
  @fs_path = filesystem_path
end

Instance Method Details

#sizeObject



10
11
12
# File 'lib/interval_response/lazy_file.rb', line 10

def size
  File.size(@fs_path)
end

#withObject



14
15
16
17
18
# File 'lib/interval_response/lazy_file.rb', line 14

def with
  File.open(@fs_path, 'rb') do |file_handle|
    yield file_handle
  end
end