class Asperalm::Preview::FileTypes
Constants
- CONVERSION_TYPES
values for
conversion_type
: input format- SUPPORTED_EXTENSIONS
this is a way to add support for extensions that are otherwise not known by node api (mime type)
- SUPPORTED_MIME_TYPES
define how files are processed based on mime type
Public Class Methods
conversion_type(filepath,mimetype,try_local_mime)
click to toggle source
# File lib/asperalm/preview/file_types.rb, line 278 def self.conversion_type(filepath,mimetype,try_local_mime) detected_mime=nil if try_local_mime detected_mime=mime_from_file(filepath) if mimetype.eql?(detected_mime) Log.log.debug("matching mime type per magic number") else # note: detected can be nil Log.log.debug("non matching mime types: node=[#{mimetype}], magic=[#{detected_mime}]") end end # 1- get type from provided mime type result=FileTypes::SUPPORTED_MIME_TYPES[mimetype] unless mimetype.nil? # 2- else, from computed mime type result||=FileTypes::SUPPORTED_MIME_TYPES[detected_mime] unless detected_mime.nil? extension = File.extname(filepath).downcase.gsub(/^\./,'') # 3- else, from local extensions result||=FileTypes::SUPPORTED_EXTENSIONS[extension] return result end
mime_from_file(filepath)
click to toggle source
private_constant :SUPPORTED_MIME_TYPES, :SUPPORTED_EXTENSIONS
# File lib/asperalm/preview/file_types.rb, line 271 def self.mime_from_file(filepath) detected_mime=MimeMagic.by_magic(File.open(filepath)).to_s detected_mime=MimeMagic.by_path(filepath).to_s if detected_mime.empty? detected_mime=nil if detected_mime.empty? return detected_mime end