Commit 749a7e59 by Daniel Mendler

initial commit

parents
lib/mimemagic.rb
lib/mimemagic_tables.rb
test/test_mimemagic.rb
script/freedesktop.org.xml
script/generate-mime.rb
Rakefile
README
MimeMagic is a library to detect the mime type of a file by extension or by content.
Usage
=====
require 'mimemagic'
MimeMagic.by_extension('html').text?
MimeMagic.by_extension('.html').child_of? 'text/plain'
MimeMagic.by_magic(File.open('test.html'))
etc...
Authors
=======
Daniel Mendler
\ No newline at end of file
require 'hoe'
$:.unshift 'lib'
require 'mimemagic'
Hoe.new 'mimemagic', MimeMagic::VERSION do |mimemagic|
mimemagic.developer 'Daniel Mendler', 'mail@daniel-mendler.de'
mimemagic.summary = 'Mime detection by extension or content'
end
require 'mimemagic_tables'
require 'stringio'
# Mime type detection
class MimeMagic
VERSION = '0.1'
attr_reader :type, :mediatype, :subtype
# Mime type by type string
def initialize(type)
@type = type
@mediatype = @type.split('/')[0]
@subtype = @type.split('/')[1]
end
# Add custom mime type. You have to
# specify the type, a string list of file extensions,
# a string list of parent mime types and an optional
# detector block for magic detection.
def self.add(type, extensions, parents, *magics)
TYPES[type] = [extensions, parents, block_given? ? proc(&block) : nil]
extensions.each do |ext|
EXTENSIONS[ext] = type
end
MAGIC.unshift [type, magics] if magics
end
# Returns true if type is a text format
def text?
child_of? 'text/plain'
end
# Returns true if type is child of parent type
def child_of?(parent)
child?(type, parent)
end
# Get string list of file extensions
def extensions
TYPES.key?(type) ? TYPES[type][0] : []
end
# Lookup mime type by file extension
def self.by_extension(ext)
ext = ext.downcase
mime = EXTENSIONS[ext] || (ext[0..0] == '.' && EXTENSIONS[ext[1..-1]])
mime ? new(mime) : nil
end
# Lookup mime type by magic content analysis
# That could be slow
def self.by_magic(content)
io = content.respond_to?(:seek) ? content : StringIO.new(content.to_s, 'rb')
mime = MAGIC.find {|type, matches| magic_match(io, matches) }
mime ? new(mime[0]) : nil
end
# Return type as string
def to_s
type
end
# Allow comparison with string
def ==(x)
type == x.to_s
end
private
def child?(child, parent)
return true if child == parent
TYPES.key?(child) ? TYPES[child][1].any? {|p| child?(p, parent) } : false
end
def self.magic_match(io, matches)
matches.any? do |offset, value, children|
if Range === offset
io.seek(offset.begin)
match = io.read(offset.end - offset.begin + value.length).include?(value)
else
io.seek(offset)
match = value == io.read(value.length)
end
match && (!children || magic_match(io, children))
end
rescue
false
end
end
# Generated from /usr/share/mime/packages/freedesktop.org.xml
class MimeMagic
private
EXTENSIONS = {
'123' => 'application/vnd.lotus-1-2-3',
'3ds' => 'image/x-3ds',
'3g2' => 'video/3gpp',
'3ga' => 'video/3gpp',
'3gp' => 'video/3gpp',
'3gpp' => 'video/3gpp',
'602' => 'application/x-t602',
'669' => 'audio/x-mod',
'7z' => 'application/x-7z-compressed',
'a' => 'application/x-archive',
'aac' => 'audio/mp4',
'abw' => 'application/x-abiword',
'abw.crashed' => 'application/x-abiword',
'abw.gz' => 'application/x-abiword',
'ac3' => 'audio/ac3',
'ace' => 'application/x-ace',
'adb' => 'text/x-adasrc',
'ads' => 'text/x-adasrc',
'afm' => 'application/x-font-afm',
'ag' => 'image/x-applix-graphics',
'ai' => 'application/illustrator',
'aif' => 'audio/x-aiff',
'aifc' => 'audio/x-aiff',
'aiff' => 'audio/x-aiff',
'al' => 'application/x-perl',
'alz' => 'application/x-alz',
'amr' => 'audio/AMR',
'ani' => 'application/x-navi-animation',
'ape' => 'audio/x-ape',
'arj' => 'application/x-arj',
'arw' => 'image/x-sony-arw',
'as' => 'application/x-applix-spreadsheet',
'asc' => 'application/pgp-encrypted',
'asf' => 'video/x-ms-asf',
'asp' => 'application/x-asp',
'ass' => 'text/x-ssa',
'asx' => 'audio/x-ms-asx',
'atom' => 'application/atom+xml',
'au' => 'audio/basic',
'avi' => 'video/x-msvideo',
'aw' => 'application/x-applix-word',
'awb' => 'audio/AMR-WB',
'awk' => 'application/x-awk',
'bak' => 'application/x-trash',
'bcpio' => 'application/x-bcpio',
'bdf' => 'application/x-font-bdf',
'bib' => 'text/x-bibtex',
'bin' => 'application/octet-stream',
'blend' => 'application/x-blender',
'blender' => 'application/x-blender',
'bmp' => 'image/bmp',
'bz' => 'application/x-bzip',
'bz2' => 'application/x-bzip',
'c' => 'text/x-c++src',
'c++' => 'text/x-c++src',
'cbr' => 'application/x-cbr',
'cbz' => 'application/x-cbz',
'cc' => 'text/x-c++src',
'cdf' => 'application/x-netcdf',
'cdr' => 'application/vnd.corel-draw',
'cer' => 'application/x-x509-ca-cert',
'cert' => 'application/x-x509-ca-cert',
'cgm' => 'image/cgm',
'chm' => 'application/x-chm',
'chrt' => 'application/x-kchart',
'class' => 'application/x-java',
'cls' => 'text/x-tex',
'cmake' => 'text/x-cmake',
'cpio' => 'application/x-cpio',
'cpio.gz' => 'application/x-cpio-compressed',
'cpp' => 'text/x-c++src',
'cr2' => 'image/x-canon-cr2',
'crt' => 'application/x-x509-ca-cert',
'crw' => 'image/x-canon-crw',
'cs' => 'text/x-csharp',
'csh' => 'application/x-csh',
'css' => 'text/css',
'cssl' => 'text/css',
'csv' => 'text/csv',
'cue' => 'application/x-cue',
'cur' => 'image/x-win-bitmap',
'cxx' => 'text/x-c++src',
'd' => 'text/x-dsrc',
'dar' => 'application/x-dar',
'dbf' => 'application/x-dbf',
'dc' => 'application/x-dc-rom',
'dcl' => 'text/x-dcl',
'dcm' => 'application/dicom',
'dcr' => 'image/x-kodak-dcr',
'dds' => 'image/x-dds',
'deb' => 'application/x-deb',
'der' => 'application/x-x509-ca-cert',
'desktop' => 'application/x-desktop',
'dia' => 'application/x-dia-diagram',
'diff' => 'text/x-patch',
'divx' => 'video/x-msvideo',
'djv' => 'image/vnd.djvu',
'djvu' => 'image/vnd.djvu',
'dng' => 'image/x-adobe-dng',
'doc' => 'application/msword',
'docbook' => 'application/docbook+xml',
'dot' => 'application/msword-template',
'dsl' => 'text/x-dsl',
'dtd' => 'application/xml-dtd',
'dtx' => 'text/x-tex',
'dv' => 'video/dv',
'dvi' => 'application/x-dvi',
'dvi.bz2' => 'application/x-bzdvi',
'dvi.gz' => 'application/x-gzdvi',
'dwg' => 'image/vnd.dwg',
'dxf' => 'image/vnd.dxf',
'e' => 'text/x-eiffel',
'egon' => 'application/x-egon',
'eif' => 'text/x-eiffel',
'el' => 'text/x-emacs-lisp',
'emf' => 'image/x-emf',
'emp' => 'application/vnd.emusic-emusic_package',
'ent' => 'application/xml-external-parsed-entity',
'eps' => 'image/x-eps',
'eps.bz2' => 'image/x-bzeps',
'eps.gz' => 'image/x-gzeps',
'epsf' => 'image/x-eps',
'epsf.bz2' => 'image/x-bzeps',
'epsf.gz' => 'image/x-gzeps',
'epsi' => 'image/x-eps',
'epsi.bz2' => 'image/x-bzeps',
'epsi.gz' => 'image/x-gzeps',
'epub' => 'application/epub+zip',
'erl' => 'text/x-erlang',
'es' => 'application/ecmascript',
'etheme' => 'application/x-e-theme',
'etx' => 'text/x-setext',
'exe' => 'application/x-ms-dos-executable',
'exr' => 'image/x-exr',
'ez' => 'application/andrew-inset',
'f' => 'text/x-fortran',
'f90' => 'text/x-fortran',
'f95' => 'text/x-fortran',
'fig' => 'image/x-xfig',
'fits' => 'image/x-fits',
'fl' => 'application/x-fluid',
'flac' => 'audio/x-flac',
'flc' => 'video/x-flic',
'fli' => 'video/x-flic',
'flv' => 'video/x-flv',
'flw' => 'application/x-kivio',
'fo' => 'text/x-xslfo',
'for' => 'text/x-fortran',
'g3' => 'image/fax-g3',
'gb' => 'application/x-gameboy-rom',
'gba' => 'application/x-gba-rom',
'gcrd' => 'text/directory',
'ged' => 'application/x-gedcom',
'gedcom' => 'application/x-gedcom',
'gen' => 'application/x-genesis-rom',
'gf' => 'application/x-tex-gf',
'gg' => 'application/x-sms-rom',
'gif' => 'image/gif',
'glade' => 'application/x-glade',
'gmo' => 'application/x-gettext-translation',
'gnc' => 'application/x-gnucash',
'gnd' => 'application/gnunet-directory',
'gnucash' => 'application/x-gnucash',
'gnumeric' => 'application/x-gnumeric',
'gnuplot' => 'application/x-gnuplot',
'gp' => 'application/x-gnuplot',
'gpg' => 'application/pgp-encrypted',
'gplt' => 'application/x-gnuplot',
'gra' => 'application/x-graphite',
'gsf' => 'application/x-font-type1',
'gtar' => 'application/x-tar',
'gvp' => 'text/x-google-video-pointer',
'gz' => 'application/x-gzip',
'h' => 'text/x-chdr',
'h++' => 'text/x-c++hdr',
'hdf' => 'application/x-hdf',
'hh' => 'text/x-c++hdr',
'hp' => 'text/x-c++hdr',
'hpgl' => 'application/vnd.hp-hpgl',
'hpp' => 'text/x-c++hdr',
'hs' => 'text/x-haskell',
'htm' => 'text/html',
'html' => 'text/html',
'hwp' => 'application/x-hwp',
'hwt' => 'application/x-hwt',
'hxx' => 'text/x-c++hdr',
'ica' => 'application/x-ica',
'icb' => 'image/x-tga',
'icns' => 'image/x-icns',
'ico' => 'image/x-ico',
'ics' => 'text/calendar',
'idl' => 'text/x-idl',
'ief' => 'image/ief',
'iff' => 'image/x-iff',
'ilbm' => 'image/x-ilbm',
'ime' => 'text/x-iMelody',
'imy' => 'text/x-iMelody',
'ins' => 'text/x-tex',
'iptables' => 'text/x-iptables',
'iso' => 'application/x-cd-image',
'iso9660' => 'application/x-cd-image',
'it' => 'audio/x-it',
'j2k' => 'image/jp2',
'jad' => 'text/vnd.sun.j2me.app-descriptor',
'jar' => 'application/x-java-archive',
'java' => 'text/x-java',
'jng' => 'image/x-jng',
'jnlp' => 'application/x-java-jnlp-file',
'jp2' => 'image/jp2',
'jpc' => 'image/jp2',
'jpe' => 'image/jpeg',
'jpeg' => 'image/jpeg',
'jpf' => 'image/jp2',
'jpg' => 'image/jpeg',
'jpr' => 'application/x-jbuilder-project',
'jpx' => 'application/x-jbuilder-project',
'js' => 'application/javascript',
'k25' => 'image/x-kodak-k25',
'kar' => 'audio/midi',
'karbon' => 'application/x-karbon',
'kdc' => 'image/x-kodak-kdc',
'kdelnk' => 'application/x-desktop',
'kfo' => 'application/x-kformula',
'kil' => 'application/x-killustrator',
'kino' => 'application/smil',
'kon' => 'application/x-kontour',
'kpm' => 'application/x-kpovmodeler',
'kpr' => 'application/x-kpresenter',
'kpt' => 'application/x-kpresenter',
'kra' => 'application/x-krita',
'ksp' => 'application/x-kspread',
'kud' => 'application/x-kugar',
'kwd' => 'application/x-kword',
'kwt' => 'application/x-kword',
'la' => 'application/x-shared-library-la',
'latex' => 'text/x-tex',
'ldif' => 'text/x-ldif',
'lha' => 'application/x-lha',
'lhs' => 'text/x-literate-haskell',
'lhz' => 'application/x-lhz',
'log' => 'text/x-log',
'ltx' => 'text/x-tex',
'lua' => 'text/x-lua',
'lwo' => 'image/x-lwo',
'lwob' => 'image/x-lwo',
'lws' => 'image/x-lws',
'ly' => 'text/x-lilypond',
'lyx' => 'application/x-lyx',
'lzh' => 'application/x-lha',
'lzma' => 'application/x-lzma',
'lzo' => 'application/x-lzop',
'm' => 'text/x-objcsrc',
'm15' => 'audio/x-mod',
'm2t' => 'video/mpeg',
'm3u' => 'audio/x-mpegurl',
'm3u8' => 'audio/x-mpegurl',
'm4' => 'application/x-m4',
'm4a' => 'audio/mp4',
'm4b' => 'audio/x-m4b',
'm4v' => 'video/mp4',
'mab' => 'application/x-markaby',
'man' => 'application/x-troff-man',
'mbox' => 'application/mbox',
'md' => 'application/x-genesis-rom',
'mdb' => 'application/vnd.ms-access',
'me' => 'text/x-troff-me',
'med' => 'audio/x-mod',
'mgp' => 'application/x-magicpoint',
'mid' => 'audio/midi',
'midi' => 'audio/midi',
'mif' => 'application/x-mif',
'minipsf' => 'audio/x-minipsf',
'mka' => 'audio/x-matroska',
'mkv' => 'video/x-matroska',
'ml' => 'text/x-ocaml',
'mli' => 'text/x-ocaml',
'mm' => 'text/x-troff-mm',
'mmf' => 'application/x-smaf',
'mml' => 'text/mathml',
'mng' => 'video/x-mng',
'mo' => 'application/x-gettext-translation',
'mo3' => 'audio/x-mo3',
'moc' => 'text/x-moc',
'mod' => 'audio/x-mod',
'mof' => 'text/x-mof',
'moov' => 'video/quicktime',
'mov' => 'video/quicktime',
'movie' => 'video/x-sgi-movie',
'mp+' => 'audio/x-musepack',
'mp2' => 'audio/mp2',
'mp3' => 'audio/mpeg',
'mp4' => 'video/mp4',
'mpc' => 'audio/x-musepack',
'mpe' => 'video/mpeg',
'mpeg' => 'video/mpeg',
'mpg' => 'video/mpeg',
'mpga' => 'audio/mpeg',
'mpp' => 'audio/x-musepack',
'mrl' => 'text/x-mrml',
'mrml' => 'text/x-mrml',
'mrw' => 'image/x-minolta-mrw',
'ms' => 'text/x-troff-ms',
'msi' => 'application/x-msi',
'msod' => 'image/x-msod',
'msx' => 'application/x-msx-rom',
'mtm' => 'audio/x-mod',
'mup' => 'text/x-mup',
'n64' => 'application/x-n64-rom',
'nb' => 'application/mathematica',
'nc' => 'application/x-netcdf',
'nds' => 'application/x-nintendo-ds-rom',
'nef' => 'image/x-nikon-nef',
'nes' => 'application/x-nes-rom',
'nfo' => 'text/x-nfo',
'not' => 'text/x-mup',
'nsc' => 'application/x-netshow-channel',
'nsv' => 'video/x-nsv',
'o' => 'application/x-object',
'obj' => 'application/x-tgif',
'ocl' => 'text/x-ocl',
'oda' => 'application/oda',
'odb' => 'application/vnd.oasis.opendocument.database',
'odc' => 'application/vnd.oasis.opendocument.chart',
'odf' => 'application/vnd.oasis.opendocument.formula',
'odg' => 'application/vnd.oasis.opendocument.graphics',
'odi' => 'application/vnd.oasis.opendocument.image',
'odm' => 'application/vnd.oasis.opendocument.text-master',
'odp' => 'application/vnd.oasis.opendocument.presentation',
'ods' => 'application/vnd.oasis.opendocument.spreadsheet',
'odt' => 'application/vnd.oasis.opendocument.text',
'oga' => 'audio/ogg',
'ogg' => 'application/ogg',
'ogm' => 'video/x-ogm+ogg',
'ogv' => 'video/ogg',
'ogx' => 'application/ogg',
'old' => 'application/x-trash',
'oleo' => 'application/x-oleo',
'opml' => 'text/x-opml+xml',
'orf' => 'image/x-olympus-orf',
'otg' => 'application/vnd.oasis.opendocument.graphics-template',
'oth' => 'application/vnd.oasis.opendocument.text-web',
'otp' => 'application/vnd.oasis.opendocument.presentation-template',
'ots' => 'application/vnd.oasis.opendocument.spreadsheet-template',
'ott' => 'application/vnd.oasis.opendocument.text-template',
'owl' => 'text/rdf',
'oxt' => 'application/vnd.openofficeorg.extension',
'p' => 'text/x-pascal',
'p10' => 'application/pkcs10',
'p12' => 'application/x-pkcs12',
'p7s' => 'application/pkcs7-signature',
'pack' => 'application/x-java-pack200',
'pak' => 'application/x-pak',
'par2' => 'application/x-par2',
'pas' => 'text/x-pascal',
'patch' => 'text/x-patch',
'pbm' => 'image/x-portable-bitmap',
'pcd' => 'image/x-photo-cd',
'pcf' => 'application/x-font-pcf',
'pcf.gz' => 'application/x-font-pcf',
'pcf.z' => 'application/x-font-pcf',
'pcl' => 'application/vnd.hp-pcl',
'pcx' => 'image/x-pcx',
'pdb' => 'application/x-palm-database',
'pdf' => 'application/pdf',
'pdf.bz2' => 'application/x-bzpdf',
'pdf.gz' => 'application/x-gzpdf',
'pef' => 'image/x-pentax-pef',
'pem' => 'application/x-x509-ca-cert',
'perl' => 'application/x-perl',
'pfa' => 'application/x-font-type1',
'pfb' => 'application/x-font-type1',
'pfx' => 'application/x-pkcs12',
'pgm' => 'image/x-portable-graymap',
'pgn' => 'application/x-chess-pgn',
'pgp' => 'application/pgp-encrypted',
'php' => 'application/x-php',
'php3' => 'application/x-php',
'php4' => 'application/x-php',
'pict' => 'image/x-pict',
'pict1' => 'image/x-pict',
'pict2' => 'image/x-pict',
'pk' => 'application/x-tex-pk',
'pkr' => 'application/pgp-keys',
'pl' => 'application/x-perl',
'pla' => 'audio/x-iriver-pla',
'pln' => 'application/x-planperfect',
'pls' => 'audio/x-scpls',
'pm' => 'application/x-perl',
'png' => 'image/png',
'pnm' => 'image/x-portable-anymap',
'pntg' => 'image/x-macpaint',
'po' => 'text/x-gettext-translation',
'pot' => 'application/vnd.ms-powerpoint',
'ppm' => 'image/x-portable-pixmap',
'pps' => 'application/vnd.ms-powerpoint',
'ppt' => 'application/vnd.ms-powerpoint',
'ppz' => 'application/vnd.ms-powerpoint',
'prc' => 'application/x-palm-database',
'ps' => 'application/postscript',
'ps.bz2' => 'application/x-bzpostscript',
'ps.gz' => 'application/x-gzpostscript',
'psd' => 'image/x-psd',
'psf' => 'application/x-font-linux-psf',
'psf.gz' => 'application/x-gz-font-linux-psf',
'psflib' => 'audio/x-psflib',
'psid' => 'audio/prs.sid',
'pw' => 'application/x-pw',
'py' => 'text/x-python',
'pyc' => 'application/x-python-bytecode',
'pyo' => 'application/x-python-bytecode',
'qif' => 'application/x-qw',
'qt' => 'video/quicktime',
'qtif' => 'image/x-quicktime',
'qtl' => 'application/x-quicktime-media-link',
'qtvr' => 'video/quicktime',
'ra' => 'audio/vnd.rn-realaudio',
'raf' => 'image/x-fuji-raf',
'ram' => 'application/ram',
'rar' => 'application/x-rar',
'ras' => 'image/x-cmu-raster',
'raw' => 'image/x-panasonic-raw',
'rax' => 'audio/vnd.rn-realaudio',
'rb' => 'application/x-ruby',
'rdf' => 'text/rdf',
'rdfs' => 'text/rdf',
'reg' => 'text/x-ms-regedit',
'rej' => 'application/x-reject',
'rgb' => 'image/x-rgb',
'rle' => 'image/rle',
'rm' => 'application/vnd.rn-realmedia',
'rmj' => 'application/vnd.rn-realmedia',
'rmm' => 'application/vnd.rn-realmedia',
'rms' => 'application/vnd.rn-realmedia',
'rmvb' => 'application/vnd.rn-realmedia',
'rmx' => 'application/vnd.rn-realmedia',
'roff' => 'text/troff',
'rp' => 'image/vnd.rn-realpix',
'rpm' => 'application/x-rpm',
'rss' => 'application/rss+xml',
'rt' => 'text/vnd.rn-realtext',
'rtf' => 'application/rtf',
'rtx' => 'text/richtext',
'rv' => 'video/vnd.rn-realvideo',
'rvx' => 'video/vnd.rn-realvideo',
's3m' => 'audio/x-s3m',
'sam' => 'application/x-amipro',
'sami' => 'application/x-sami',
'scm' => 'text/x-scheme',
'sda' => 'application/vnd.stardivision.draw',
'sdc' => 'application/vnd.stardivision.calc',
'sdd' => 'application/vnd.stardivision.impress',
'sdp' => 'application/vnd.stardivision.impress',
'sds' => 'application/vnd.stardivision.chart',
'sdw' => 'application/vnd.stardivision.writer',
'sgf' => 'application/x-go-sgf',
'sgi' => 'image/x-sgi',
'sgl' => 'application/vnd.stardivision.writer',
'sgm' => 'text/sgml',
'sgml' => 'text/sgml',
'sh' => 'application/x-shellscript',
'shar' => 'application/x-shar',
'shn' => 'application/x-shorten',
'siag' => 'application/x-siag',
'sid' => 'audio/prs.sid',
'sik' => 'application/x-trash',
'sis' => 'application/vnd.symbian.install',
'sisx' => 'x-epoc/x-sisx-app',
'sit' => 'application/x-stuffit',
'siv' => 'application/sieve',
'sk' => 'image/x-skencil',
'sk1' => 'image/x-skencil',
'skr' => 'application/pgp-keys',
'slk' => 'text/spreadsheet',
'smaf' => 'application/x-smaf',
'smc' => 'application/x-snes-rom',
'smd' => 'application/vnd.stardivision.mail',
'smf' => 'application/vnd.stardivision.math',
'smi' => 'application/smil',
'smil' => 'application/smil',
'sml' => 'application/smil',
'sms' => 'application/x-sms-rom',
'snd' => 'audio/basic',
'so' => 'application/x-sharedlib',
'spd' => 'application/x-font-speedo',
'spec' => 'text/x-rpm-spec',
'spl' => 'application/x-shockwave-flash',
'spx' => 'audio/x-speex',
'sql' => 'text/x-sql',
'sr2' => 'image/x-sony-sr2',
'src' => 'application/x-wais-source',
'srf' => 'image/x-sony-srf',
'srt' => 'application/x-subrip',
'ssa' => 'text/x-ssa',
'stc' => 'application/vnd.sun.xml.calc.template',
'std' => 'application/vnd.sun.xml.draw.template',
'sti' => 'application/vnd.sun.xml.impress.template',
'stm' => 'audio/x-stm',
'stw' => 'application/vnd.sun.xml.writer.template',
'sty' => 'text/x-tex',
'sub' => 'text/x-microdvd',
'sun' => 'image/x-sun-raster',
'sv4cpio' => 'application/x-sv4cpio',
'sv4crc' => 'application/x-sv4crc',
'svg' => 'image/svg+xml',
'svgz' => 'image/svg+xml-compressed',
'swf' => 'application/x-shockwave-flash',
'sxc' => 'application/vnd.sun.xml.calc',
'sxd' => 'application/vnd.sun.xml.draw',
'sxg' => 'application/vnd.sun.xml.writer.global',
'sxi' => 'application/vnd.sun.xml.impress',
'sxm' => 'application/vnd.sun.xml.math',
'sxw' => 'application/vnd.sun.xml.writer',
'sylk' => 'text/spreadsheet',
't' => 'text/troff',
't2t' => 'text/x-txt2tags',
'tar' => 'application/x-tar',
'tar.bz' => 'application/x-bzip-compressed-tar',
'tar.bz2' => 'application/x-bzip-compressed-tar',
'tar.gz' => 'application/x-compressed-tar',
'tar.lzma' => 'application/x-lzma-compressed-tar',
'tar.lzo' => 'application/x-tzo',
'tar.z' => 'application/x-tarz',
'tbz' => 'application/x-bzip-compressed-tar',
'tbz2' => 'application/x-bzip-compressed-tar',
'tcl' => 'text/x-tcl',
'tex' => 'text/x-tex',
'texi' => 'text/x-texinfo',
'texinfo' => 'text/x-texinfo',
'tga' => 'image/x-tga',
'tgz' => 'application/x-compressed-tar',
'theme' => 'application/x-theme',
'tif' => 'image/tiff',
'tiff' => 'image/tiff',
'tk' => 'text/x-tcl',
'tlz' => 'application/x-lzma-compressed-tar',
'tnef' => 'application/vnd.ms-tnef',
'tnf' => 'application/vnd.ms-tnef',
'toc' => 'application/x-cdrdao-toc',
'torrent' => 'application/x-bittorrent',
'tpic' => 'image/x-tga',
'tr' => 'text/troff',
'ts' => 'application/x-linguist',
'tsv' => 'text/tab-separated-values',
'tta' => 'audio/x-tta',
'ttc' => 'application/x-font-ttf',
'ttf' => 'application/x-font-ttf',
'ttx' => 'application/x-font-ttx',
'txt' => 'text/plain',
'tzo' => 'application/x-tzo',
'ufraw' => 'application/x-ufraw',
'ui' => 'application/x-designer',
'uil' => 'text/x-uil',
'ult' => 'audio/x-mod',
'uni' => 'audio/x-mod',
'uri' => 'text/x-uri',
'url' => 'text/x-uri',
'ustar' => 'application/x-ustar',
'vala' => 'text/x-vala',
'vcf' => 'text/directory',
'vcs' => 'text/calendar',
'vct' => 'text/directory',
'vda' => 'image/x-tga',
'vhd' => 'text/x-vhdl',
'vhdl' => 'text/x-vhdl',
'viv' => 'video/vivo',
'vivo' => 'video/vivo',
'vlc' => 'audio/x-mpegurl',
'vob' => 'video/mpeg',
'voc' => 'audio/x-voc',
'vor' => 'application/vnd.stardivision.writer',
'vst' => 'image/x-tga',
'wav' => 'audio/x-wav',
'wax' => 'audio/x-ms-asx',
'wb1' => 'application/x-quattropro',
'wb2' => 'application/x-quattropro',
'wb3' => 'application/x-quattropro',
'wbmp' => 'image/vnd.wap.wbmp',
'wcm' => 'application/vnd.ms-works',
'wdb' => 'application/vnd.ms-works',
'wk1' => 'application/vnd.lotus-1-2-3',
'wk3' => 'application/vnd.lotus-1-2-3',
'wk4' => 'application/vnd.lotus-1-2-3',
'wks' => 'application/vnd.lotus-1-2-3',
'wma' => 'audio/x-ms-wma',
'wmf' => 'image/x-wmf',
'wml' => 'text/vnd.wap.wml',
'wmls' => 'text/vnd.wap.wmlscript',
'wmv' => 'video/x-ms-wmv',
'wmx' => 'audio/x-ms-asx',
'wp' => 'application/vnd.wordperfect',
'wp4' => 'application/vnd.wordperfect',
'wp5' => 'application/vnd.wordperfect',
'wp6' => 'application/vnd.wordperfect',
'wpd' => 'application/vnd.wordperfect',
'wpg' => 'application/x-wpg',
'wpp' => 'application/vnd.wordperfect',
'wps' => 'application/vnd.ms-works',
'wri' => 'application/x-mswrite',
'wrl' => 'model/vrml',
'wv' => 'audio/x-wavpack',
'wvc' => 'audio/x-wavpack-correction',
'wvp' => 'audio/x-wavpack',
'wvx' => 'audio/x-ms-asx',
'x3f' => 'image/x-sigma-x3f',
'xac' => 'application/x-gnucash',
'xbel' => 'application/x-xbel',
'xbl' => 'application/xml',
'xbm' => 'image/x-xbitmap',
'xcf' => 'image/x-xcf',
'xcf.bz2' => 'image/x-compressed-xcf',
'xcf.gz' => 'image/x-compressed-xcf',
'xhtml' => 'application/xhtml+xml',
'xi' => 'audio/x-xi',
'xla' => 'application/vnd.ms-excel',
'xlc' => 'application/vnd.ms-excel',
'xld' => 'application/vnd.ms-excel',
'xlf' => 'application/x-xliff',
'xliff' => 'application/x-xliff',
'xll' => 'application/vnd.ms-excel',
'xlm' => 'application/vnd.ms-excel',
'xls' => 'application/vnd.ms-excel',
'xlt' => 'application/vnd.ms-excel',
'xlw' => 'application/vnd.ms-excel',
'xm' => 'audio/x-xm',
'xmf' => 'audio/x-xmf',
'xmi' => 'text/x-xmi',
'xml' => 'application/xml',
'xpm' => 'image/x-xpixmap',
'xps' => 'application/vnd.ms-xpsdocument',
'xsl' => 'application/xml',
'xslfo' => 'text/x-xslfo',
'xslt' => 'application/xml',
'xspf' => 'application/xspf+xml',
'xul' => 'application/vnd.mozilla.xul+xml',
'xwd' => 'image/x-xwindowdump',
'z' => 'application/x-compress',
'zabw' => 'application/x-abiword',
'zip' => 'application/zip',
'zoo' => 'application/x-zoo',
}
TYPES = {
'application/andrew-inset' => [["ez"], []],
'application/atom+xml' => [["atom"], ["application/xml"]],
'application/dicom' => [["dcm"], []],
'application/docbook+xml' => [["docbook"], ["application/xml"]],
'application/ecmascript' => [["es"], ["text/plain"]],
'application/epub+zip' => [["epub"], []],
'application/gnunet-directory' => [["gnd"], []],
'application/illustrator' => [["ai"], []],
'application/javascript' => [["js"], ["text/plain"]],
'application/mathematica' => [["nb"], ["text/plain"]],
'application/mbox' => [["mbox"], ["text/plain"]],
'application/msword' => [["doc"], ["application/x-ole-storage"]],
'application/msword-template' => [["dot"], ["application/msword"]],
'application/octet-stream' => [["bin"], []],
'application/oda' => [["oda"], []],
'application/ogg' => [["ogg", "ogx"], []],
'application/pdf' => [["pdf"], []],
'application/pgp-encrypted' => [["asc", "gpg", "pgp"], []],
'application/pgp-keys' => [["asc", "pkr", "skr"], ["text/plain"]],
'application/pkcs10' => [["p10"], []],
'application/pkcs7-signature' => [["p7s"], ["text/plain"]],
'application/postscript' => [["ps"], ["text/plain"]],
'application/ram' => [["ram"], ["text/plain"]],
'application/rss+xml' => [["rss"], ["application/xml"]],
'application/rtf' => [["rtf"], ["text/plain"]],
'application/sdp' => [["sdp"], []],
'application/sieve' => [["siv"], ["application/xml"]],
'application/smil' => [["kino", "smi", "smil", "sml"], ["application/xml"]],
'application/vnd.corel-draw' => [["cdr"], []],
'application/vnd.emusic-emusic_package' => [["emp"], []],
'application/vnd.hp-hpgl' => [["hpgl"], []],
'application/vnd.hp-pcl' => [["pcl"], []],
'application/vnd.lotus-1-2-3' => [["123", "wk1", "wk3", "wk4", "wks"], []],
'application/vnd.mozilla.xul+xml' => [["xul"], ["application/xml"]],
'application/vnd.ms-access' => [["mdb"], []],
'application/vnd.ms-excel' => [["xla", "xlc", "xld", "xll", "xlm", "xls", "xlt", "xlw"], []],
'application/vnd.ms-powerpoint' => [["pot", "pps", "ppt", "ppz"], []],
'application/vnd.ms-tnef' => [["tnef", "tnf"], []],
'application/vnd.ms-works' => [["wcm", "wdb", "wks", "wps"], ["application/x-ole-storage"]],
'application/vnd.ms-xpsdocument' => [["xps"], ["application/zip"]],
'application/vnd.oasis.opendocument.chart' => [["odc"], ["application/zip"]],
'application/vnd.oasis.opendocument.database' => [["odb"], ["application/zip"]],
'application/vnd.oasis.opendocument.formula' => [["odf"], ["application/zip"]],
'application/vnd.oasis.opendocument.graphics' => [["odg"], ["application/zip"]],
'application/vnd.oasis.opendocument.graphics-template' => [["otg"], ["application/zip"]],
'application/vnd.oasis.opendocument.image' => [["odi"], ["application/zip"]],
'application/vnd.oasis.opendocument.presentation' => [["odp"], ["application/zip"]],
'application/vnd.oasis.opendocument.presentation-template' => [["otp"], ["application/zip"]],
'application/vnd.oasis.opendocument.spreadsheet' => [["ods"], ["application/zip"]],
'application/vnd.oasis.opendocument.spreadsheet-template' => [["ots"], ["application/zip"]],
'application/vnd.oasis.opendocument.text' => [["odt"], ["application/zip"]],
'application/vnd.oasis.opendocument.text-master' => [["odm"], ["application/zip"]],
'application/vnd.oasis.opendocument.text-template' => [["ott"], ["application/zip"]],
'application/vnd.oasis.opendocument.text-web' => [["oth"], ["application/zip"]],
'application/vnd.openofficeorg.extension' => [["oxt"], ["application/zip"]],
'application/vnd.rn-realmedia' => [["rm", "rmj", "rmm", "rms", "rmvb", "rmx"], []],
'application/vnd.stardivision.calc' => [["sdc"], []],
'application/vnd.stardivision.chart' => [["sds"], []],
'application/vnd.stardivision.draw' => [["sda"], []],
'application/vnd.stardivision.impress' => [["sdd", "sdp"], []],
'application/vnd.stardivision.mail' => [["smd"], []],
'application/vnd.stardivision.math' => [["smf"], []],
'application/vnd.stardivision.writer' => [["sdw", "sgl", "vor"], []],
'application/vnd.sun.xml.calc' => [["sxc"], ["application/zip"]],
'application/vnd.sun.xml.calc.template' => [["stc"], ["application/zip"]],
'application/vnd.sun.xml.draw' => [["sxd"], ["application/zip"]],
'application/vnd.sun.xml.draw.template' => [["std"], ["application/zip"]],
'application/vnd.sun.xml.impress' => [["sxi"], ["application/zip"]],
'application/vnd.sun.xml.impress.template' => [["sti"], ["application/zip"]],
'application/vnd.sun.xml.math' => [["sxm"], ["application/zip"]],
'application/vnd.sun.xml.writer' => [["sxw"], ["application/zip"]],
'application/vnd.sun.xml.writer.global' => [["sxg"], ["application/zip"]],
'application/vnd.sun.xml.writer.template' => [["stw"], ["application/zip"]],
'application/vnd.symbian.install' => [["sis"], []],
'application/vnd.wordperfect' => [["wp", "wp4", "wp5", "wp6", "wpd", "wpp"], []],
'application/x-7z-compressed' => [["7z"], []],
'application/x-abiword' => [["abw", "abw.crashed", "abw.gz", "zabw"], ["application/xml"]],
'application/x-ace' => [["ace"], []],
'application/x-alz' => [["alz"], []],
'application/x-amipro' => [["sam"], []],
'application/x-applix-spreadsheet' => [["as"], []],
'application/x-applix-word' => [["aw"], []],
'application/x-archive' => [["a"], []],
'application/x-arj' => [["arj"], []],
'application/x-asp' => [["asp"], ["text/plain"]],
'application/x-awk' => [["awk"], ["application/x-executable", "text/plain"]],
'application/x-bcpio' => [["bcpio"], []],
'application/x-bittorrent' => [["torrent"], []],
'application/x-blender' => [["blend", "blend", "blender"], []],
'application/x-bzdvi' => [["dvi.bz2"], []],
'application/x-bzip' => [["bz", "bz2"], []],
'application/x-bzip-compressed-tar' => [["tar.bz", "tar.bz2", "tbz", "tbz2"], []],
'application/x-bzpdf' => [["pdf.bz2"], []],
'application/x-bzpostscript' => [["ps.bz2"], []],
'application/x-cbr' => [["cbr"], ["application/x-rar"]],
'application/x-cbz' => [["cbz"], ["application/zip"]],
'application/x-cd-image' => [["iso", "iso9660"], []],
'application/x-cdrdao-toc' => [["toc"], ["text/plain"]],
'application/x-chess-pgn' => [["pgn"], ["text/plain"]],
'application/x-chm' => [["chm"], []],
'application/x-cisco-vpn-settings' => [["pcf"], []],
'application/x-compress' => [["z"], []],
'application/x-compressed-tar' => [["tar.gz", "tgz"], []],
'application/x-cpio' => [["cpio"], []],
'application/x-cpio-compressed' => [["cpio.gz"], []],
'application/x-csh' => [["csh"], ["application/x-shellscript", "text/plain"]],
'application/x-cue' => [["cue"], ["text/plain"]],
'application/x-dar' => [["dar"], []],
'application/x-dbf' => [["dbf"], []],
'application/x-dc-rom' => [["dc"], []],
'application/x-deb' => [["deb"], []],
'application/x-designer' => [["ui"], []],
'application/x-desktop' => [["desktop", "kdelnk"], ["text/plain"]],
'application/x-dia-diagram' => [["dia"], ["application/xml"]],
'application/x-dvi' => [["dvi"], []],
'application/x-e-theme' => [["etheme"], []],
'application/x-egon' => [["egon"], []],
'application/x-fluid' => [["fl"], ["text/plain"]],
'application/x-font-afm' => [["afm"], []],
'application/x-font-bdf' => [["bdf"], []],
'application/x-font-linux-psf' => [["psf"], []],
'application/x-font-pcf' => [["pcf", "pcf.gz", "pcf.z"], []],
'application/x-font-speedo' => [["spd"], []],
'application/x-font-ttf' => [["ttc", "ttf"], []],
'application/x-font-ttx' => [["ttx"], ["text/xml"]],
'application/x-font-type1' => [["gsf", "pfa", "pfb"], ["application/postscript"]],
'application/x-gameboy-rom' => [["gb"], []],
'application/x-gba-rom' => [["gba"], []],
'application/x-gedcom' => [["ged", "gedcom"], []],
'application/x-genesis-rom' => [["gen", "md"], []],
'application/x-gettext-translation' => [["gmo", "mo"], []],
'application/x-glade' => [["glade"], ["application/xml"]],
'application/x-gnucash' => [["gnc", "gnucash", "xac"], []],
'application/x-gnumeric' => [["gnumeric"], []],
'application/x-gnuplot' => [["gnuplot", "gp", "gplt"], ["text/plain"]],
'application/x-go-sgf' => [["sgf"], ["text/plain"]],
'application/x-graphite' => [["gra"], []],
'application/x-gz-font-linux-psf' => [["psf.gz"], ["application/x-gzip"]],
'application/x-gzdvi' => [["dvi.gz"], ["application/x-gzip"]],
'application/x-gzip' => [["gz"], []],
'application/x-gzpdf' => [["pdf.gz"], ["application/x-gzip"]],
'application/x-gzpostscript' => [["ps.gz"], ["application/x-gzip"]],
'application/x-hdf' => [["hdf"], []],
'application/x-hwp' => [["hwp"], []],
'application/x-hwt' => [["hwt"], []],
'application/x-ica' => [["ica"], ["text/plain"]],
'application/x-java' => [["class"], []],
'application/x-java-archive' => [["jar"], []],
'application/x-java-jnlp-file' => [["jnlp"], ["application/xml"]],
'application/x-java-pack200' => [["pack"], []],
'application/x-jbuilder-project' => [["jpr", "jpx"], []],
'application/x-karbon' => [["karbon"], []],
'application/x-kchart' => [["chrt"], []],
'application/x-kformula' => [["kfo"], []],
'application/x-killustrator' => [["kil"], []],
'application/x-kivio' => [["flw"], []],
'application/x-kontour' => [["kon"], []],
'application/x-kpovmodeler' => [["kpm"], []],
'application/x-kpresenter' => [["kpr", "kpt"], []],
'application/x-krita' => [["kra"], []],
'application/x-kspread' => [["ksp"], []],
'application/x-kugar' => [["kud"], []],
'application/x-kword' => [["kwd", "kwt"], []],
'application/x-lha' => [["lha", "lzh"], []],
'application/x-lhz' => [["lhz"], []],
'application/x-linguist' => [["ts"], []],
'application/x-lyx' => [["lyx"], ["text/plain"]],
'application/x-lzma' => [["lzma"], []],
'application/x-lzma-compressed-tar' => [["tar.lzma", "tlz"], []],
'application/x-lzop' => [["lzo"], []],
'application/x-m4' => [["m4"], ["text/plain"]],
'application/x-magicpoint' => [["mgp"], ["text/plain"]],
'application/x-markaby' => [["mab"], ["application/x-ruby"]],
'application/x-mif' => [["mif"], []],
'application/x-ms-dos-executable' => [["exe"], []],
'application/x-msi' => [["msi"], ["application/x-ole-storage"]],
'application/x-mswrite' => [["wri"], []],
'application/x-msx-rom' => [["msx"], []],
'application/x-n64-rom' => [["n64"], []],
'application/x-navi-animation' => [["ani"], []],
'application/x-nes-rom' => [["nes"], []],
'application/x-netcdf' => [["cdf", "nc"], []],
'application/x-netshow-channel' => [["nsc"], ["video/x-ms-asf"]],
'application/x-nintendo-ds-rom' => [["nds"], []],
'application/x-object' => [["o"], []],
'application/x-oleo' => [["oleo"], []],
'application/x-pak' => [["pak"], []],
'application/x-palm-database' => [["pdb", "prc"], []],
'application/x-par2' => [["par2", "par2"], []],
'application/x-perl' => [["al", "perl", "pl", "pm"], ["application/x-executable", "text/plain"]],
'application/x-php' => [["php", "php3", "php4"], ["text/plain"]],
'application/x-pkcs12' => [["p12", "pfx"], []],
'application/x-planperfect' => [["pln"], []],
'application/x-pw' => [["pw"], []],
'application/x-python-bytecode' => [["pyc", "pyo"], []],
'application/x-quattropro' => [["wb1", "wb2", "wb3"], []],
'application/x-quicktime-media-link' => [["qtl"], ["video/quicktime"]],
'application/x-qw' => [["qif"], []],
'application/x-rar' => [["rar"], []],
'application/x-reject' => [["rej"], ["text/plain"]],
'application/x-rpm' => [["rpm"], []],
'application/x-ruby' => [["rb"], ["application/x-executable", "text/plain"]],
'application/x-sami' => [["sami", "smi"], ["text/plain"]],
'application/x-shar' => [["shar"], []],
'application/x-shared-library-la' => [["la"], ["text/plain"]],
'application/x-sharedlib' => [["so"], []],
'application/x-shellscript' => [["sh"], ["application/x-executable", "text/plain"]],
'application/x-shockwave-flash' => [["spl", "swf"], []],
'application/x-shorten' => [["shn"], []],
'application/x-siag' => [["siag"], []],
'application/x-smaf' => [["mmf", "smaf"], []],
'application/x-sms-rom' => [["gg", "sms"], []],
'application/x-snes-rom' => [["smc"], []],
'application/x-stuffit' => [["sit"], []],
'application/x-subrip' => [["srt"], ["text/plain"]],
'application/x-sv4cpio' => [["sv4cpio"], []],
'application/x-sv4crc' => [["sv4crc"], []],
'application/x-t602' => [["602"], []],
'application/x-tar' => [["gtar", "tar"], []],
'application/x-tarz' => [["tar.z"], []],
'application/x-tex-gf' => [["gf"], []],
'application/x-tex-pk' => [["pk"], []],
'application/x-tgif' => [["obj"], []],
'application/x-theme' => [["theme"], ["application/x-desktop"]],
'application/x-trash' => [["bak", "old", "sik"], []],
'application/x-troff-man' => [["man"], ["text/plain"]],
'application/x-tzo' => [["tar.lzo", "tzo"], []],
'application/x-ufraw' => [["ufraw"], ["text/xml"]],
'application/x-ustar' => [["ustar"], []],
'application/x-wais-source' => [["src"], []],
'application/x-wpg' => [["wpg"], []],
'application/x-x509-ca-cert' => [["cer", "cert", "crt", "der", "pem"], []],
'application/x-xbel' => [["xbel"], ["application/xml"]],
'application/x-xliff' => [["xlf", "xliff"], ["application/xml"]],
'application/x-zoo' => [["zoo"], []],
'application/xhtml+xml' => [["xhtml"], ["application/xml"]],
'application/xml' => [["xbl", "xml", "xsl", "xslt"], ["text/plain"]],
'application/xml-dtd' => [["dtd"], ["text/plain"]],
'application/xml-external-parsed-entity' => [["ent"], ["application/xml"]],
'application/xspf+xml' => [["xspf"], ["application/xml"]],
'application/zip' => [["zip"], []],
'audio/AMR' => [["amr"], []],
'audio/AMR-WB' => [["awb"], []],
'audio/ac3' => [["ac3"], []],
'audio/basic' => [["au", "snd"], []],
'audio/midi' => [["kar", "mid", "midi"], []],
'audio/mp2' => [["mp2"], []],
'audio/mp4' => [["aac", "m4a"], []],
'audio/mpeg' => [["mp3", "mpga"], []],
'audio/ogg' => [["oga"], ["application/ogg"]],
'audio/prs.sid' => [["psid", "sid"], []],
'audio/vnd.rn-realaudio' => [["ra", "rax"], []],
'audio/x-aiff' => [["aif", "aifc", "aiff"], []],
'audio/x-ape' => [["ape"], []],
'audio/x-flac' => [["flac"], []],
'audio/x-flac+ogg' => [["ogg"], ["audio/ogg"]],
'audio/x-iriver-pla' => [["pla"], []],
'audio/x-it' => [["it"], []],
'audio/x-m4b' => [["m4b"], ["audio/mp4"]],
'audio/x-matroska' => [["mka"], ["application/x-matroska"]],
'audio/x-minipsf' => [["minipsf"], ["audio/x-psf"]],
'audio/x-mo3' => [["mo3"], []],
'audio/x-mod' => [["669", "m15", "med", "mod", "mtm", "ult", "uni"], []],
'audio/x-mpegurl' => [["m3u", "m3u8", "vlc"], ["text/plain"]],
'audio/x-ms-asx' => [["asx", "wax", "wmx", "wvx"], []],
'audio/x-ms-wma' => [["wma"], ["video/x-ms-asf"]],
'audio/x-musepack' => [["mp+", "mpc", "mpp"], []],
'audio/x-psf' => [["psf"], []],
'audio/x-psflib' => [["psflib"], ["audio/x-psf"]],
'audio/x-s3m' => [["s3m"], []],
'audio/x-scpls' => [["pls"], []],
'audio/x-speex' => [["spx"], []],
'audio/x-speex+ogg' => [["ogg"], ["audio/ogg"]],
'audio/x-stm' => [["stm"], []],
'audio/x-tta' => [["tta"], []],
'audio/x-voc' => [["voc"], []],
'audio/x-vorbis+ogg' => [["ogg"], ["audio/ogg"]],
'audio/x-wav' => [["wav"], []],
'audio/x-wavpack' => [["wv", "wvp"], []],
'audio/x-wavpack-correction' => [["wvc"], []],
'audio/x-xi' => [["xi"], []],
'audio/x-xm' => [["xm"], []],
'audio/x-xmf' => [["xmf"], []],
'image/bmp' => [["bmp"], []],
'image/cgm' => [["cgm"], []],
'image/fax-g3' => [["g3"], []],
'image/gif' => [["gif"], []],
'image/ief' => [["ief"], []],
'image/jp2' => [["j2k", "jp2", "jpc", "jpf", "jpx"], []],
'image/jpeg' => [["jpe", "jpeg", "jpg"], []],
'image/png' => [["png"], []],
'image/rle' => [["rle"], []],
'image/svg+xml' => [["svg"], ["application/xml"]],
'image/svg+xml-compressed' => [["svgz"], ["application/x-gzip"]],
'image/tiff' => [["tif", "tiff"], []],
'image/vnd.djvu' => [["djv", "djvu"], []],
'image/vnd.dwg' => [["dwg"], []],
'image/vnd.dxf' => [["dxf"], []],
'image/vnd.rn-realpix' => [["rp"], []],
'image/vnd.wap.wbmp' => [["wbmp"], []],
'image/x-3ds' => [["3ds"], []],
'image/x-adobe-dng' => [["dng"], ["image/tiff", "image/x-dcraw"]],
'image/x-applix-graphics' => [["ag"], []],
'image/x-bzeps' => [["eps.bz2", "epsf.bz2", "epsi.bz2"], []],
'image/x-canon-cr2' => [["cr2"], ["image/tiff", "image/x-dcraw"]],
'image/x-canon-crw' => [["crw"], ["image/x-dcraw"]],
'image/x-cmu-raster' => [["ras"], []],
'image/x-compressed-xcf' => [["xcf.bz2", "xcf.gz"], []],
'image/x-dds' => [["dds"], []],
'image/x-emf' => [["emf"], []],
'image/x-eps' => [["eps", "epsf", "epsi"], ["application/postscript"]],
'image/x-exr' => [["exr"], []],
'image/x-fits' => [["fits"], []],
'image/x-fuji-raf' => [["raf"], ["image/x-dcraw"]],
'image/x-gzeps' => [["eps.gz", "epsf.gz", "epsi.gz"], []],
'image/x-icns' => [["icns"], []],
'image/x-ico' => [["ico"], []],
'image/x-iff' => [["iff"], []],
'image/x-ilbm' => [["ilbm"], []],
'image/x-jng' => [["jng"], []],
'image/x-kodak-dcr' => [["dcr"], ["image/tiff", "image/x-dcraw"]],
'image/x-kodak-k25' => [["k25"], ["image/tiff", "image/x-dcraw"]],
'image/x-kodak-kdc' => [["kdc"], ["image/tiff", "image/x-dcraw"]],
'image/x-lwo' => [["lwo", "lwob"], []],
'image/x-lws' => [["lws"], []],
'image/x-macpaint' => [["pntg"], []],
'image/x-minolta-mrw' => [["mrw"], ["image/x-dcraw"]],
'image/x-msod' => [["msod"], []],
'image/x-nikon-nef' => [["nef"], ["image/tiff", "image/x-dcraw"]],
'image/x-olympus-orf' => [["orf"], ["image/x-dcraw"]],
'image/x-panasonic-raw' => [["raw"], ["image/x-dcraw"]],
'image/x-pcx' => [["pcx"], []],
'image/x-pentax-pef' => [["pef"], ["image/tiff", "image/x-dcraw"]],
'image/x-photo-cd' => [["pcd"], []],
'image/x-pict' => [["pict", "pict1", "pict2"], []],
'image/x-portable-anymap' => [["pnm"], []],
'image/x-portable-bitmap' => [["pbm"], ["image/x-portable-anymap"]],
'image/x-portable-graymap' => [["pgm"], ["image/x-portable-anymap"]],
'image/x-portable-pixmap' => [["ppm"], ["image/x-portable-anymap"]],
'image/x-psd' => [["psd"], []],
'image/x-quicktime' => [["qif", "qtif"], []],
'image/x-rgb' => [["rgb"], []],
'image/x-sgi' => [["sgi"], []],
'image/x-sigma-x3f' => [["x3f"], ["image/x-dcraw"]],
'image/x-skencil' => [["sk", "sk1"], []],
'image/x-sony-arw' => [["arw"], ["image/tiff", "image/x-dcraw"]],
'image/x-sony-sr2' => [["sr2"], ["image/tiff", "image/x-dcraw"]],
'image/x-sony-srf' => [["srf"], ["image/tiff", "image/x-dcraw"]],
'image/x-sun-raster' => [["sun"], []],
'image/x-tga' => [["icb", "tga", "tpic", "vda", "vst"], []],
'image/x-win-bitmap' => [["cur"], []],
'image/x-wmf' => [["wmf"], []],
'image/x-xbitmap' => [["xbm"], []],
'image/x-xcf' => [["xcf"], []],
'image/x-xfig' => [["fig"], []],
'image/x-xpixmap' => [["xpm"], []],
'image/x-xwindowdump' => [["xwd"], []],
'model/vrml' => [["wrl"], ["text/plain"]],
'text/calendar' => [["ics", "vcs"], ["text/plain"]],
'text/css' => [["css", "cssl"], ["text/x-csrc"]],
'text/csv' => [["csv"], ["text/plain"]],
'text/directory' => [["gcrd", "vcf", "vct"], ["text/plain"]],
'text/html' => [["htm", "html"], ["text/plain"]],
'text/mathml' => [["mml"], ["application/xml"]],
'text/plain' => [["asc", "txt"], []],
'text/rdf' => [["owl", "rdf", "rdfs"], ["application/xml"]],
'text/richtext' => [["rtx"], ["text/plain"]],
'text/sgml' => [["sgm", "sgml"], ["text/plain"]],
'text/spreadsheet' => [["slk", "sylk"], ["text/plain"]],
'text/tab-separated-values' => [["tsv"], ["text/plain"]],
'text/troff' => [["roff", "t", "tr"], ["text/plain"]],
'text/vnd.rn-realtext' => [["rt"], []],
'text/vnd.sun.j2me.app-descriptor' => [["jad"], []],
'text/vnd.wap.wml' => [["wml"], ["application/xml"]],
'text/vnd.wap.wmlscript' => [["wmls"], []],
'text/x-adasrc' => [["adb", "ads"], ["text/plain"]],
'text/x-bibtex' => [["bib"], ["text/plain"]],
'text/x-c++hdr' => [["h++", "hh", "hp", "hpp", "hxx"], ["text/x-chdr"]],
'text/x-c++src' => [["c", "c++", "cc", "cpp", "cxx"], ["text/x-csrc"]],
'text/x-chdr' => [["h"], ["text/x-csrc"]],
'text/x-cmake' => [["cmake"], []],
'text/x-csharp' => [["cs"], ["text/x-csrc"]],
'text/x-csrc' => [["c"], ["text/plain"]],
'text/x-dcl' => [["dcl"], ["text/plain"]],
'text/x-dsl' => [["dsl"], ["text/plain"]],
'text/x-dsrc' => [["d"], ["text/plain"]],
'text/x-eiffel' => [["e", "eif"], ["text/plain"]],
'text/x-emacs-lisp' => [["el"], ["text/plain"]],
'text/x-erlang' => [["erl"], ["text/plain"]],
'text/x-fortran' => [["f", "f90", "f95", "for"], ["text/plain"]],
'text/x-gettext-translation' => [["po"], ["text/plain"]],
'text/x-gettext-translation-template' => [["pot"], ["text/plain"]],
'text/x-google-video-pointer' => [["gvp"], []],
'text/x-haskell' => [["hs"], ["text/plain"]],
'text/x-iMelody' => [["ime", "imy"], []],
'text/x-idl' => [["idl"], ["text/plain"]],
'text/x-iptables' => [["iptables"], ["text/plain"]],
'text/x-java' => [["java"], ["text/x-csrc"]],
'text/x-ldif' => [["ldif"], ["text/plain"]],
'text/x-lilypond' => [["ly"], ["text/plain"]],
'text/x-literate-haskell' => [["lhs"], ["text/plain"]],
'text/x-log' => [["log"], ["text/plain"]],
'text/x-lua' => [["lua"], ["application/x-executable", "text/plain"]],
'text/x-matlab' => [["m"], ["text/plain"]],
'text/x-microdvd' => [["sub"], ["text/plain"]],
'text/x-moc' => [["moc"], ["text/plain"]],
'text/x-mof' => [["mof"], ["text/x-csrc"]],
'text/x-mpsub' => [["sub"], ["text/plain"]],
'text/x-mrml' => [["mrl", "mrml"], []],
'text/x-ms-regedit' => [["reg"], ["text/plain"]],
'text/x-mup' => [["mup", "not"], ["text/plain"]],
'text/x-nfo' => [["nfo"], ["text/x-readme"]],
'text/x-objcsrc' => [["m"], ["text/x-csrc"]],
'text/x-ocaml' => [["ml", "mli"], []],
'text/x-ocl' => [["ocl"], ["text/plain"]],
'text/x-opml+xml' => [["opml"], ["application/xml"]],
'text/x-pascal' => [["p", "pas"], ["text/plain"]],
'text/x-patch' => [["diff", "patch"], ["text/plain"]],
'text/x-python' => [["py"], ["application/x-executable", "text/plain"]],
'text/x-rpm-spec' => [["spec"], ["text/plain"]],
'text/x-scheme' => [["scm"], ["text/plain"]],
'text/x-setext' => [["etx"], ["text/plain"]],
'text/x-sql' => [["sql"], ["text/plain"]],
'text/x-ssa' => [["ass", "ssa"], ["text/plain"]],
'text/x-subviewer' => [["sub"], ["text/plain"]],
'text/x-tcl' => [["tcl", "tk"], ["text/plain"]],
'text/x-tex' => [["cls", "dtx", "ins", "latex", "ltx", "sty", "tex"], ["text/plain"]],
'text/x-texinfo' => [["texi", "texinfo"], ["text/plain"]],
'text/x-troff-me' => [["me"], ["text/plain"]],
'text/x-troff-mm' => [["mm"], ["text/plain"]],
'text/x-troff-ms' => [["ms"], ["text/plain"]],
'text/x-txt2tags' => [["t2t"], ["text/plain"]],
'text/x-uil' => [["uil"], ["text/plain"]],
'text/x-uri' => [["uri", "url"], ["text/plain"]],
'text/x-vala' => [["vala"], ["text/x-csrc"]],
'text/x-vhdl' => [["vhd", "vhdl"], ["text/plain"]],
'text/x-xmi' => [["xmi"], ["application/xml"]],
'text/x-xslfo' => [["fo", "xslfo"], ["application/xml"]],
'video/3gpp' => [["3g2", "3ga", "3gp", "3gpp"], ["video/mp4"]],
'video/dv' => [["dv"], []],
'video/mp4' => [["m4v", "mp4"], []],
'video/mpeg' => [["m2t", "mp2", "mpe", "mpeg", "mpg", "vob"], []],
'video/ogg' => [["ogv"], ["application/ogg"]],
'video/quicktime' => [["moov", "mov", "qt", "qtvr"], []],
'video/vivo' => [["viv", "vivo"], []],
'video/vnd.rn-realvideo' => [["rv", "rvx"], []],
'video/x-flic' => [["flc", "fli"], []],
'video/x-flv' => [["flv"], []],
'video/x-matroska' => [["mkv"], ["application/x-matroska"]],
'video/x-mng' => [["mng"], []],
'video/x-ms-asf' => [["asf"], []],
'video/x-ms-wmv' => [["wmv"], ["video/x-ms-asf"]],
'video/x-msvideo' => [["avi", "divx"], []],
'video/x-nsv' => [["nsv"], []],
'video/x-ogm+ogg' => [["ogm"], ["video/ogg"]],
'video/x-sgi-movie' => [["movie"], []],
'video/x-theora+ogg' => [["ogg"], ["video/ogg"]],
'x-epoc/x-sisx-app' => [["sisx"], []],
}
MAGIC = [
['application/vnd.stardivision.writer', [[2089, "StarWriter"]]],
['image/x-eps', [[0, "%!", [[15, "EPS"]]], [0, "\x04%!", [[16, "EPS"]]]]],
['application/docbook+xml', [[0, "<?xml", [[0..100, "-//OASIS//DTD DocBook XML"], [0..100, "-//KDE//DTD DocBook XML"]]]]],
['application/x-java-archive', [[0, "PK\x03\x04", [[40, "\xFE\xCA"]]]]],
['application/smil', [[0..256, "<smil"]]],
['image/x-niff', [[0, "IIN1"]]],
['application/prs.plucker', [[60, "DataPlkr"]]],
['application/x-mozilla-bookmarks', [[0..64, "<!DOCTYPE NETSCAPE-Bookmark-file-1>"]]],
['image/svg+xml', [[0..256, "<!DOCTYPE svg"], [0..256, "<svg"]]],
['image/x-kodak-kdc', [[242, "EASTMAN KODAK COMPANY"]]],
['audio/x-vorbis+ogg', [[0, "OggS", [[28, "\x01vorbis"]]]]],
['application/vnd.corel-draw', []],
['application/x-php', [[0..64, "<?php"]]],
['application/x-xliff', [[0..256, "<xliff"]]],
['application/x-pak', [[0, "PACK"]]],
['audio/x-flac+ogg', [[0, "OggS", [[28, "fLaC"]]], [0, "OggS", [[28, "\x7FFLAC"]]]]],
['video/x-theora+ogg', [[0, "OggS", [[28, "\x80theora"]]]]],
['audio/x-speex+ogg', [[0, "OggS", [[28, "Speex "]]]]],
['video/x-ogm+ogg', [[0, "OggS", [[29, "video"]]]]],
['application/rss+xml', [[0..256, "<rss "], [0..256, "<RSS "]]],
['text/x-opml+xml', [[0..256, "<opml "]]],
['application/atom+xml', [[0..256, "<feed "]]],
['text/x-txt2tags', [[0, "%!postproc"], [0, "%!encoding"]]],
['application/x-quicktime-media-link', [[0, "<?xml", [[0..64, "<?quicktime"]]], [0, "RTSPtext"], [0, "rtsptext"], [0, "SMILtext"]]],
['application/x-font-type1', [[0, "LWFN"], [65, "LWFN"], [0, "%!PS-AdobeFont-1."], [6, "%!PS-AdobeFont-1."], [0, "%!FontType1-1."], [6, "%!FontType1-1."]]],
['audio/x-ms-asx', [[0, "ASF "], [0..64, "<ASX"], [0..64, "<asx"], [0..64, "<Asx"]]],
['audio/x-wav', [[8, "WAVE"], [8, "WAV "]]],
['application/gnunet-directory', [[0, "\x89GND\r\n\x1A\n"]]],
['video/x-sgi-movie', [[0, "MOVI"]]],
['application/sdp', [[0, "v=", [[0..256, "s="]]]]],
['video/x-nsv', [[0, "NSVf"]]],
['video/x-msvideo', [[0, "RIFF", [[8, "AVI "]]]]],
['application/x-netshow-channel', [[0, "[Address]"]]],
['video/x-ms-asf', [[0, "0&\xB2u"], [0, "[Reference]"]]],
['application/x-hwp', [[0, "HWP Document File"]]],
['video/x-flic', [[0, "\x11\xAF"], [0, "\x12\xAF"]]],
['image/x-quicktime', [[4, "idat"]]],
['video/quicktime', [[12, "mdat"], [4, "mdat"], [4, "moov"], [4, "ftypqt"]]],
['application/vnd.oasis.opendocument.text', [[0, "PK\x03\x04", [[30, "mimetype", [[38, "application/vnd.oasis.opendocument.text"]]]]]]],
['application/vnd.oasis.opendocument.text-template', [[0, "PK\x03\x04", [[30, "mimetype", [[38, "application/vnd.oasis.opendocument.text-template"]]]]]]],
['application/vnd.oasis.opendocument.text-web', [[0, "PK\x03\x04", [[30, "mimetype", [[38, "application/vnd.oasis.opendocument.text-web"]]]]]]],
['application/vnd.oasis.opendocument.text-master', [[0, "PK\x03\x04", [[30, "mimetype", [[38, "application/vnd.oasis.opendocument.text-master"]]]]]]],
['application/vnd.oasis.opendocument.graphics', [[0, "PK\x03\x04", [[30, "mimetype", [[38, "application/vnd.oasis.opendocument.graphics"]]]]]]],
['application/vnd.oasis.opendocument.graphics-template', [[0, "PK\x03\x04", [[30, "mimetype", [[38, "application/vnd.oasis.opendocument.graphics-template"]]]]]]],
['application/vnd.oasis.opendocument.presentation', [[0, "PK\x03\x04", [[30, "mimetype", [[38, "application/vnd.oasis.opendocument.presentation"]]]]]]],
['application/vnd.oasis.opendocument.presentation-template', [[0, "PK\x03\x04", [[30, "mimetype", [[38, "application/vnd.oasis.opendocument.presentation-template"]]]]]]],
['application/vnd.oasis.opendocument.spreadsheet', [[0, "PK\x03\x04", [[30, "mimetype", [[38, "application/vnd.oasis.opendocument.spreadsheet"]]]]]]],
['application/vnd.oasis.opendocument.spreadsheet-template', [[0, "PK\x03\x04", [[30, "mimetype", [[38, "application/vnd.oasis.opendocument.spreadsheet-template"]]]]]]],
['application/vnd.oasis.opendocument.chart', [[0, "PK\x03\x04", [[30, "mimetype", [[38, "application/vnd.oasis.opendocument.chart"]]]]]]],
['application/vnd.oasis.opendocument.formula', [[0, "PK\x03\x04", [[30, "mimetype", [[38, "application/vnd.oasis.opendocument.formula"]]]]]]],
['application/vnd.oasis.opendocument.image', [[0, "PK\x03\x04", [[30, "mimetype", [[38, "application/vnd.oasis.opendocument.image"]]]]]]],
['application/vnd.symbian.install', [[8, "\x19\x04\x00\x10"]]],
['x-epoc/x-sisx-app', [[0, "z\x1A \x10"]]],
['application/vnd.wordperfect', [[1, "WPC"]]],
['application/x-xbel', [[0..256, "<!DOCTYPE xbel"]]],
['application/x-abiword', [[0..256, "<abiword"], [0..256, "<!DOCTYPE abiword"]]],
['application/x-applix-spreadsheet', [[0, "*BEGIN SPREADSHEETS"], [0, "*BEGIN", [[7, "SPREADSHEETS"]]]]],
['application/x-applix-word', [[0, "*BEGIN", [[7, "WORDS"]]]]],
['application/x-arc', []],
['video/mpeg', [[0, "G?\xFF\x10"], [0, "\x00\x00\x01\xB3"], [0, "\x00\x00\x01\xBA"]]],
['application/x-arj', [[0, "`\xEA"]]],
['application/x-awk', [[0, "#!/bin/gawk"], [0, "#! /bin/gawk"], [0, "#!/usr/bin/gawk"], [0, "#! /usr/bin/gawk"], [0, "#!/usr/local/bin/gawk"], [0, "#! /usr/local/bin/gawk"], [0, "#!/bin/awk"], [0, "#! /bin/awk"], [0, "#!/usr/bin/awk"], [0, "#! /usr/bin/awk"]]],
['application/x-bittorrent', [[0, "d8:announce"]]],
['application/x-blender', [[0, "BLENDER"]]],
['application/x-bzip', [[0, "BZh"]]],
['application/x-cdrdao-toc', [[0, "CD_ROM\n"], [0, "CD_DA\n"], [0, "CD_ROM_XA\n"], [0, "CD_TEXT "], [0, "CATALOG \"", [[22, "\""]]]]],
['application/x-chess-pgn', [[0, "[Event "]]],
['application/x-compress', [[0, "\x1F\x9D"]]],
['application/x-core', [[0, "\x7FELF", [[5, "\x01", [[16, "\x04\x00"]]]]], [0, "\x7FELF", [[5, "\x02", [[16, "\x00\x04"]]]]], [0, "Core\x01"], [0, "Core\x02"]]],
['application/x-cpio', [[0, "\xC7q"], [0, "070701"], [0, "070702"], [0, "q\xC7"]]],
['video/dv', []],
['application/x-deb', [[0, "!<arch>", [[8, "debian"]]]]],
['application/x-desktop', [[0..32, "[Desktop Entry]"], [0, "[Desktop Action"], [0, "[KDE Desktop Entry]"], [0, "# Config File"], [0, "# KDE Config File"]]],
['application/x-dia-diagram', [[5..100, "<dia:"]]],
['application/x-dvi', [[0, "\xF7\x02"]]],
['text/xmcd', [[0, "# xmcd"]]],
['application/x-fluid', [[0, "# data file for the Fltk"], [0, "version"], [0, "header_name"], [0, "code_name"]]],
['application/msword', [[0, "1\xBE\x00\x00"], [0, "PO^Q`"], [0, "\xFE7\x00#"], [0, "\xDB\xA5-\x00\x00\x00"], [2112, "MSWordDoc"], [2108, "MSWordDoc"], [2112, "Microsoft Word document data"]]],
['application/x-font-bdf', [[0, "STARTFONT "]]],
['application/x-font-dos', [[0, "\xFFFON"], [7, "\x00EGA"], [7, "\x00VID"]]],
['application/x-font-framemaker', [[0, "<MakerScreenFont"]]],
['application/x-font-libgrx', [[0, "\x14\x02Y\x19"]]],
['application/x-font-linux-psf', [[0, "6\x04"]]],
['application/x-font-pcf', [[0, "\x01fcp"]]],
['application/x-font-otf', [[0, "OTTO"]]],
['application/x-font-speedo', [[0, "D1.0\r"]]],
['application/x-font-sunos-news', [[0, "StartFont"], [0, "\x13z)"], [8, "\x13z+"]]],
['application/x-font-tex', [[0, "\xF7\x83"], [0, "\xF7Y"], [0, "\xF7\xCA"]]],
['application/x-font-tex-tfm', [[2, "\x00\x11"], [2, "\x00\x12"]]],
['application/x-font-ttf', [[0, "FFIL"], [65, "FFIL"], [0, "\x00\x01\x00\x00\x00"]]],
['application/x-font-ttx', [[0..256, "<ttFont sfntVersion=\"\\x00\\x01\\x00\\x00\" ttLibVersion=\""]]],
['application/x-font-vfont', [[0, "FONT"]]],
['application/x-frame', [[0, "<MakerFile"], [0, "<MIFFile"], [0, "<MakerDictionary"], [0, "<MakerScreenFon"], [0, "<MML"], [0, "<Book"], [0, "<Maker"]]],
['application/x-gdbm', [[0, "\x13W\x9A\xCE"], [0, "\xCE\x9AW\x13"], [0, "GDBM"]]],
['application/x-glade', [[0..256, "<glade-interface"]]],
['application/x-gmc-link', [[0..32, "URL:"]]],
['application/x-gnumeric', [[0..64, "gmr:Workbook"], [0..64, "gnm:Workbook"]]],
['application/x-gtktalog', [[4, "gtktalog "]]],
['application/x-gzip', [[0, "\x1F\x8B"]]],
['application/x-ipod-firmware', [[0, "S T O P"]]],
['application/vnd.ms-excel', [[2080, "Microsoft Excel 5.0 Worksheet"]]],
['application/x-java', [[0, "\xCA\xFE\xBA\xBE"]]],
['application/x-java-jnlp-file', [[0..256, "<jnlp"]]],
['application/x-java-pack200', [[0, "\xCA\xFE\xD0\r"]]],
['application/x-karbon', [[0, "\x1F\x8B", [[10, "KOffice", [[18, "application/x-karbon\x04\x06"]]]]], [0, "PK\x03\x04", [[30, "mimetype", [[38, "application/x-karbon"]]]]]]],
['application/x-kchart', [[0, "\x1F\x8B", [[10, "KOffice", [[18, "application/x-kchart\x04\x06"]]]]], [0, "PK\x03\x04", [[30, "mimetype", [[38, "application/x-kchart"]]]]]]],
['application/x-kformula', [[0, "\x1F\x8B", [[10, "KOffice", [[18, "application/x-kformula\x04\x06"]]]]], [0, "PK\x03\x04", [[30, "mimetype", [[38, "application/x-kformula"]]]]]]],
['application/x-killustrator', [[0, "\x1F\x8B", [[10, "KOffice", [[18, "application/x-killustrator\x04\x06"]]]]]]],
['text/x-ms-regedit', [[0, "REGEDIT"], [0, "Windows Registry Editor Version 5.00"], [0, "\xFF\xFEW\x00i\x00n\x00d\x00o\x00w\x00s\x00 \x00R\x00e\x00g\x00i\x00s\x00t\x00r\x00y\x00 \x00E\x00d\x00i\x00t\x00o\x00r\x00"]]],
['application/x-kontour', [[0, "\x1F\x8B", [[10, "KOffice", [[18, "application/x-kontour\x04\x06"]]]]], [0, "PK\x03\x04", [[30, "mimetype", [[38, "application/x-kontour"]]]]]]],
['application/x-kpresenter', [[0, "\x1F\x8B", [[10, "KOffice", [[18, "application/x-kpresenter\x04\x06"]]]]], [0, "PK\x03\x04", [[30, "mimetype", [[38, "application/x-kpresenter"]]]]]]],
['application/x-krita', [[0, "\x1F\x8B", [[10, "KOffice", [[18, "application/x-krita\x04\x06"]]]]], [0, "PK\x03\x04", [[30, "mimetype", [[38, "application/x-krita"]]]]]]],
['application/x-kspread', [[0, "\x1F\x8B", [[10, "KOffice", [[18, "application/x-kspread\x04\x06"]]]]], [0, "PK\x03\x04", [[30, "mimetype", [[38, "application/x-kspread"]]]]]]],
['application/x-kspread-crypt', [[0, "\r\x1A'\x02"]]],
['application/x-ksysv-package', [[4, "KSysV", [[15, "\x01"]]]]],
['application/x-kword', [[0, "\x1F\x8B", [[10, "KOffice", [[18, "application/x-kword\x04\x06"]]]]], [0, "PK\x03\x04", [[30, "mimetype", [[38, "application/x-kword"]]]]]]],
['application/x-kword-crypt', [[0, "\r\x1A'\x01"]]],
['application/x-lha', [[2, "-lh -"], [2, "-lh0-"], [2, "-lh1-"], [2, "-lh2-"], [2, "-lh3-"], [2, "-lh4-"], [2, "-lh5-"], [2, "-lh40-"], [2, "-lhd-"], [2, "-lz4-"], [2, "-lz5-"], [2, "-lzs-"]]],
['application/x-lyx', [[0, "#LyX"]]],
['application/x-macbinary', [[102, "mBIN"]]],
['application/x-matroska', [[8, "matroska"]]],
['application/vnd.ms-access', [[0, "\x00\x01\x00\x00Standard Jet DB"]]],
['application/x-ms-dos-executable', [[0, "MZ"]]],
['application/x-mswinurl', [[1, "InternetShortcut"], [1, "DEFAULT", [[10, "BASEURL="]]]]],
['application/x-nautilus-link', [[0..32, "<nautilus_object nautilus_link"]]],
['application/x-object', [[0, "\x7FELF", [[5, "\x01", [[16, "\x01\x00"]]]]], [0, "\x7FELF", [[5, "\x02", [[16, "\x00\x01"]]]]]]],
['application/ogg', [[0, "OggS"]]],
['audio/ogg', [[0, "OggS"]]],
['video/ogg', [[0, "OggS"]]],
['application/vnd.lotus-1-2-3', [[0, "\x00\x00\x02\x00\x06\x04\x06\x00\b\x00\x00\x00\x00\x00"]]],
['application/x-go-sgf', [[0, "(;FF[3]"], [0, "(;FF[4]"]]],
['video/x-flv', [[0, "FLV"]]],
['audio/x-speex', [[0, "Speex"]]],
['application/x-gedcom', [[0, "0 HEAD"]]],
['application/vnd.emusic-emusic_package', [[0, "nF7YLao"]]],
['application/x-ole-storage', [[0, "\xD0\xCF\x11\xE0\xA1\xB1\x1A\xE1"], [0, "\xD0\xCF\x11\xE0"]]],
['application/x-msi', [[0, "\xD0\xCF\x11\xE0\xA1\xB1\x1A\xE1\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00>\x00\x03\x00\xFE\xFF\t\x00\x06"]]],
['application/x-oleo', [[31, "Oleo"]]],
['application/x-t602', [[0, "@CT 0"], [0, "@CT 1"], [0, "@CT 2"]]],
['application/x-par2', [[0, "PAR2"]]],
['application/x-pef-executable', [[0, "Joy!"]]],
['application/x-perl', [[0, "eval \"exec /usr/local/bin/perl"], [1..16, "/bin/perl"], [1..16, "/bin/env perl"]]],
['application/rtf', [[0, "{\\rtf"]]],
['application/x-python-bytecode', [[0, "\x99N\r\n"]]],
['application/epub+zip', [[0, "PK\x03\x04", [[30, "mimetype", [[38, "application/epub+zip"]]]]]]],
['application/x-rar', [[0, "Rar!"]]],
['text/x-iptables', [[0..256, "/etc/sysconfig/iptables"], [0..256, "*filter", [[0..256, ":INPUT", [[0..256, ":FORWARD", [[0..256, ":OUTPUT"]]]]]]], [0..256, "-A INPUT", [[0..256, "-A FORWARD", [[0..256, "-A OUTPUT"]]]]], [0..256, "-P INPUT", [[0..256, "-P FORWARD", [[0..256, "-P OUTPUT"]]]]]]],
['application/x-alz', [[0, "ALZ"]]],
['application/x-rpm', [[0, "\xED\xAB\xEE\xDB"]]],
['text/x-tex', [[1, "documentclass"]]],
['application/x-sc', [[38, "Spreadsheet"]]],
['application/x-sharedlib', [[0, "\x7FELF", [[5, "\x01", [[16, "\x03\x00"]]]]], [0, "\x7FELF", [[5, "\x02", [[16, "\x00\x03"]]]]], [0, "\x83\x01"]]],
['application/x-shellscript', [[10, "# This is a shell archive"], [1..16, "/bin/bash"], [1..16, "/bin/nawk"], [1..16, "/bin/zsh"], [1..16, "/bin/sh"], [1..16, "/bin/ksh"], [0, "#!/usr/bin/env sh"], [0, "#!/usr/bin/env bash"], [0, "#!/usr/bin/env zsh"], [0, "#!/usr/bin/env ksh"]]],
['application/x-shockwave-flash', [[0, "FWS"], [0, "CWS"]]],
['application/x-shorten', [[0, "ajkg"]]],
['image/x-skencil', [[0, "##Sketch"]]],
['application/x-stuffit', [[0, "StuffIt "], [0, "SIT!"]]],
['application/x-subrip', [[0, "1", [[0..256, " --> "]]]]],
['application/x-sami', [[0..256, "<SAMI>"]]],
['text/x-microdvd', [[0, "{1}"], [0, "{0}"], [0..6, "}{"]]],
['text/x-mpsub', [[0..256, "FORMAT="]]],
['text/x-ssa', [[0..256, "[Script Info]"], [0..256, "Dialogue: "]]],
['text/x-subviewer', [[0, "[INFORMATION]"]]],
['text/x-iMelody', [[0, "BEGIN:IMELODY"]]],
['application/x-smaf', [[0, "MMMD"]]],
['text/x-mrml', [[0, "<mrml "]]],
['audio/x-xmf', [[0, "XMF_"], [0, "XMF_2.00\x00\x00\x00\x02"]]],
['application/x-tar', [[257, "ustar\x00"], [257, "ustar \x00"]]],
['application/x-tgif', [[0, "%TGIF"]]],
['text/troff', [[0, ".\\\""], [0, "'\\\""], [0, "'.\\\""], [0, "\\\""]]],
['application/x-zoo', [[20, "\xDC\xA7\xC4\xFD"]]],
['text/x-rpm-spec', [[0, "Summary: "], [0, "%define "]]],
['audio/ac3', [[0, "\vw"]]],
['audio/AMR', [[0, "#!AMR\n"], [0, "#!AMR_MC1.0\n"]]],
['audio/AMR-WB', [[0, "#!AMR-WB\n"], [0, "#!AMR-WB_MC1.0\n"]]],
['text/x-lua', [[0, "/bin/lua"], [0, "/bin/env lua"]]],
['audio/prs.sid', [[0, "PSID"]]],
['audio/x-adpcm', [[0, ".snd", [[12, "\x00\x00\x00\x17"]]], [0, ".sd\x00", [[12, "\x01\x00\x00\x00"], [12, "\x02\x00\x00\x00"], [12, "\x03\x00\x00\x00"], [12, "\x04\x00\x00\x00"], [12, "\x05\x00\x00\x00"], [12, "\x06\x00\x00\x00"], [12, "\a\x00\x00\x00"], [12, "\x17\x00\x00\x00"]]]]],
['audio/x-aifc', [[8, "AIFC"]]],
['audio/x-aiff', [[8, "AIFF"], [8, "AIFC"], [8, "8SVX"]]],
['audio/x-ape', [[0, "MAC "]]],
['audio/x-it', [[0, "IMPM"]]],
['audio/x-wavpack', [[0, "wvpk"]]],
['audio/x-wavpack-correction', [[0, "wvpk"]]],
['audio/midi', [[0, "MThd"]]],
['audio/x-mo3', [[0, "MO3"]]],
['audio/mp4', [[4, "ftypM4A"]]],
['video/mp4', [[4, "ftypisom"], [4, "ftypmp42"]]],
['audio/x-m4b', [[4, "ftypM4B"]]],
['video/3gpp', [[4, "ftyp3gp"]]],
['audio/mpeg', [[0, "\x00\x00\xFF\xFB"], [0, "ID3"]]],
['audio/x-mpegurl', [[0, "#EXTM3U"]]],
['application/postscript', [[0, "\x04%!"], [0, "%!"]]],
['audio/x-psf', [[0, "PSF"]]],
['audio/x-musepack', [[0, "MP+"]]],
['text/x-python', [[0, "#!/bin/python"], [0, "#! /bin/python"], [0, "eval \"exec /bin/python"], [0, "#!/usr/bin/python"], [0, "#! /usr/bin/python"], [0, "eval \"exec /usr/bin/python"], [0, "#!/usr/local/bin/python"], [0, "#! /usr/local/bin/python"], [0, "eval \"exec /usr/local/bin/python"], [1..16, "/bin/env python"]]],
['audio/x-s3m', [[44, "SCRM"]]],
['audio/x-scpls', [[0, "[playlist]"], [0, "[Playlist]"], [0, "[PLAYLIST]"]]],
['application/vnd.ms-tnef', [[0, "x\x9F>\""]]],
['audio/x-xi', [[0, "Extended Intrument:"]]],
['audio/x-xm', [[0, "Extended Module:"]]],
['audio/x-tta', [[0, "TTA1"]]],
['image/bmp', [[0, "BM", [[14, "\f"], [14, "@"], [14, "("]]]]],
['image/gif', [[0, "GIF8"]]],
['image/jpeg', [[0, "\xFF\xD8\xFF"], [0, "\xFF\xD8"]]],
['image/jp2', [[4, "jP"], [0, "\xFFO\xFFQ\x00"], [3, "\fjP "]]],
['image/x-dds', [[0, "DDS"]]],
['image/x-xcursor', [[0, "Xcur"]]],
['image/x-exr', [[0, "v/1\x01"]]],
['image/x-canon-crw', [[0, "II\x1A\x00\x00\x00HEAPCCDR"]]],
['image/x-fuji-raf', [[0, "FUJIFILMCCD-RAW "]]],
['application/pgp-signature', [[0, "-----BEGIN PGP SIGNED MESSAGE-----"], [0, "-----BEGIN PGP SIGNATURE-----"]]],
['image/x-minolta-mrw', [[0, "\x00MRM"]]],
['image/x-olympus-orf', [[0, "IIRO\b\x00\x00\x00"]]],
['image/x-panasonic-raw', [[0, "IIU\x00\b\x00\x00\x00"]]],
['image/x-sigma-x3f', [[0, "FOVb"]]],
['image/png', [[0, "\x89PNG"]]],
['application/pgp-keys', [[0, "-----BEGIN PGP PUBLIC KEY BLOCK-----"], [0, "-----BEGIN PGP PRIVATE KEY BLOCK-----"], [0, "\x95\x01"], [0, "\x95\x00"], [0, "\x99\x00"], [0, "\x99\x01"]]],
['image/tiff', [[0, "MM\x00*"], [0, "II*\x00"]]],
['image/vnd.dxf', [[0..64, "\nHEADER\n"], [0..64, "\r\nHEADER\r\n"]]],
['image/x-applix-graphics', [[0, "*BEGIN", [[7, "GRAPHICS"]]]]],
['application/dicom', [[128, "DICM"]]],
['application/pgp-encrypted', [[0, "-----BEGIN PGP MESSAGE-----"]]],
['image/x-dib', [[0, "(\x00\x00\x00"]]],
['image/vnd.djvu', [[0, "AT&TFORM", [[12, "DJVM"], [12, "DJVU"]]], [0, "FORM", [[8, "DJVM"], [8, "DJVU"]]]]],
['image/dpx', [[0, "SDPX"]]],
['audio/x-iriver-pla', [[4, "iriver UMS PLA"]]],
['image/x-fits', [[0, "SIMPLE ="]]],
['image/x-fpx', [[0, "FPix"]]],
['image/x-ico', [[0, "\x00\x00\x01\x00", [[5, "\x00"]]]]],
['image/x-icns', [[0, "icns"]]],
['application/xspf+xml', [[0..64, "<playlist version=\"1"]]],
['image/x-pcx', [[0, "\n", [[1, "\x00"], [1, "\x02"], [1, "\x03"], [1, "\x05"]]]]],
['image/x-portable-bitmap', [[0, "P1", [[2, "\n", [[3, "#"]]]]], [0, "P4", [[2, "\n", [[3, "#"]]]]]]],
['image/x-portable-graymap', [[0, "P2", [[2, "\n", [[3, "#"]]]]], [0, "P5", [[2, "\n", [[3, "#"]]]]]]],
['image/x-portable-pixmap', [[0, "P3", [[2, "\n", [[3, "#"]]]]], [0, "P6", [[2, "\n", [[3, "#"]]]]]]],
['image/x-psd', []],
['image/x-sun-raster', [[0, "Y\xA6j\x95"]]],
['text/x-patch', [[0, "diff\t"], [0, "diff "], [0, "***\t"], [0, "*** "], [0, "=== "], [0, "--- "], [0, "Only in\t"], [0, "Only in "], [0, "Common subdirectories: "], [0, "Index:"]]],
['image/x-win-bitmap', [[0, "\x00\x00\x02\x00", [[5, "\x00"]]]]],
['application/x-navi-animation', [[0, "RIFF", [[8, "ACON"]]]]],
['image/x-emf', [[0, "\x01\x00\x00\x00", [[40, " EMF", [[44, "\x00\x00\x01\x00", [[58, "\x00\x00"]]]]]]]]],
['image/x-wmf', [[0, "\xD7\xCD\xC6\x9A", [[22, "\x01\x00", [[24, "\t\x00"]]]]], [0, "\x01\x00", [[2, "\t\x00"]]]]],
['image/x-xfig', [[0, "#FIG"]]],
['image/x-xpixmap', [[0, "/* XPM"]]],
['message/news', [[0, "Article"], [0, "Path:"], [0, "Xref:"]]],
['message/rfc822', [[0, "#! rnews"], [0, "Forward to"], [0, "From:"], [0, "N#! rnews"], [0, "Pipe to"], [0, "Received:"], [0, "Relay-Version:"], [0, "Return-Path:"], [0, "Return-path:"], [0, "Subject: "]]],
['text/calendar', [[0, "BEGIN:VCALENDAR"], [0, "begin:vcalendar"]]],
['text/directory', [[0, "BEGIN:VCARD"], [0, "begin:vcard"]]],
['application/pdf', [[0, "%PDF-"]]],
['text/x-matlab', [[0, "function"]]],
['text/plain', [[0, "This is TeX,"], [0, "This is METAFONT,"]]],
['application/x-cisco-vpn-settings', [[0, "[main]"]]],
['application/mathematica', [[0, "(************** Content-type: application/mathematica"], [100..256, "This notebook can be used on any computer system with Mathematica"], [10..256, "This is a Mathematica Notebook file. It contains ASCII text"]]],
['application/mac-binhex40', [[11, "must be converted with BinHex"]]],
['text/spreadsheet', [[0, "ID;"]]],
['text/vnd.sun.j2me.app-descriptor', [[0, "MIDlet-"]]],
['application/x-ace', [[7, "**ACE**"]]],
['text/x-mup', [[0, "//!Mup"]]],
['text/x-emacs-lisp', [[0, "\n("], [0, ";ELC\x13\x00\x00\x00"]]],
['text/html', [[0..256, "<!DOCTYPE HTML"], [0..256, "<!doctype html"], [0..256, "<HEAD"], [0..256, "<head"], [0..256, "<TITLE"], [0..256, "<title"], [0..256, "<HTML"], [0..256, "<html"], [0..256, "<SCRIPT"], [0..256, "<script"], [0, "<BODY"], [0, "<body"], [0, "<!--"], [0, "<h1"], [0, "<H1"], [0, "<!doctype HTML"], [0, "<!DOCTYPE html"]]],
['text/x-google-video-pointer', [[0, "#.download.the.free.Google.Video.Player"], [0, "# download the free Google Video Player"]]],
['text/x-ldif', [[0, "dn: cn="], [0, "dn: mail="]]],
['text/x-makefile', [[0, "#!/usr/bin/make"], [0, "#! /usr/bin/make"]]],
['application/x-kivio', [[0, "\x1F\x8B", [[10, "KOffice", [[18, "application/x-kivio\x04\x06"]]]]], [0, "PK\x03\x04", [[30, "mimetype", [[38, "application/x-kivio"]]]]]]],
['application/x-archive', [[0, "<ar>"], [0, "!<arch>"]]],
['audio/x-riff', [[0, "RIFF"]]],
['application/x-executable', [[0, "\x7FELF", [[5, "\x01", [[16, "\x02\x00"]]]]], [0, "\x7FELF", [[5, "\x02", [[16, "\x00\x02"]]]]], [0, "MZ"], [0, "\x1CR"], [0, "\x10\x01"], [0, "\x11\x01"], [0, "\x83\x01"]]],
['application/xml', [[0, "<?xml"], [0, "<!--"]]],
['audio/basic', [[0, ".snd"]]],
['application/zip', [[0, "PK\x03\x04"]]],
['text/x-csrc', [[0, "/*"], [0, "//"], [0, "#include"]]],
['text/x-objcsrc', [[0, "#import"]]],
['text/x-vhdl', [[0, "--"]]],
['application/mbox', [[0, "From "]]],
['text/x-matlab', [[0, "%"]]],
['text/x-tex', [[0, "%"]]],
['image/x-tga', [[1, "\x01\x01"], [1, "\x019"], [1, "\x00\x03"], [1, "\x00\n"], [1, "\x00\v"], [1, "\x00\x02"]]],
['application/vnd.sun.xml.impress.template', [[0, "PK\x03\x04", [[30, "mimetype", [[38, "application/vnd.sun.xml.impress"]]]]]]],
['application/x-ruby', [[1..16, "/bin/env ruby"], [1..16, "/bin/ruby"]]],
['application/vnd.sun.xml.writer.template', [[0, "PK\x03\x04", [[30, "mimetype", [[38, "application/vnd.sun.xml.writer"]]]]]]],
['application/vnd.sun.xml.writer.global', [[0, "PK\x03\x04", [[30, "mimetype", [[38, "application/vnd.sun.xml.writer"]]]]]]],
['application/x-dar', [[0, "\x00\x00\x00{"]]],
['application/vnd.sun.xml.math', [[0, "PK\x03\x04", [[30, "mimetype", [[38, "application/vnd.sun.xml.math"]]]]]]],
['application/x-csh', [[1..16, "/bin/tcsh"], [1..16, "/bin/csh"], [0, "#!/usr/bin/env csh"], [0, "#!/usr/bin/env tcsh"]]],
['application/vnd.sun.xml.impress', [[0, "PK\x03\x04", [[30, "mimetype", [[38, "application/vnd.sun.xml.impress"]]]]]]],
['application/vnd.sun.xml.draw.template', [[0, "PK\x03\x04", [[30, "mimetype", [[38, "application/vnd.sun.xml.draw"]]]]]]],
['application/vnd.sun.xml.draw', [[0, "PK\x03\x04", [[30, "mimetype", [[38, "application/vnd.sun.xml.draw"]]]]]]],
['application/vnd.sun.xml.calc.template', [[0, "PK\x03\x04", [[30, "mimetype", [[38, "application/vnd.sun.xml.calc"]]]]]]],
['application/vnd.sun.xml.calc', [[0, "PK\x03\x04", [[30, "mimetype", [[38, "application/vnd.sun.xml.calc"]]]]]]],
['application/x-sqlite3', [[0, "SQLite format 3"]]],
['application/x-sqlite2', [[0, "** This file contains an SQLite"]]],
['application/vnd.sun.xml.writer', [[0, "PK\x03\x04", [[30, "mimetype", [[38, "application/vnd.sun.xml.writer"]]]]]]],
]
end
# -*- encoding: utf-8 -*-
Gem::Specification.new do |s|
s.name = %q{mimemagic}
s.version = "0.1"
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
s.authors = ["Daniel Mendler"]
s.date = %q{2009-05-09}
s.email = ["mail@daniel-mendler.de"]
s.files = ["lib/mimemagic.rb", "lib/mimemagic_tables.rb", "test/test_mimemagic.rb", "script/freedesktop.org.xml", "script/generate-mime.rb", "Rakefile"]
s.has_rdoc = true
s.rdoc_options = ["--main", "README.txt"]
s.require_paths = ["lib"]
s.rubyforge_project = %q{mimemagic}
s.rubygems_version = %q{1.3.1}
s.summary = %q{Mime detection by extension or content}
s.test_files = ["test/test_mimemagic.rb"]
if s.respond_to? :specification_version then
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
s.specification_version = 2
if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
s.add_development_dependency(%q<hoe>, [">= 1.8.3"])
else
s.add_dependency(%q<hoe>, [">= 1.8.3"])
end
else
s.add_dependency(%q<hoe>, [">= 1.8.3"])
end
end
This source diff could not be displayed because it is too large. You can view the blob instead.
#!/usr/bin/ruby
require 'rexml/document'
def str2int(s)
return s.to_i(16) if s[0..1].downcase == '0x'
return s.to_i(8) if s[0..0].downcase == '0'
s.to_i(10)
end
def get_matches(parent)
parent.get_elements('match').map {|match|
if match.attributes['mask']
nil
else
type = match.attributes['type']
value = match.attributes['value']
offset = match.attributes['offset'].split(':').map {|x| x.to_i }
offset = offset.size == 2 ? offset[0]..offset[1] : offset[0]
case type
when 'string'
value.gsub!(/\\(x[\dA-Fa-f]{1,2}|0\d{1,3}|\d{1,3}|.)/) { eval("\"\\#{$1}\"") }
when 'big16'
value = str2int(value)
value = ((value >> 8).chr + (value & 0xFF).chr)
when 'big32'
value = str2int(value)
value = (((value >> 24) & 0xFF).chr + ((value >> 16) & 0xFF).chr + ((value >> 8) & 0xFF).chr + (value & 0xFF).chr)
when 'little16'
value = str2int(value)
value = ((value & 0xFF).chr + (value >> 8).chr)
when 'little32'
value = str2int(value)
value = ((value & 0xFF).chr + ((value >> 8) & 0xFF).chr + ((value >> 16) & 0xFF).chr + ((value >> 24) & 0xFF).chr)
when 'host16' # use little endian
value = str2int(value)
value = ((value & 0xFF).chr + (value >> 8).chr)
when 'host32' # use little endian
value = str2int(value)
value = ((value & 0xFF).chr + ((value >> 8) & 0xFF).chr + ((value >> 16) & 0xFF).chr + ((value >> 24) & 0xFF).chr)
when 'byte'
value = str2int(value)
value = value.chr
end
children = get_matches(match)
children.empty? ? [offset, value] : [offset, value, children]
end
}.compact
end
FILE = ARGV[0] || '/usr/share/mime/packages/freedesktop.org.xml'
file = File.new(FILE)
doc = REXML::Document.new(file)
extensions = {}
types = {}
magics = []
doc.each_element('mime-info/mime-type') do |mime|
type = mime.attributes['type']
subclass = mime.get_elements('sub-class-of').map{|x| x.attributes['type']}
exts = mime.get_elements('glob').map{|x| x.attributes['pattern'] =~ /^\*\.([^\[\]]+)$/ ? $1.downcase : nil }.compact
mime.get_elements('magic').each do |magic|
priority = magic.attributes['priority'].to_i
matches = get_matches(magic)
magics << [priority, type, matches]
end
if !exts.empty?
exts.each{|x|
extensions[x] = type if !extensions.include?(x)
}
types[type] = [exts,subclass]
end
end
magics = magics.sort {|a,b| b[0] <=> a[0] }.map {|x| [x[1], x[2]] }
puts "# Generated from #{FILE}"
puts "class MimeMagic"
puts " private"
puts " EXTENSIONS = {"
extensions.keys.sort.each do |key|
puts " '#{key}' => '#{extensions[key]}',"
end
puts " }"
puts " TYPES = {"
types.keys.sort.each do |key|
exts = types[key][0].sort.inspect
parents = types[key][1].sort.inspect
puts " '#{key}' => [#{exts}, #{parents}],"
end
puts " }"
puts " MAGIC = ["
magics.each do |type, matches|
puts " ['#{type}', #{matches.inspect}],"
end
puts " ]"
puts "end"
require 'mimemagic'
class TC_MimeMagic < Test::Unit::TestCase
def test_text?
assert MimeMagic.new('text/plain').text?
assert MimeMagic.new('text/html').text?
assert !MimeMagic.new('application/octet-stream').text?
assert !MimeMagic.new('image/png').text?
end
def test_child_of?
assert MimeMagic.new('text/html').child_of?('text/plain')
assert MimeMagic.new('text/x-java').child_of?('text/plain')
end
def test_extensions
assert_equal %w(htm html), MimeMagic.new('text/html').extensions
end
def test_by_extension
assert_equal 'text/html', MimeMagic.by_extension('html').to_s
assert_equal 'application/x-ruby', MimeMagic.by_extension('rb').to_s
assert_nil MimeMagic.by_extension('crazy')
assert_nil MimeMagic.by_extension('')
end
def test_by_magic
assert_equal 'application/x-executable', MimeMagic.by_magic(File.open('/bin/ls')).to_s
assert_equal 'application/x-sharedlib', MimeMagic.by_magic(File.open('/lib/libc.so.6')).to_s
end
end
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