mime-types 1.17.2 → 3.0
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 +7 -0
- data/.autotest +35 -0
- data/.gitignore +17 -0
- data/.hoerc +20 -12
- data/Code-of-Conduct.rdoc +41 -0
- data/Contributing.rdoc +169 -0
- data/History.rdoc +531 -30
- data/Licence.rdoc +25 -0
- data/Manifest.txt +32 -34
- data/README.rdoc +198 -13
- data/Rakefile +181 -159
- data/lib/mime/type/columnar.rb +55 -0
- data/lib/mime/type.rb +566 -0
- data/lib/mime/types/cache.rb +56 -0
- data/lib/mime/types/columnar.rb +142 -0
- data/lib/mime/types/container.rb +30 -0
- data/lib/mime/types/deprecations.rb +32 -0
- data/lib/mime/types/full.rb +17 -0
- data/lib/mime/types/loader.rb +148 -0
- data/lib/mime/types/logger.rb +37 -0
- data/lib/mime/types/registry.rb +81 -0
- data/lib/mime/types.rb +199 -819
- data/lib/mime-types.rb +1 -0
- data/support/benchmarks/load.rb +65 -0
- data/support/benchmarks/load_allocations.rb +90 -0
- data/support/benchmarks/object_counts.rb +43 -0
- data/support/profile/columnar.rb +5 -0
- data/support/profile/columnar_full.rb +5 -0
- data/support/profile/full.rb +5 -0
- data/test/bad-fixtures/malformed +9 -0
- data/test/fixture/json.json +1 -0
- data/test/fixture/old-data +9 -0
- data/test/fixture/yaml.yaml +55 -0
- data/test/minitest_helper.rb +12 -0
- data/test/test_mime_type.rb +527 -242
- data/test/test_mime_types.rb +130 -68
- data/test/test_mime_types_cache.rb +100 -0
- data/test/test_mime_types_class.rb +155 -0
- data/test/test_mime_types_lazy.rb +43 -0
- data/test/test_mime_types_loader.rb +32 -0
- metadata +286 -229
- data/License.rdoc +0 -10
- data/lib/mime/types/application +0 -940
- data/lib/mime/types/application.mac +0 -2
- data/lib/mime/types/application.nonstandard +0 -114
- data/lib/mime/types/application.obsolete +0 -40
- data/lib/mime/types/audio +0 -131
- data/lib/mime/types/audio.nonstandard +0 -10
- data/lib/mime/types/audio.obsolete +0 -1
- data/lib/mime/types/image +0 -43
- data/lib/mime/types/image.nonstandard +0 -17
- data/lib/mime/types/image.obsolete +0 -5
- data/lib/mime/types/message +0 -19
- data/lib/mime/types/message.obsolete +0 -1
- data/lib/mime/types/model +0 -15
- data/lib/mime/types/multipart +0 -14
- data/lib/mime/types/multipart.nonstandard +0 -1
- data/lib/mime/types/multipart.obsolete +0 -7
- data/lib/mime/types/other.nonstandard +0 -8
- data/lib/mime/types/text +0 -54
- data/lib/mime/types/text.nonstandard +0 -5
- data/lib/mime/types/text.obsolete +0 -7
- data/lib/mime/types/text.vms +0 -1
- data/lib/mime/types/video +0 -68
- data/lib/mime/types/video.nonstandard +0 -11
- data/lib/mime/types/video.obsolete +0 -3
- data/mime-types.gemspec +0 -57
- data/type-lists/application.txt +0 -951
- data/type-lists/audio.txt +0 -132
- data/type-lists/image.txt +0 -43
- data/type-lists/message.txt +0 -20
- data/type-lists/model.txt +0 -15
- data/type-lists/multipart.txt +0 -14
- data/type-lists/text.txt +0 -57
- data/type-lists/video.txt +0 -67
data/lib/mime-types.rb
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require 'mime/types'
|
@@ -0,0 +1,65 @@
|
|
1
|
+
# -*- ruby encoding: utf-8 -*-
|
2
|
+
|
3
|
+
require 'benchmark'
|
4
|
+
require 'mime/types'
|
5
|
+
|
6
|
+
module Benchmarks
|
7
|
+
class Load
|
8
|
+
def self.report(load_path, repeats)
|
9
|
+
new(load_path, repeats.to_i).report
|
10
|
+
end
|
11
|
+
|
12
|
+
def initialize(load_path, repeats = nil)
|
13
|
+
@cache_file = File.expand_path('../cache.mtc', __FILE__)
|
14
|
+
@repeats = repeats.to_i
|
15
|
+
@repeats = 50 if @repeats <= 0
|
16
|
+
@load_path = load_path
|
17
|
+
end
|
18
|
+
|
19
|
+
def reload_mime_types(repeats = 1, force: false, columnar: false, cache: false)
|
20
|
+
loader = MIME::Types::Loader.new
|
21
|
+
|
22
|
+
repeats.times {
|
23
|
+
types = MIME::Types::Cache.load if cache
|
24
|
+
unless types
|
25
|
+
types = loader.load(columnar: columnar)
|
26
|
+
MIME::Types::Cache.save(types) if cache
|
27
|
+
end
|
28
|
+
types.first.to_h if force
|
29
|
+
}
|
30
|
+
end
|
31
|
+
|
32
|
+
def report
|
33
|
+
remove_cache
|
34
|
+
|
35
|
+
Benchmark.bm(30) do |mark|
|
36
|
+
mark.report('Normal') { reload_mime_types(@repeats) }
|
37
|
+
mark.report('Columnar') {
|
38
|
+
reload_mime_types(@repeats, columnar: true)
|
39
|
+
}
|
40
|
+
mark.report('Columnar Full') {
|
41
|
+
reload_mime_types(@repeats, columnar: true, force: true)
|
42
|
+
}
|
43
|
+
|
44
|
+
ENV['RUBY_MIME_TYPES_CACHE'] = @cache_file
|
45
|
+
mark.report('Cache Initialize') { reload_mime_types(cache: true) }
|
46
|
+
mark.report('Cached') { reload_mime_types(@repeats, cache: true) }
|
47
|
+
|
48
|
+
remove_cache
|
49
|
+
ENV['RUBY_MIME_TYPES_CACHE'] = @cache_file
|
50
|
+
mark.report('Columnar Cache Initialize') {
|
51
|
+
reload_mime_types(columnar: true, cache: true)
|
52
|
+
}
|
53
|
+
mark.report('Columnar Cached') {
|
54
|
+
reload_mime_types(@repeats, columnar: true, cache: true)
|
55
|
+
}
|
56
|
+
end
|
57
|
+
ensure
|
58
|
+
remove_cache
|
59
|
+
end
|
60
|
+
|
61
|
+
def remove_cache
|
62
|
+
File.unlink(@cache_file) if File.exist?(@cache_file)
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
@@ -0,0 +1,90 @@
|
|
1
|
+
# -*- ruby encoding: utf-8 -*-
|
2
|
+
|
3
|
+
if RUBY_VERSION < '2.1'
|
4
|
+
$stderr.puts "Cannot count allocations on #{RUBY_VERSION}."
|
5
|
+
exit 1
|
6
|
+
end
|
7
|
+
|
8
|
+
begin
|
9
|
+
require 'allocation_tracer'
|
10
|
+
rescue LoadError
|
11
|
+
$stderr.puts "Allocation tracking requires the gem 'allocation_tracer'."
|
12
|
+
exit 1
|
13
|
+
end
|
14
|
+
|
15
|
+
module Benchmarks
|
16
|
+
class LoadAllocations
|
17
|
+
def self.report(columnar: false, full: false, top_x: nil, mime_types_only: false)
|
18
|
+
new(
|
19
|
+
columnar: columnar,
|
20
|
+
top_x: top_x,
|
21
|
+
mime_types_only: mime_types_only,
|
22
|
+
full: full
|
23
|
+
).report
|
24
|
+
end
|
25
|
+
|
26
|
+
def initialize(columnar: false, full: false, top_x: nil, mime_types_only: false)
|
27
|
+
@columnar = !!columnar
|
28
|
+
@full = !!full
|
29
|
+
@mime_types_only = !!mime_types_only
|
30
|
+
|
31
|
+
@top_x = top_x
|
32
|
+
|
33
|
+
return unless @top_x
|
34
|
+
@top_x = top_x.to_i
|
35
|
+
@top_x = 10 if @top_x <= 0
|
36
|
+
end
|
37
|
+
|
38
|
+
def report
|
39
|
+
collect
|
40
|
+
report_top_x if @top_x
|
41
|
+
puts "TOTAL Allocations: #{@count}"
|
42
|
+
end
|
43
|
+
|
44
|
+
private
|
45
|
+
|
46
|
+
def report_top_x
|
47
|
+
table = @allocations.sort_by { |_, v| v.first }.reverse.first(@top_x)
|
48
|
+
table.map! { |(location, allocs)|
|
49
|
+
next if @mime_types_only and location.first !~ %r{mime-types/lib}
|
50
|
+
[ location.join(':').gsub(%r{^#{Dir.pwd}/}, ''), *allocs ]
|
51
|
+
}.compact!
|
52
|
+
|
53
|
+
head = (ObjectSpace::AllocationTracer.header - [ :line ]).map {|h|
|
54
|
+
h.to_s.split(/_/).map(&:capitalize).join(' ')
|
55
|
+
}
|
56
|
+
table.unshift head
|
57
|
+
|
58
|
+
max_widths = [].tap do |mw|
|
59
|
+
table.map { |row| row.lazy.map(&:to_s).map(&:length).to_a }.tap do |w|
|
60
|
+
w.first.each_index do |i|
|
61
|
+
mw << w.lazy.map { |r| r[i] }.max
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
pattern = [ '%%-%ds' ]
|
67
|
+
pattern << ([ '%% %ds' ] * (max_widths.length - 1))
|
68
|
+
pattern = pattern.join("\t") % max_widths
|
69
|
+
table.each { |row| puts pattern % row }
|
70
|
+
puts
|
71
|
+
end
|
72
|
+
|
73
|
+
def collect
|
74
|
+
if @columnar
|
75
|
+
@allocations = ObjectSpace::AllocationTracer.trace do
|
76
|
+
require 'mime/types'
|
77
|
+
|
78
|
+
MIME::Types.first.to_h if @full
|
79
|
+
end
|
80
|
+
else
|
81
|
+
@allocations = ObjectSpace::AllocationTracer.trace do
|
82
|
+
require 'mime/types/full'
|
83
|
+
end
|
84
|
+
end
|
85
|
+
|
86
|
+
@count = ObjectSpace::AllocationTracer.allocated_count_table.values.
|
87
|
+
inject(:+)
|
88
|
+
end
|
89
|
+
end
|
90
|
+
end
|
@@ -0,0 +1,43 @@
|
|
1
|
+
# -*- ruby encoding: utf-8 -*-
|
2
|
+
|
3
|
+
module Benchmarks
|
4
|
+
class ObjectCounts
|
5
|
+
def self.report(columnar: false, full: false)
|
6
|
+
new(columnar: columnar).report
|
7
|
+
end
|
8
|
+
|
9
|
+
def initialize(columnar: false, full: false)
|
10
|
+
@columnar = columnar
|
11
|
+
@full = full
|
12
|
+
end
|
13
|
+
|
14
|
+
def report
|
15
|
+
collect
|
16
|
+
@before.keys.grep(/T_/).map { |key|
|
17
|
+
[ key, @after[key] - @before[key] ]
|
18
|
+
}.sort_by { |_, delta| -delta }.each { |key, delta|
|
19
|
+
puts '%10s +%6d' % [ key, delta ]
|
20
|
+
}
|
21
|
+
end
|
22
|
+
|
23
|
+
private
|
24
|
+
|
25
|
+
def collect
|
26
|
+
@before = count_objects
|
27
|
+
|
28
|
+
if @columnar
|
29
|
+
require 'mime/types'
|
30
|
+
MIME::Types.first.to_h if @full
|
31
|
+
else
|
32
|
+
require 'mime/types/full'
|
33
|
+
end
|
34
|
+
|
35
|
+
@after = count_objects
|
36
|
+
end
|
37
|
+
|
38
|
+
def count_objects
|
39
|
+
GC.start
|
40
|
+
ObjectSpace.count_objects
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
@@ -0,0 +1,9 @@
|
|
1
|
+
!application.smil @smi,smil :8bit 'IANA,RFC4536 =use-instead:application/smil+xml
|
2
|
+
!audio/vnd.qcelp @qcp 'IANA,RFC3625 =use-instead:audio/QCELP
|
3
|
+
*!image/bmp @bmp =use-instead:image/x-bmp
|
4
|
+
*application/acad 'LTSW
|
5
|
+
*audio/webm @webm '{WebM=http://www.webmproject.org/code/specs/container/}
|
6
|
+
*image/pjpeg :base64 =Fixes a bug with IE6 and progressive JPEGs
|
7
|
+
application/1d-interleaved-parityfec 'IANA,RFC6015
|
8
|
+
audio/1d-interleaved-parityfec 'IANA,RFC6015
|
9
|
+
mac:application/x-apple-diskimage @dmg
|
@@ -0,0 +1 @@
|
|
1
|
+
[{"content-type":"application/smil","encoding":"8bit","extensions":["smi","smil"],"obsolete":true,"use-instead":"application/smil+xml","registered":true},{"content-type":"audio/vnd.qcelp","encoding":"base64","extensions":["qcp"],"obsolete":true,"use-instead":"audio/QCELP","registered":true},{"content-type":"image/bmp","encoding":"base64","extensions":["bmp"],"obsolete":true,"use-instead":"image/x-bmp","registered":false},{"content-type":"application/acad","encoding":"base64","registered":false},{"content-type":"audio/webm","encoding":"base64","extensions":["webm"],"registered":false},{"content-type":"image/pjpeg","docs":"Fixes a bug with IE6 and progressive JPEGs","encoding":"base64","registered":false},{"content-type":"application/1d-interleaved-parityfec","encoding":"base64","registered":true},{"content-type":"audio/1d-interleaved-parityfec","encoding":"base64","registered":true},{"content-type":"application/x-apple-diskimage","encoding":"base64","extensions":["dmg"],"registered":false}]
|
@@ -0,0 +1,9 @@
|
|
1
|
+
!application/smil @smi,smil :8bit 'IANA,RFC4536 =use-instead:application/smil+xml
|
2
|
+
!audio/vnd.qcelp @qcp 'IANA,RFC3625 =use-instead:audio/QCELP
|
3
|
+
*!image/bmp @bmp =use-instead:image/x-bmp
|
4
|
+
*application/acad 'LTSW
|
5
|
+
*audio/webm @webm '{WebM=http://www.webmproject.org/code/specs/container/}
|
6
|
+
*image/pjpeg :base64 =Fixes a bug with IE6 and progressive JPEGs
|
7
|
+
application/1d-interleaved-parityfec 'IANA,RFC6015
|
8
|
+
audio/1d-interleaved-parityfec 'IANA,RFC6015
|
9
|
+
mac:application/x-apple-diskimage @dmg
|
@@ -0,0 +1,55 @@
|
|
1
|
+
---
|
2
|
+
- !ruby/object:MIME::Type
|
3
|
+
content-type: application/smil
|
4
|
+
encoding: 8bit
|
5
|
+
extensions:
|
6
|
+
- smi
|
7
|
+
- smil
|
8
|
+
obsolete: true
|
9
|
+
use-instead: application/smil+xml
|
10
|
+
registered: true
|
11
|
+
- !ruby/object:MIME::Type
|
12
|
+
content-type: audio/vnd.qcelp
|
13
|
+
encoding: base64
|
14
|
+
extensions:
|
15
|
+
- qcp
|
16
|
+
obsolete: true
|
17
|
+
use-instead: audio/QCELP
|
18
|
+
registered: true
|
19
|
+
- !ruby/object:MIME::Type
|
20
|
+
content-type: image/bmp
|
21
|
+
encoding: base64
|
22
|
+
extensions:
|
23
|
+
- bmp
|
24
|
+
obsolete: true
|
25
|
+
use-instead: image/x-bmp
|
26
|
+
registered: false
|
27
|
+
- !ruby/object:MIME::Type
|
28
|
+
content-type: application/acad
|
29
|
+
encoding: base64
|
30
|
+
registered: false
|
31
|
+
- !ruby/object:MIME::Type
|
32
|
+
content-type: audio/webm
|
33
|
+
encoding: base64
|
34
|
+
extensions:
|
35
|
+
- webm
|
36
|
+
registered: false
|
37
|
+
- !ruby/object:MIME::Type
|
38
|
+
content-type: image/pjpeg
|
39
|
+
docs: Fixes a bug with IE6 and progressive JPEGs
|
40
|
+
encoding: base64
|
41
|
+
registered: false
|
42
|
+
- !ruby/object:MIME::Type
|
43
|
+
content-type: application/1d-interleaved-parityfec
|
44
|
+
encoding: base64
|
45
|
+
registered: true
|
46
|
+
- !ruby/object:MIME::Type
|
47
|
+
content-type: audio/1d-interleaved-parityfec
|
48
|
+
encoding: base64
|
49
|
+
registered: true
|
50
|
+
- !ruby/object:MIME::Type
|
51
|
+
content-type: application/x-apple-diskimage
|
52
|
+
encoding: base64
|
53
|
+
extensions:
|
54
|
+
- dmg
|
55
|
+
registered: false
|
@@ -0,0 +1,12 @@
|
|
1
|
+
# -*- ruby encoding: utf-8 -*-
|
2
|
+
|
3
|
+
require 'mime/type'
|
4
|
+
require 'fileutils'
|
5
|
+
|
6
|
+
gem 'minitest'
|
7
|
+
require 'fivemat/minitest/autorun'
|
8
|
+
require 'minitest/focus'
|
9
|
+
require 'minitest/rg'
|
10
|
+
require 'minitest-bonus-assertions'
|
11
|
+
|
12
|
+
ENV['RUBY_MIME_TYPES_LAZY_LOAD'] = 'yes'
|