Class: Sgfa::Web::FileBody

Inherits:
Object
  • Object
show all
Defined in:
lib/sgfa/web/base.rb

Overview

Provide the contents of a file in chunks. Designed to work with Rack response.

Constant Summary collapse

ReadChunk =

Size of the chunks provided by each

256 * 1024

Instance Method Summary collapse

Constructor Details

#initialize(file) ⇒ FileBody

initialize new file response



207
208
209
# File 'lib/sgfa/web/base.rb', line 207

def initialize(file)
  @file = file
end

Instance Method Details

#closeObject

close



220
221
222
223
224
225
226
# File 'lib/sgfa/web/base.rb', line 220

def close
  if @file.respond_to?(:close!)
    @file.close!
  else
    @file.close
  end
end

#eachObject

provide the body of the file



212
213
214
215
216
217
# File 'lib/sgfa/web/base.rb', line 212

def each
  str = ''
  while @file.read(ReadChunk, str)
    yield str
  end
end