Class: Sgfa::Web::FileBody
- Inherits:
-
Object
- Object
- Sgfa::Web::FileBody
- 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
-
#close ⇒ Object
close.
-
#each ⇒ Object
provide the body of the file.
-
#initialize(file) ⇒ FileBody
constructor
initialize new file response.
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
#close ⇒ Object
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 |
#each ⇒ Object
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 |