Class: Rstreamor::File

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(file) ⇒ File

Returns a new instance of File.



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

def initialize(file)
  @file = file
end

Instance Attribute Details

#fileObject (readonly)

Returns the value of attribute file.



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

def file
  @file
end

Instance Method Details

#content_typeObject



17
18
19
# File 'lib/rstreamor/file.rb', line 17

def content_type
  file.content_type
end

#dataObject



9
10
11
12
13
14
15
# File 'lib/rstreamor/file.rb', line 9

def data
  @data ||= if file.respond_to? :data
    file.data
  else
    file.read
  end
end

#sizeObject



21
22
23
24
25
26
27
# File 'lib/rstreamor/file.rb', line 21

def size
  # Because of encoding, the string size might not match the stream size,
  # and that may lead to files being truncated when served (i.e. this happens
  # often for MP3 files, were the last few seconds of files longer than a minute
  # gets trimmed).
  @size ||= data.bytesize
end