Sha256: 91148071acf2c1807135c98478c4f16f5ccd243597456c850706d571135e72ee

Contents?: true

Size: 815 Bytes

Versions: 17

Compression:

Stored size: 815 Bytes

Contents

module Dragonfly
  module Analysis
    
    class FileCommandAnalyser
      
      include Configurable
      
      configurable_attr :file_command, "file"
      configurable_attr :use_filesystem, false
      configurable_attr :num_bytes_to_check, 255
      
      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
      
    end
    
  end
end

Version data entries

17 entries across 17 versions & 3 rubygems

Version Path
dragonfly-0.8.6 lib/dragonfly/analysis/file_command_analyser.rb
dragonfly-0.8.5 lib/dragonfly/analysis/file_command_analyser.rb
dragonfly-0.8.4 lib/dragonfly/analysis/file_command_analyser.rb
oahu-dragonfly-0.8.2 lib/dragonfly/analysis/file_command_analyser.rb
fog-dragonfly-0.8.2 lib/dragonfly/analysis/file_command_analyser.rb
dragonfly-0.8.2 lib/dragonfly/analysis/file_command_analyser.rb
fog-dragonfly-0.8.1 lib/dragonfly/analysis/file_command_analyser.rb
dragonfly-0.8.1 lib/dragonfly/analysis/file_command_analyser.rb
dragonfly-0.8.0 lib/dragonfly/analysis/file_command_analyser.rb
dragonfly-0.7.7 lib/dragonfly/analysis/file_command_analyser.rb
dragonfly-0.7.6 lib/dragonfly/analysis/file_command_analyser.rb
dragonfly-0.7.5 lib/dragonfly/analysis/file_command_analyser.rb
dragonfly-0.7.4 lib/dragonfly/analysis/file_command_analyser.rb
dragonfly-0.7.3 lib/dragonfly/analysis/file_command_analyser.rb
dragonfly-0.7.2 lib/dragonfly/analysis/file_command_analyser.rb
dragonfly-0.7.1 lib/dragonfly/analysis/file_command_analyser.rb
dragonfly-0.7.0 lib/dragonfly/analysis/file_command_analyser.rb