Class: Rstreamor::Request

Inherits:
Object
  • Object
show all
Defined in:
lib/rstreamor/request.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(request, file) ⇒ Request

Returns a new instance of Request.



5
6
7
8
# File 'lib/rstreamor/request.rb', line 5

def initialize(request, file)
  @request = request
  @file = file
end

Instance Attribute Details

#fileObject (readonly)

Returns the value of attribute file.



3
4
5
# File 'lib/rstreamor/request.rb', line 3

def file
  @file
end

#requestObject (readonly)

Returns the value of attribute request.



3
4
5
# File 'lib/rstreamor/request.rb', line 3

def request
  @request
end

Instance Method Details

#file_content_typeObject



26
27
28
# File 'lib/rstreamor/request.rb', line 26

def file_content_type
  file.content_type
end

#file_sizeObject



38
39
40
# File 'lib/rstreamor/request.rb', line 38

def file_size
  file.size
end

#lower_boundObject



18
19
20
# File 'lib/rstreamor/request.rb', line 18

def lower_bound
  ranges[0] ? ranges[0].to_i : 0
end

#range_header?Boolean

Returns:

  • (Boolean)


22
23
24
# File 'lib/rstreamor/request.rb', line 22

def range_header?
  request.headers['HTTP_RANGE'].present?
end

#rangesObject



10
11
12
# File 'lib/rstreamor/request.rb', line 10

def ranges
  request.headers['HTTP_RANGE'].gsub('bytes=', '').split('-') if request.headers['HTTP_RANGE']
end

#slice_fileObject



30
31
32
33
34
35
36
# File 'lib/rstreamor/request.rb', line 30

def slice_file
  if request.headers['HTTP_RANGE'].present?
    file.data.byteslice(lower_bound..upper_bound)
  else
    file.data
  end
end

#upper_boundObject



14
15
16
# File 'lib/rstreamor/request.rb', line 14

def upper_bound
  ranges[1] ? ranges[1].to_i : (file.size - 1)
end