marcel 0.3.2 → 1.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/marcel.rb +3 -2
- data/lib/marcel/magic.rb +147 -0
- data/lib/marcel/mime_type.rb +68 -67
- data/lib/marcel/mime_type/definitions.rb +8 -3
- data/lib/marcel/tables.rb +2515 -0
- data/lib/marcel/version.rb +1 -1
- metadata +42 -235
- data/.gitignore +0 -1
- data/.travis.yml +0 -7
- data/Gemfile +0 -4
- data/Gemfile.lock +0 -26
- data/README.md +0 -50
- data/Rakefile +0 -33
- data/marcel.gemspec +0 -28
- data/test/declared_type_test.rb +0 -17
- data/test/extension_test.rb +0 -25
- data/test/fixtures/image.gif +0 -0
- data/test/fixtures/magic/application/msword/msword.doc +0 -0
- data/test/fixtures/magic/application/pdf/illustrator-seen-as-pdf.ai +22 -6302
- data/test/fixtures/magic/application/pdf/pdf.pdf +0 -0
- data/test/fixtures/magic/application/rtf/rtf.rtf +0 -1
- data/test/fixtures/magic/application/vnd.adobe.flash.movie/flash.swf +0 -0
- data/test/fixtures/magic/application/vnd.openxmlformats-officedocument.presentationml.presentation/vnd.openxmlformats-officedocument.presentationml.presentation.pptx +0 -0
- data/test/fixtures/magic/application/vnd.openxmlformats-officedocument.spreadsheetml.sheet/vnd.openxmlformats-officedocument.spreadsheetml.sheet.xlsx +0 -0
- data/test/fixtures/magic/application/vnd.openxmlformats-officedocument.wordprocessingml.document/vnd.openxmlformats-officedocument.wordprocessingml.document.docx +0 -0
- data/test/fixtures/magic/application/x-font-ttf.ttf +0 -0
- data/test/fixtures/magic/application/xml/xml.xml +0 -1
- data/test/fixtures/magic/application/zip/sketch.sketch +0 -0
- data/test/fixtures/magic/application/zip/zip.zip +0 -0
- data/test/fixtures/magic/audio/flac/flac.flac +0 -0
- data/test/fixtures/magic/audio/mp4/m4a.m4a +0 -0
- data/test/fixtures/magic/audio/mp4/mp4.m4a +0 -0
- data/test/fixtures/magic/audio/mpeg/mpeg.mp3 +0 -0
- data/test/fixtures/magic/audio/x-wav/wav.wav +0 -0
- data/test/fixtures/magic/audio/x-wav/x-wav.wav +0 -0
- data/test/fixtures/magic/image/bmp/bmp.bmp +0 -0
- data/test/fixtures/magic/image/gif/gif.gif +0 -0
- data/test/fixtures/magic/image/jpeg/jpeg.jpg +0 -0
- data/test/fixtures/magic/image/png/png.png +0 -0
- data/test/fixtures/magic/image/svg+xml/svg.svg +0 -1
- data/test/fixtures/magic/image/tiff/tiff.tif +0 -0
- data/test/fixtures/magic/image/vnd.adobe.photoshop/photoshop-large-document-format.psb +0 -0
- data/test/fixtures/magic/image/vnd.adobe.photoshop/vnd.adobe.photoshop.psd +0 -0
- data/test/fixtures/magic/image/vnd.dwg/x-dwg.dwg +0 -0
- data/test/fixtures/magic/image/vnd.microsoft.icon/ico.ico +0 -0
- data/test/fixtures/magic/image/webp/webp.webp +0 -0
- data/test/fixtures/magic/image/x-eps/postscript/postscript.eps +0 -0
- data/test/fixtures/magic/image/x-eps/x-eps.eps +0 -0
- data/test/fixtures/magic/text/html/html.html +0 -3
- data/test/fixtures/magic/video/mp4/m4v.m4v +0 -0
- data/test/fixtures/magic/video/mp4/mp4.mp4 +0 -0
- data/test/fixtures/magic/video/quicktime/quicktime.mov +0 -0
- data/test/fixtures/magic/video/webm/webm.mkv +0 -0
- data/test/fixtures/name/application/illustrator/illustrator.ai +27 -6301
- data/test/fixtures/name/application/javascript/javascript.js +0 -3
- data/test/fixtures/name/application/json/json.json +0 -3
- data/test/fixtures/name/application/msword/msword.doc +0 -0
- data/test/fixtures/name/application/pdf/pdf.pdf +0 -0
- data/test/fixtures/name/application/rtf/rtf.rtf +0 -1
- data/test/fixtures/name/application/sql/sql.sql +0 -0
- data/test/fixtures/name/application/vnd.adobe.flash.movie/flash.swf +0 -0
- data/test/fixtures/name/application/vnd.android.package-archive/vnd.android.package-archive.apk +0 -0
- data/test/fixtures/name/application/vnd.apple.keynote/vnd.apple.keynote.key +0 -0
- data/test/fixtures/name/application/vnd.apple.numbers/vnd.apple.numbers.numbers +0 -0
- data/test/fixtures/name/application/vnd.apple.pages/vnd.apple.pages.pages +0 -0
- data/test/fixtures/name/application/vnd.ms-excel.sheet.binary.macroenabled.12/vnd.ms-excel.sheet.binary.macroenabled.12.xlsb +0 -0
- data/test/fixtures/name/application/vnd.ms-excel.sheet.macroenabled.12/vnd.ms-excel.sheet.macroenabled.12.xlsm +0 -0
- data/test/fixtures/name/application/vnd.ms-excel.template.macroenabled.12/vnd.ms-excel.template.macroenabled.12.xltm +0 -0
- data/test/fixtures/name/application/vnd.ms-excel/vnd.ms-excel.xls +0 -0
- data/test/fixtures/name/application/vnd.ms-powerpoint.presentation.macroenabled.12/vnd.ms-powerpoint.presentation.macroenabled.12.pptm +0 -0
- data/test/fixtures/name/application/vnd.ms-powerpoint.slideshow.macroenabled.12/vnd.ms-powerpoint.slideshow.macroenabled.12.ppsm +0 -0
- data/test/fixtures/name/application/vnd.ms-powerpoint.template.macroenabled.12/vnd.ms-powerpoint.template.macroenabled.12.potm +0 -0
- data/test/fixtures/name/application/vnd.ms-powerpoint/vnd.ms-powerpoint.ppt +0 -0
- data/test/fixtures/name/application/vnd.ms-word.document.macroenabled.12/vnd.ms-word.document.macroenabled.12.docm +0 -0
- data/test/fixtures/name/application/vnd.ms-word.template.macroenabled.12/vnd.ms-word.template.macroenabled.12.dotm +0 -0
- data/test/fixtures/name/application/vnd.openxmlformats-officedocument.presentationml.presentation/vnd.openxmlformats-officedocument.presentationml.presentation.pptx +0 -0
- data/test/fixtures/name/application/vnd.openxmlformats-officedocument.presentationml.slideshow/vnd.openxmlformats-officedocument.presentationml.slideshow.ppsx +0 -0
- data/test/fixtures/name/application/vnd.openxmlformats-officedocument.presentationml.template/vnd.openxmlformats-officedocument.presentationml.template.potx +0 -0
- data/test/fixtures/name/application/vnd.openxmlformats-officedocument.spreadsheetml.sheet/downloaded-from-google-docs.xlsx +0 -0
- data/test/fixtures/name/application/vnd.openxmlformats-officedocument.spreadsheetml.sheet/vnd.openxmlformats-officedocument.spreadsheetml.sheet.xlsx +0 -0
- data/test/fixtures/name/application/vnd.openxmlformats-officedocument.wordprocessingml.document/vnd.openxmlformats-officedocument.wordprocessingml.document.docx +0 -0
- data/test/fixtures/name/application/vnd.openxmlformats-officedocument.wordprocessingml.template/vnd.openxmlformats-officedocument.wordprocessingml.template.dotx +0 -0
- data/test/fixtures/name/application/x-font-ttf.ttf +0 -0
- data/test/fixtures/name/application/zip/zip.zip +0 -0
- data/test/fixtures/name/audio/flac/flac.flac +0 -0
- data/test/fixtures/name/audio/mp4/mp4.m4a +0 -0
- data/test/fixtures/name/audio/mpeg/mpeg.mp3 +0 -0
- data/test/fixtures/name/audio/x-wav/x-wav.wav +0 -0
- data/test/fixtures/name/image/bmp/bmp.bmp +0 -0
- data/test/fixtures/name/image/gif/gif.gif +0 -0
- data/test/fixtures/name/image/heic.heic +0 -0
- data/test/fixtures/name/image/heif.heif +0 -0
- data/test/fixtures/name/image/jpeg/jpeg.jpg +0 -0
- data/test/fixtures/name/image/png/png.png +0 -0
- data/test/fixtures/name/image/svg+xml/svg.svg +0 -1
- data/test/fixtures/name/image/tiff/tiff.tif +0 -0
- data/test/fixtures/name/image/tiff/tiff.tiff +0 -0
- data/test/fixtures/name/image/vnd.adobe.photoshop/saved-as-large-document-format.psb +0 -0
- data/test/fixtures/name/image/vnd.adobe.photoshop/vnd.adobe.photoshop.psd +0 -0
- data/test/fixtures/name/image/x-eps/postscript/postscript.eps +0 -0
- data/test/fixtures/name/image/x-eps/x-eps.eps +0 -0
- data/test/fixtures/name/message/rfc822/rfc822.eml +0 -34
- data/test/fixtures/name/text/csv/csv.csv +0 -2
- data/test/fixtures/name/text/html/html.html +0 -3
- data/test/fixtures/name/text/plain/plain.asc +0 -1
- data/test/fixtures/name/text/plain/plain.txt +0 -1
- data/test/fixtures/name/text/x-log/x-log.log +0 -1
- data/test/fixtures/name/video/mp4/mp4.mp4 +0 -0
- data/test/fixtures/name/video/quicktime/quicktime.mov +0 -0
- data/test/magic_and_declared_type_test.rb +0 -10
- data/test/magic_and_name_test.rb +0 -13
- data/test/magic_test.rb +0 -13
- data/test/mime_type_test.rb +0 -47
- data/test/name_test.rb +0 -10
- data/test/test_helper.rb +0 -49
Binary file
|
Binary file
|
@@ -1 +0,0 @@
|
|
1
|
-
{\rtf1}
|
File without changes
|
Binary file
|
data/test/fixtures/name/application/vnd.android.package-archive/vnd.android.package-archive.apk
DELETED
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
@@ -1 +0,0 @@
|
|
1
|
-
<svg xmlns="http://www.w3.org/2000/svg"/>
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
@@ -1,34 +0,0 @@
|
|
1
|
-
User-Agent: Microsoft-MacOutlook/0.0.0.151105
|
2
|
-
Date: Wed, 12 Jul 2017 15:25:43 +0100
|
3
|
-
Subject: Example email
|
4
|
-
From: Tom Ward <tom@popdog.net>
|
5
|
-
To: <tom@example.com>
|
6
|
-
Message-ID: <D7B2F82B-4176-475B-BA89-4356D7AA2DF6@popdog.net>
|
7
|
-
Thread-Topic: Example email
|
8
|
-
Mime-version: 1.0
|
9
|
-
Content-type: multipart/alternative;
|
10
|
-
boundary="B_3582727856_2021010881"
|
11
|
-
|
12
|
-
> This message is in MIME format. Since your mail reader does not understand
|
13
|
-
this format, some or all of this message may not be legible.
|
14
|
-
|
15
|
-
--B_3582727856_2021010881
|
16
|
-
Content-type: text/plain;
|
17
|
-
charset="UTF-8"
|
18
|
-
Content-transfer-encoding: 7bit
|
19
|
-
|
20
|
-
Hello
|
21
|
-
|
22
|
-
|
23
|
-
--B_3582727856_2021010881
|
24
|
-
Content-type: text/html;
|
25
|
-
charset="UTF-8"
|
26
|
-
Content-transfer-encoding: quoted-printable
|
27
|
-
|
28
|
-
<html><head></head><body style=3D"word-wrap: break-word; -webkit-nbsp-mode: s=
|
29
|
-
pace; -webkit-line-break: after-white-space; color: rgb(0, 0, 0); font-size:=
|
30
|
-
14px; font-family: Calibri, sans-serif;"><div><div><div>Hello</div><div><di=
|
31
|
-
v id=3D"MAC_OUTLOOK_SIGNATURE"></div></div></div></div></body></html>
|
32
|
-
|
33
|
-
--B_3582727856_2021010881--
|
34
|
-
|
@@ -1 +0,0 @@
|
|
1
|
-
Marcel
|
@@ -1 +0,0 @@
|
|
1
|
-
Marcel
|
@@ -1 +0,0 @@
|
|
1
|
-
Some logging
|
Binary file
|
Binary file
|
@@ -1,10 +0,0 @@
|
|
1
|
-
require 'test_helper'
|
2
|
-
require 'rack'
|
3
|
-
|
4
|
-
class Marcel::MimeType::MagicAndDeclaredTypeTest < Marcel::TestCase
|
5
|
-
each_content_type_fixture('name') do |file, name, content_type|
|
6
|
-
test "correctly returns #{content_type} for #{name} given both file and declared type" do
|
7
|
-
assert_equal content_type, Marcel::MimeType.for(file, declared_type: content_type)
|
8
|
-
end
|
9
|
-
end
|
10
|
-
end
|
data/test/magic_and_name_test.rb
DELETED
@@ -1,13 +0,0 @@
|
|
1
|
-
require 'test_helper'
|
2
|
-
require 'rack'
|
3
|
-
|
4
|
-
class Marcel::MimeType::MagicAndNameTest < Marcel::TestCase
|
5
|
-
# All fixtures that can be recognised by name should also be recognisable when given
|
6
|
-
# the file contents and the name. In some cases, the file contents will point to a
|
7
|
-
# generic type, while the name will choose a more specific subclass
|
8
|
-
each_content_type_fixture('name') do |file, name, content_type|
|
9
|
-
test "correctly returns #{content_type} for #{name} given both file and name" do
|
10
|
-
assert_equal content_type, Marcel::MimeType.for(file, name: name)
|
11
|
-
end
|
12
|
-
end
|
13
|
-
end
|
data/test/magic_test.rb
DELETED
@@ -1,13 +0,0 @@
|
|
1
|
-
require 'test_helper'
|
2
|
-
require 'rack'
|
3
|
-
|
4
|
-
class Marcel::MimeType::MagicTest < Marcel::TestCase
|
5
|
-
# These fixtures should be recognisable given only their contents. Where a generic type
|
6
|
-
# has more specific subclasses (such as application/zip), these subclasses cannot usually
|
7
|
-
# be recognised by magic alone; their name is also needed to correctly identify them.
|
8
|
-
each_content_type_fixture('magic') do |file, name, content_type|
|
9
|
-
test "gets type for #{content_type} by using only magic bytes #{name}" do
|
10
|
-
assert_equal content_type, Marcel::MimeType.for(file)
|
11
|
-
end
|
12
|
-
end
|
13
|
-
end
|
data/test/mime_type_test.rb
DELETED
@@ -1,47 +0,0 @@
|
|
1
|
-
require 'test_helper'
|
2
|
-
require 'rack'
|
3
|
-
|
4
|
-
class Marcel::MimeTypeTest < Marcel::TestCase
|
5
|
-
def setup
|
6
|
-
@path = files("image.gif").to_s
|
7
|
-
end
|
8
|
-
|
9
|
-
test "gets content type from Files" do
|
10
|
-
content_type = File.open @path do |file|
|
11
|
-
Marcel::MimeType.for file
|
12
|
-
end
|
13
|
-
assert_equal "image/gif", content_type
|
14
|
-
end
|
15
|
-
|
16
|
-
test "gets content type from Pathnames" do
|
17
|
-
content_type = Marcel::MimeType.for Pathname.new(@path)
|
18
|
-
assert_equal "image/gif", content_type
|
19
|
-
end
|
20
|
-
|
21
|
-
test "closes Pathname files after use" do
|
22
|
-
content_type = Marcel::MimeType.for Pathname.new(@path)
|
23
|
-
open_files = ObjectSpace.each_object(File).reject(&:closed?)
|
24
|
-
assert open_files.none? { |f| f.path == @path }
|
25
|
-
end
|
26
|
-
|
27
|
-
test "gets content type from Tempfiles" do
|
28
|
-
Tempfile.open("Marcel") do |tempfile|
|
29
|
-
tempfile.write(File.read(@path))
|
30
|
-
content_type = Marcel::MimeType.for tempfile
|
31
|
-
assert_equal "image/gif", content_type
|
32
|
-
end
|
33
|
-
end
|
34
|
-
|
35
|
-
test "gets content type from IOs" do
|
36
|
-
io = StringIO.new(File.read(@path))
|
37
|
-
content_type = Marcel::MimeType.for io
|
38
|
-
assert_equal "image/gif", content_type
|
39
|
-
end
|
40
|
-
|
41
|
-
test "gets content type from sources that conform to Rack::Lint::InputWrapper" do
|
42
|
-
io = StringIO.new(File.read(@path))
|
43
|
-
wrapper = Rack::Lint::InputWrapper.new(io)
|
44
|
-
content_type = Marcel::MimeType.for wrapper
|
45
|
-
assert_equal "image/gif", content_type
|
46
|
-
end
|
47
|
-
end
|
data/test/name_test.rb
DELETED
@@ -1,10 +0,0 @@
|
|
1
|
-
require 'test_helper'
|
2
|
-
require 'rack'
|
3
|
-
|
4
|
-
class Marcel::MimeType::NameTest < Marcel::TestCase
|
5
|
-
each_content_type_fixture('name') do |file, name, content_type|
|
6
|
-
test "gets type for #{content_type} by filename from #{name}" do
|
7
|
-
assert_equal content_type, Marcel::MimeType.for(name: name)
|
8
|
-
end
|
9
|
-
end
|
10
|
-
end
|
data/test/test_helper.rb
DELETED
@@ -1,49 +0,0 @@
|
|
1
|
-
require 'minitest/autorun'
|
2
|
-
require 'marcel'
|
3
|
-
|
4
|
-
class Marcel::TestCase < MiniTest::Test
|
5
|
-
class << self
|
6
|
-
def setup(&block)
|
7
|
-
define_method(:setup, &block)
|
8
|
-
end
|
9
|
-
|
10
|
-
def teardown(&block)
|
11
|
-
define_method(:teardown, &block)
|
12
|
-
end
|
13
|
-
|
14
|
-
def test(name, &block)
|
15
|
-
test_name = "test_#{name.gsub(/\s+/,'_')}".to_sym
|
16
|
-
defined = instance_method(test_name) rescue false
|
17
|
-
raise "#{test_name} is already defined in #{self}" if defined
|
18
|
-
define_method(test_name, &block)
|
19
|
-
end
|
20
|
-
|
21
|
-
def fixture_path(name)
|
22
|
-
File.expand_path("../fixtures/#{name}", __FILE__)
|
23
|
-
end
|
24
|
-
|
25
|
-
def files(name)
|
26
|
-
Pathname.new fixture_path(name)
|
27
|
-
end
|
28
|
-
|
29
|
-
def each_content_type_fixture(folder)
|
30
|
-
FileUtils.chdir fixture_path(folder) do
|
31
|
-
Dir["**/*.*"].map do |name|
|
32
|
-
if File.file?(name)
|
33
|
-
_, content_type, extra, extension = *name.match(/\A([^\/]+\/[^\/]*)\/?(.*)\.(\w+)\Z/)
|
34
|
-
extra = nil if content_type[-content_type.size..-1] == extra
|
35
|
-
yield files("#{folder}/#{name}"), name, content_type
|
36
|
-
end
|
37
|
-
end
|
38
|
-
end
|
39
|
-
end
|
40
|
-
end
|
41
|
-
|
42
|
-
def files(name)
|
43
|
-
Pathname.new fixture_path(name)
|
44
|
-
end
|
45
|
-
|
46
|
-
def fixture_path(name)
|
47
|
-
self.class.fixture_path(name)
|
48
|
-
end
|
49
|
-
end
|