Code Monkey home page Code Monkey logo

mimemagic's Introduction

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

Warning: If you are using a version of MimeMagic < 0.3.7, or version 0.4.0, you may well be in breach of the GPL due to a GPL licensed dependency that was bundled with this gem. You should update to a version >= 0.3.7 as soon as possible. See mimemagicrb#97 for details.

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

rake test

Authors

Daniel Mendler Jon Wood MimeMagic Contributors

LICENSE

MIT

mimemagic's People

Contributors

aliismayilov avatar boutil avatar bronson avatar crisfole avatar epitron avatar fedot avatar gbh avatar gsar avatar iangreenleaf avatar janko avatar jaredbeck avatar jcoyne avatar jellybob avatar jordan-thoms avatar junaruga avatar mathieumahe avatar minad avatar olleolleolle avatar pocke avatar robcherry avatar rosa avatar scpike avatar viraptor avatar wbond avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

mimemagic's Issues

Add default Macports freedesktop.org.xml install location

(Sorry for opening this here; I would do it over at mimemagicrb/mimemagic but it seems to be locking out new issues right now).

The script attempting to locate the mime types file includes the following default locations:

  possible_paths = [
    (File.expand_path(ENV["FREEDESKTOP_MIME_TYPES_PATH"]) if ENV["FREEDESKTOP_MIME_TYPES_PATH"]),
    "/usr/local/share/mime/packages/freedesktop.org.xml",
    "/opt/homebrew/share/mime/packages/freedesktop.org.xml",
    "/usr/share/mime/packages/freedesktop.org.xml"
  ].compact

Given that this includes the default Homebrew install location, could this also be updated to include the default Macports install location at /opt/local/share/mime/packages/freedesktop.org.xml, given that Macports is still a widely-used package manager?

Derive from pre-GPL license

This code base is currently a fork from tip of master, which includes the GPL changes - since you cannot relicense from GPL to MIT, it should fork prior to relicense.

eg 40dd02b for master or 01f92d86d15d85cfd0f20dabd025dcbd36a8a60f for 0.3 branch

Support loading data at runtime, or by configuring a different location for a preinstalled version

No license lawyering please - unless you're someone able to speak on behalf of freedesktop.org your interpretation of the GPL isn't going to add anything to this conversation

See rails/rails#41750 and mimemagicrb#97 for background.

In order to cause minimal impact on existing users of the mimemagic gem, particularly people using Rails, I'm going to have it load MIME types from a preinstalled version of the Freedesktop MIME types database, rather than bundling one with the gem. This will require having a copy of that either installed with your distribution, or obtained in some other way. The availability of that will be checked at build time.

Issue running rake test

I'm getting:

~/dev/mimemagic$ rake default

File does not exist: mimemagic/path

rake aborted!
Command failed with status (1)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.