Go to file
Jon Wood af5a9b1c5b Update the changelog 2021-03-26 17:37:17 +00:00
ext/mimemagic Allow the Rakefile to be used in isolation for test runs 2021-03-26 17:10:05 +00:00
lib Release 0.4.2 2021-03-26 16:59:41 +00:00
test Handle the \c escape character in Tex detection (badly). 2021-03-25 22:00:27 +00:00
.gitignore fixes gem development environment 2021-03-26 11:45:43 -04:00
.travis.yml Use frozen string literal feature when running tests 2020-07-14 10:52:17 +02:00
.yardopts fixes gem development environment 2021-03-26 11:45:43 -04:00
CHANGELOG.md Update the changelog 2021-03-26 17:37:17 +00:00
Gemfile fixes gem development environment 2021-03-26 11:45:43 -04:00
LICENSE Remove freedesktop.org.xml, and re-re-license back to MIT 2021-03-24 17:16:49 +00:00
README.md fixes gem development environment 2021-03-26 11:45:43 -04:00
Rakefile fixes gem development environment 2021-03-26 11:45:43 -04:00
mimemagic.gemspec Update gemspec to follow using nokogiri 2021-03-26 14:50:45 +09:00

README.md

MimeMagic is a library to detect the mime type of a file by extension or by content. It uses the mime database provided by freedesktop.org (see http://freedesktop.org/wiki/Software/shared-mime-info/).

Gem Version

Dependencies

You will require a copy of the Freedesktop.org shared-mime-info database to be available. If you're on Linux, it's probably available via your package manager, and will probably be in the location it's being looked for when the gem is installed.

macOS users can install the database via Homebrew with brew install shared-mime-info.

Should you be unable to use a package manager you can obtain a copy of the needed file by extracting it from the Debian package. This process will also work on a Windows machine.

  1. Download the package from https://packages.debian.org/sid/amd64/shared-mime-info/download
  2. Ensure the command line version of 7-Zip is installed
  3. 7z x -so shared-mime-info_2.0-1_amd64.deb data.tar | 7z e -sidata.tar "./usr/share/mime/packages/freedesktop.org.xml"

Place the file freedesktop.org.xml in an appropriate location, and then set the environment variable FREEDESKTOP_MIME_TYPES_PATH to that path. Once that has been done the gem should install successfully. Please note that the gem will depend upon the file remaining in that location at run time.

Usage

require 'mimemagic'
MimeMagic.by_extension('html').text?
MimeMagic.by_extension('.html').child_of? 'text/plain'
MimeMagic.by_path('filename.txt')
MimeMagic.by_magic(File.open('test.html'))
# etc...

You can add your own magic with MimeMagic.add.

API

http://www.rubydoc.info/github/mimemagicrb/mimemagic

Tests

$ bundle install

$ bundle exec rake test

Authors

LICENSE

{file:LICENSE MIT}