Class: Deas::Runner::SendFileBody
- Inherits:
-
Object
- Object
- Deas::Runner::SendFileBody
- Defined in:
- lib/deas/runner.rb
Constant Summary collapse
- CHUNK_SIZE =
this class borrows from the body range handling in Rack::File.
(8*1024).freeze
Instance Attribute Summary collapse
-
#content_range ⇒ Object
readonly
Returns the value of attribute content_range.
-
#path_name ⇒ Object
readonly
Returns the value of attribute path_name.
-
#size ⇒ Object
readonly
Returns the value of attribute size.
Instance Method Summary collapse
- #==(other_body) ⇒ Object
- #each ⇒ Object
-
#initialize(env, path_name) ⇒ SendFileBody
constructor
A new instance of SendFileBody.
- #inspect ⇒ Object
- #partial? ⇒ Boolean
- #range_begin ⇒ Object
- #range_end ⇒ Object
Constructor Details
#initialize(env, path_name) ⇒ SendFileBody
Returns a new instance of SendFileBody.
232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 |
# File 'lib/deas/runner.rb', line 232 def initialize(env, path_name) @path_name = path_name file_size = @path_name.size? || Rack::Utils.bytesize(path_name.read) ranges = byte_ranges(env, file_size) if ranges.nil? || ranges.empty? || ranges.length > 1 # No ranges or multiple ranges are not supported @range = 0..file_size-1 @content_range = nil else # single range @range = ranges[0] @content_range = "bytes #{@range.begin}-#{@range.end}/#{file_size}" end @size = self.range_end - self.range_begin + 1 end |
Instance Attribute Details
#content_range ⇒ Object (readonly)
Returns the value of attribute content_range.
230 231 232 |
# File 'lib/deas/runner.rb', line 230 def content_range @content_range end |
#path_name ⇒ Object (readonly)
Returns the value of attribute path_name.
230 231 232 |
# File 'lib/deas/runner.rb', line 230 def path_name @path_name end |
#size ⇒ Object (readonly)
Returns the value of attribute size.
230 231 232 |
# File 'lib/deas/runner.rb', line 230 def size @size end |
Instance Method Details
#==(other_body) ⇒ Object
277 278 279 280 281 |
# File 'lib/deas/runner.rb', line 277 def ==(other_body) self.path_name.to_s == other_body.path_name.to_s && self.range_begin == other_body.range_begin && self.range_end == other_body.range_end end |
#each ⇒ Object
257 258 259 260 261 262 263 264 265 266 267 268 269 |
# File 'lib/deas/runner.rb', line 257 def each @path_name.open("rb") do |io| io.seek(@range.begin) remaining_len = self.size while remaining_len > 0 part = io.read([CHUNK_SIZE, remaining_len].min) break if part.nil? remaining_len -= part.length yield part end end end |
#inspect ⇒ Object
271 272 273 274 275 |
# File 'lib/deas/runner.rb', line 271 def inspect "#<#{self.class}:#{'0x0%x' % (self.object_id << 1)} " \ "path=#{self.path_name} " \ "range_begin=#{self.range_begin} range_end=#{self.range_end}>" end |
#partial? ⇒ Boolean
250 251 252 |
# File 'lib/deas/runner.rb', line 250 def partial? !@content_range.nil? end |
#range_begin ⇒ Object
254 |
# File 'lib/deas/runner.rb', line 254 def range_begin; @range.begin; end |
#range_end ⇒ Object
255 |
# File 'lib/deas/runner.rb', line 255 def range_end; @range.end; end |