Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Mime type detection in ruby via file extension or file content
Ruby
branch: master

v0.3.0

latest commit a4b038c6c1
@minad authored
Failed to load latest commit information.
lib v0.3.0
script update shared-mime-info-1.4
test drop 1.8.7
.gitignore fix magic matching for 1.9.3
.travis.yml drop 1.8.7
.yardopts fix readme
Gemfile switch gemfile to https
LICENSE license
README.md Handle .docx, .xlsx, and .pptx with extra magic
Rakefile update rakefile
mimemagic.gemspec update gemspec

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/).

Build Status Code Climate Gittip donate button Flattr this git repo

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...

Extra magic overlay

Microsoft Office 2007+ formats (xlsx, docx, and pptx) are not supported by the mime database at freedesktop.org. These files are all zipped collections of xml files and will be detected as "application/zip". Mimemagic comes with extra magic you can overlay on top of the defaults to correctly detect these file types. Enable it like this:

require 'mimemagic'
require 'mimemagic/overlay'
MimeMagic.by_magic(File.open('test.xlsx'))

You can add your own magic with MimeMagic.add. See lib/mimemagic/overlay.rb.

API

http://rdoc.info/github/minad/mimemagic/frames/file/README.md

Tests

bundle install

rake test

Authors

Daniel Mendler

Something went wrong with that request. Please try again.