Class: Dragonfly::Analysis::FileCommandAnalyser

Inherits:
Object
  • Object
show all
Defined in:
lib/dragonfly/analysis/file_command_analyser.rb

Instance Method Summary collapse

Instance Method Details

#mime_type(temp_object) ⇒ Object



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/dragonfly/analysis/file_command_analyser.rb', line 12

def mime_type(temp_object)
  content_type = if use_filesystem
    `#{file_command} -b --mime '#{temp_object.path}'`
  else
    IO.popen("#{file_command} -b --mime -", 'r+') do |io|
      if num_bytes_to_check
        io.write temp_object.data[0, num_bytes_to_check]
      else
        io.write temp_object.data 
      end
      io.close_write
      io.read
    end
  end.split(';').first
  content_type.strip if content_type
end