Sha256: cf65041be7ac44050c7342d18b3fd58b13370f2ccb1d9ae0ce91e51996cbc986

Contents?: true

Size: 764 Bytes

Versions: 6

Compression:

Stored size: 764 Bytes

Contents

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

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
dragonfly-0.5.6 lib/dragonfly/analysis/file_command_analyser.rb
dragonfly-0.5.5 lib/dragonfly/analysis/file_command_analyser.rb
dragonfly-0.5.4 lib/dragonfly/analysis/file_command_analyser.rb
dragonfly-0.5.3 lib/dragonfly/analysis/file_command_analyser.rb
dragonfly-0.5.2 lib/dragonfly/analysis/file_command_analyser.rb
dragonfly-0.5.1 lib/dragonfly/analysis/file_command_analyser.rb