Commit 641561de by Jon Wood

Support for loading a freedesktop.org.xml that exists locally

Currently looks at the value of `FREEDESKTOP_MIME_TYPES_PATH` and
in `/usr/share/mime/packages/freedesktop.org.xml`, which is the
path you would expect to find that file at on a typical Linux
system.
parent f95088a0
......@@ -5,7 +5,7 @@ require 'mimemagic/version'
require 'stringio'
MimeMagic.parse_database("script/freedesktop.org.xml")
MimeMagic.parse_database
# Mime type detection
class MimeMagic
......
......@@ -55,8 +55,27 @@ class MimeMagic
}.compact
end
def self.parse_database(source_path)
file = File.new(source_path)
def self.locate_mime_database
# User provided path.
return ENV["FREEDESKTOP_MIME_TYPES_PATH"] unless ENV["FREEDESKTOP_MIME_TYPES_PATH"].nil?
# Default path on Linux installs for the MIME types database.
return "/usr/share/mime/packages/freedesktop.org.xml" if File.exist?("/usr/share/mime/packages/freedesktop.org.xml")
nil
end
def self.open_mime_database
path = locate_mime_database
return File.open(path) unless path.nil?
# Couldn't find it locally, pull it from the Internet.
raise "MIME types database could not be found. Pulling from the internet is currently unsupported."
end
def self.parse_database
file = open_mime_database
doc = Nokogiri::XML(file)
extensions = {}
types = {}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment