Commit 0c913214 by Daniel Mendler

remove overlay

parent f5a56d88
...@@ -18,18 +18,7 @@ MimeMagic.by_magic(File.open('test.html')) ...@@ -18,18 +18,7 @@ MimeMagic.by_magic(File.open('test.html'))
# etc... # etc...
``` ```
Extra magic overlay You can add your own magic with `MimeMagic.add`.
=====
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:
```ruby
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 API
=== ===
......
# frozen_string_literal: true
# Extra magic
[['application/vnd.openxmlformats-officedocument.presentationml.presentation', [[0, "PK\003\004", [[0..5000, '[Content_Types].xml', [[0..5000, 'ppt/']]]]]]],
['application/vnd.openxmlformats-officedocument.spreadsheetml.sheet', [[0, "PK\003\004", [[0..5000, '[Content_Types].xml', [[0..5000, 'xl/']]]]]]],
['application/vnd.openxmlformats-officedocument.wordprocessingml.document', [[0, "PK\003\004", [[0..5000, '[Content_Types].xml', [[0..5000, 'word/']]]]]]]].each do |magic|
MimeMagic.add(magic[0], magic: magic[1])
end
...@@ -78,7 +78,6 @@ class TestMimeMagic < Minitest::Test ...@@ -78,7 +78,6 @@ class TestMimeMagic < Minitest::Test
end end
def test_recognize_by_magic def test_recognize_by_magic
load "mimemagic/overlay.rb"
Dir['test/files/*'].each do |file| Dir['test/files/*'].each do |file|
mime = file[11..-1].sub('.', '/').sub(/\{\w+\}/, '') mime = file[11..-1].sub('.', '/').sub(/\{\w+\}/, '')
assert_equal mime, MimeMagic.by_magic(File.read(file)).to_s assert_equal mime, MimeMagic.by_magic(File.read(file)).to_s
...@@ -87,7 +86,6 @@ class TestMimeMagic < Minitest::Test ...@@ -87,7 +86,6 @@ class TestMimeMagic < Minitest::Test
end end
def test_recognize_all_by_magic def test_recognize_all_by_magic
load 'mimemagic/overlay.rb'
%w(msoffice rubyxl gdocs).each do |variant| %w(msoffice rubyxl gdocs).each do |variant|
file = "test/files/application.vnd.openxmlformats-officedocument.spreadsheetml{#{variant}}.sheet" file = "test/files/application.vnd.openxmlformats-officedocument.spreadsheetml{#{variant}}.sheet"
mimes = %w[application/vnd.openxmlformats-officedocument.spreadsheetml.sheet application/zip] mimes = %w[application/vnd.openxmlformats-officedocument.spreadsheetml.sheet application/zip]
......
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