mime-types 3.6.0 → 3.6.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.
data/README.md ADDED
@@ -0,0 +1,199 @@
1
+ # mime-types for Ruby
2
+
3
+ - home :: https://github.com/mime-types/ruby-mime-types/
4
+ - issues :: https://github.com/mime-types/ruby-mime-types/issues
5
+ - code :: https://github.com/mime-types/ruby-mime-types/
6
+ - rdoc :: http://rdoc.info/gems/mime-types/
7
+ - changelog ::
8
+ https://github.com/mime-types/ruby-mime-types/blob/master/History.md
9
+ - continuous integration ::
10
+ {<img src="https://github.com/mime-types/ruby-mime-types/actions/workflows/ci.yml/badge.svg" alt="Build Status" />}[https://github.com/mime-types/ruby-mime-types/actions/workflows/ci.yml]
11
+ - test coverage ::
12
+ {<img src="https://coveralls.io/repos/mime-types/ruby-mime-types/badge.svg?branch=master&service=github" alt="Coverage Status" />}[https://coveralls.io/github/mime-types/ruby-mime-types?branch=master]
13
+
14
+ ## Description
15
+
16
+ The mime-types library provides a library and registry for information about
17
+ MIME content type definitions. It can be used to determine defined filename
18
+ extensions for MIME types, or to use filename extensions to look up the likely
19
+ MIME type definitions.
20
+
21
+ Version 3.0 is a major release that requires Ruby 2.0 compatibility and removes
22
+ deprecated functions. The columnar registry format introduced in 2.6 has been
23
+ made the primary format; the registry data has been extracted from this library
24
+ and put into {mime-types-data}[https://github.com/mime-types/mime-types-data].
25
+ Additionally, mime-types is now licensed exclusively under the MIT licence and
26
+ there is a code of conduct in effect. There are a number of other smaller
27
+ changes described in the History file.
28
+
29
+ ### About MIME Media Types
30
+
31
+ MIME content types are used in MIME-compliant communications, as in e-mail or
32
+ HTTP traffic, to indicate the type of content which is transmitted. The
33
+ mime-types library provides the ability for detailed information about MIME
34
+ entities (provided as an enumerable collection of MIME::Type objects) to be
35
+ determined and used. There are many types defined by RFCs and vendors, so the
36
+ list is long but by definition incomplete; don't hesitate to add additional type
37
+ definitions. MIME type definitions found in mime-types are from RFCs, W3C
38
+ recommendations, the {IANA Media Types
39
+ registry}[https://www.iana.org/assignments/media-types/media-types.xhtml], and
40
+ user contributions. It conforms to RFCs 2045 and 2231.
41
+
42
+ ### mime-types 3.x
43
+
44
+ Users are encouraged to upgrade to mime-types 3.x as soon as is practical.
45
+ mime-types 3.x requires Ruby 2.0 compatibility and a simpler licensing scheme.
46
+
47
+ ## Synopsis
48
+
49
+ MIME types are used in MIME entities, as in email or HTTP traffic. It is useful
50
+ at times to have information available about MIME types (or, inversely, about
51
+ files). A MIME::Type stores the known information about one MIME type.
52
+
53
+ ```ruby
54
+ require 'mime/types'
55
+
56
+ plaintext = MIME::Types['text/plain'] # => [ text/plain ]
57
+ text = plaintext.first
58
+ puts text.media_type # => 'text'
59
+ puts text.sub_type # => 'plain'
60
+
61
+ puts text.extensions.join(' ') # => 'txt asc c cc h hh cpp hpp dat hlp'
62
+ puts text.preferred_extension # => 'txt'
63
+ puts text.friendly # => 'Text Document'
64
+ puts text.i18n_key # => 'text.plain'
65
+
66
+ puts text.encoding # => quoted-printable
67
+ puts text.default_encoding # => quoted-printable
68
+ puts text.binary? # => false
69
+ puts text.ascii? # => true
70
+ puts text.obsolete? # => false
71
+ puts text.registered? # => true
72
+ puts text.provisional? # => false
73
+ puts text.complete? # => true
74
+
75
+ puts text # => 'text/plain'
76
+
77
+ puts text == 'text/plain' # => true
78
+ puts 'text/plain' == text # => true
79
+ puts text == 'text/x-plain' # => false
80
+ puts 'text/x-plain' == text # => false
81
+
82
+ puts MIME::Type.simplified('x-appl/x-zip') # => 'x-appl/x-zip'
83
+ puts MIME::Type.i18n_key('x-appl/x-zip') # => 'x-appl.x-zip'
84
+
85
+ puts text.like?('text/x-plain') # => true
86
+ puts text.like?(MIME::Type.new('x-text/x-plain')) # => true
87
+
88
+ puts text.xrefs.inspect # => { "rfc" => [ "rfc2046", "rfc3676", "rfc5147" ] }
89
+ puts text.xref_urls # => [ "http://www.iana.org/go/rfc2046",
90
+ # "http://www.iana.org/go/rfc3676",
91
+ # "http://www.iana.org/go/rfc5147" ]
92
+
93
+ xtext = MIME::Type.new('x-text/x-plain')
94
+ puts xtext.media_type # => 'text'
95
+ puts xtext.raw_media_type # => 'x-text'
96
+ puts xtext.sub_type # => 'plain'
97
+ puts xtext.raw_sub_type # => 'x-plain'
98
+ puts xtext.complete? # => false
99
+
100
+ puts MIME::Types.any? { |type| type.content_type == 'text/plain' } # => true
101
+ puts MIME::Types.all?(&:registered?) # => false
102
+
103
+ # Various string representations of MIME types
104
+ qcelp = MIME::Types['audio/QCELP'].first # => audio/QCELP
105
+ puts qcelp.content_type # => 'audio/QCELP'
106
+ puts qcelp.simplified # => 'audio/qcelp'
107
+
108
+ xwingz = MIME::Types['application/x-Wingz'].first # => application/x-Wingz
109
+ puts xwingz.content_type # => 'application/x-Wingz'
110
+ puts xwingz.simplified # => 'application/x-wingz'
111
+ ```
112
+
113
+ ### Columnar Store
114
+
115
+ mime-types uses as its primary registry storage format a columnar storage format
116
+ reducing the default memory footprint. This is done by selectively loading the
117
+ data on a per-attribute basis. When the registry is first loaded from the
118
+ columnar store, only the canonical MIME content type and known extensions and
119
+ the MIME type will be connected to its loading registry. When other data about
120
+ the type is required (including `preferred_extension`, `obsolete?`, and
121
+ `registered?`) that data is loaded from its own column file for all types in the
122
+ registry.
123
+
124
+ The load of any column data is performed with a Mutex to ensure that types are
125
+ updated safely in a multithreaded environment. Benchmarks show that while
126
+ columnar data loading is slower than the JSON store, it cuts the memory use by a
127
+ third over the JSON store.
128
+
129
+ If you prefer to load all the data at once, this can be specified in your
130
+ application Gemfile as:
131
+
132
+ ```ruby
133
+ gem 'mime-types', require: 'mime/types/full'
134
+ ```
135
+
136
+ Projects that do not use Bundler should `require` the same:
137
+
138
+ ```ruby
139
+ require 'mime/types/full'
140
+ ```
141
+
142
+ Libraries that use mime-types are discouraged from choosing the JSON store.
143
+
144
+ For applications and clients that used mime-types 2.6 when the columnar store
145
+ was introduced, the require used previously will still work through at least
146
+ [version 4][pull-96-comment] and possibly beyond; it is effectively an empty
147
+ operation. You are recommended to change your Gemfile as soon as is practical.
148
+
149
+ ```ruby
150
+ require 'mime/types/columnar'
151
+ ```
152
+
153
+ Note that MIME::Type::Columnar and MIME::Types::Columnar are considered private
154
+ variant implementations of MIME::Type and MIME::Types and the specific
155
+ implementation should not be relied upon by consumers of the mime-types library.
156
+ Instead, depend on the public implementations (MIME::Type and MIME::Types) only.
157
+
158
+ ### Cached Storage
159
+
160
+ mime-types supports a cache of MIME types using `Marshal.dump`. The cache is
161
+ invalidated for each version of the mime-types-data gem so that data version
162
+ 3.2015.1201 will not be reused with data version 3.2016.0101. If the environment
163
+ variable `RUBY_MIME_TYPES_CACHE` is set to a cache file, mime-types will attempt
164
+ to load the MIME type registry from the cache file. If it cannot, it will load
165
+ the types normally and then saves the registry to the cache file.
166
+
167
+ The caching works with both full stores and columnar stores. Only the data that
168
+ has been loaded prior to saving the cache will be stored.
169
+
170
+ ## mime-types Modified Semantic Versioning
171
+
172
+ The mime-types library has one version number, but this single version number
173
+ tracks both API changes and registry data changes; this is not wholly compatible
174
+ with all aspects of [Semantic Versioning][semver]; removing a MIME type from the
175
+ registry _could_ be considered a breaking change under some interpretations of
176
+ semantic versioning (as lookups for that particular type would no longer work by
177
+ default).
178
+
179
+ mime-types itself uses a modified semantic versioning scheme. Given the version
180
+ `MAJOR.MINOR`:
181
+
182
+ 1. If an incompatible API (code) change is made, the `MAJOR` version will be
183
+ incremented and both `MINOR` and `PATCH` will be set to zero. Major version
184
+ updates will also generally break Ruby version compatibility guarantees.
185
+
186
+ 2. If an API (code) feature is added that does not break compatibility, the
187
+ `MINOR` version will be incremented and `PATCH` will be set to zero.
188
+
189
+ 3. If there is a bug fix to a feature added in the most recent `MAJOR.MINOR`
190
+ release, the `PATCH` value will be incremented.
191
+
192
+ In practical terms, there will be fewer releases of mime-types focussing on
193
+ features because of the existence of the [mime-types-data][data] gem, and if
194
+ features are marked deprecated in the course of mime-types 3.x, they will not be
195
+ removed until mime-types 4.x or possibly later.
196
+
197
+ [pull-96-comment]: https://github.com/mime-types/ruby-mime-types/pull/96#issuecomment-100725400
198
+ [semver]: https://semver.org
199
+ [data]: https://github.com/mime-types/mime-types-data
data/Rakefile CHANGED
@@ -1,33 +1,34 @@
1
1
  require "rubygems"
2
2
  require "hoe"
3
3
  require "rake/clean"
4
+ require "minitest"
4
5
 
5
- Hoe.plugin :cov
6
- Hoe.plugin :doofus
7
- Hoe.plugin :gemspec2
8
- Hoe.plugin :git2
9
- Hoe.plugin :minitest
6
+ Hoe.plugin :halostatue
10
7
  Hoe.plugin :rubygems
11
8
 
9
+ Hoe.plugins.delete :debug
10
+ Hoe.plugins.delete :newb
11
+ Hoe.plugins.delete :publish
12
+ Hoe.plugins.delete :signing
13
+
12
14
  spec = Hoe.spec "mime-types" do
13
15
  developer("Austin Ziegler", "halostatue@gmail.com")
14
16
 
15
- self.history_file = "History.md"
16
- self.readme_file = "README.rdoc"
17
-
18
- license "MIT"
17
+ self.trusted_release = ENV["rubygems_release_gem"] == "true"
19
18
 
20
19
  require_ruby_version ">= 2.0"
21
20
 
22
- spec_extras[:metadata] = ->(val) { val["rubygems_mfa_required"] = "true" }
21
+ license "MIT"
22
+
23
+ spec_extras[:metadata] = ->(val) {
24
+ val.merge!({"rubygems_mfa_required" => "true"})
25
+ }
23
26
 
24
27
  extra_deps << ["mime-types-data", "~> 3.2015"]
25
28
  extra_deps << ["logger", ">= 0"]
26
29
 
27
- extra_dev_deps << ["hoe", ">= 3.0", "< 5"]
28
- extra_dev_deps << ["hoe-doofus", "~> 1.0"]
29
- extra_dev_deps << ["hoe-gemspec2", "~> 1.1"]
30
- extra_dev_deps << ["hoe-git2", "~> 1.7"]
30
+ extra_dev_deps << ["hoe", "~> 4.0"]
31
+ extra_dev_deps << ["hoe-halostatue", "~> 2.0"]
31
32
  extra_dev_deps << ["hoe-rubygems", "~> 1.0"]
32
33
  extra_dev_deps << ["minitest", "~> 5.0"]
33
34
  extra_dev_deps << ["minitest-autotest", "~> 1.0"]
@@ -37,6 +38,25 @@ spec = Hoe.spec "mime-types" do
37
38
  extra_dev_deps << ["standard", "~> 1.0"]
38
39
  end
39
40
 
41
+ Minitest::TestTask.create :test
42
+ Minitest::TestTask.create :coverage do |t|
43
+ t.test_prelude = <<-RUBY.split($/).join("; ")
44
+ require "simplecov"
45
+ require "simplecov-lcov"
46
+
47
+ SimpleCov::Formatter::LcovFormatter.config do |config|
48
+ config.report_with_single_file = true
49
+ config.lcov_file_name = "lcov.info"
50
+ end
51
+
52
+ SimpleCov.start "test_frameworks" do
53
+ enable_coverage :branch
54
+ primary_coverage :branch
55
+ formatter SimpleCov::Formatter::MultiFormatter.new([SimpleCov::Formatter::HTMLFormatter, SimpleCov::Formatter::LcovFormatter, SimpleCov::Formatter::SimpleFormatter])
56
+ end
57
+ RUBY
58
+ end
59
+
40
60
  namespace :benchmark do
41
61
  task :support do
42
62
  %w[lib support].each { |path|
@@ -53,39 +73,9 @@ namespace :benchmark do
53
73
  )
54
74
  end
55
75
 
56
- desc "Allocation counts"
57
- task :allocations, [:top_x, :mime_types_only] => "benchmark:support" do |_, args|
58
- require "benchmarks/load_allocations"
59
- Benchmarks::LoadAllocations.report(
60
- top_x: args.top_x,
61
- mime_types_only: args.mime_types_only
62
- )
63
- end
64
-
65
- desc "Columnar allocation counts"
66
- task "allocations:columnar", [:top_x, :mime_types_only] => "benchmark:support" do |_, args|
67
- require "benchmarks/load_allocations"
68
- Benchmarks::LoadAllocations.report(
69
- columnar: true,
70
- top_x: args.top_x,
71
- mime_types_only: args.mime_types_only
72
- )
73
- end
74
-
75
- desc "Columnar allocation counts (full load)"
76
- task "allocations:columnar:full", [:top_x, :mime_types_only] => "benchmark:support" do |_, args|
77
- require "benchmarks/load_allocations"
78
- Benchmarks::LoadAllocations.report(
79
- columnar: true,
80
- top_x: args.top_x,
81
- mime_types_only: args.mime_types_only,
82
- full: true
83
- )
84
- end
85
-
86
76
  desc "Memory profiler"
87
77
  task :memory, [:top_x, :mime_types_only] => "benchmark:support" do |_, args|
88
- require "benchmarks/memory_profiler"
78
+ require "benchmarks/profile_memory"
89
79
  Benchmarks::ProfileMemory.report(
90
80
  mime_types_only: args.mime_types_only,
91
81
  top_x: args.top_x
@@ -94,7 +84,7 @@ namespace :benchmark do
94
84
 
95
85
  desc "Columnar memory profiler"
96
86
  task "memory:columnar", [:top_x, :mime_types_only] => "benchmark:support" do |_, args|
97
- require "benchmarks/memory_profiler"
87
+ require "benchmarks/profile_memory"
98
88
  Benchmarks::ProfileMemory.report(
99
89
  columnar: true,
100
90
  mime_types_only: args.mime_types_only,
@@ -104,7 +94,7 @@ namespace :benchmark do
104
94
 
105
95
  desc "Columnar allocation counts (full load)"
106
96
  task "memory:columnar:full", [:top_x, :mime_types_only] => "benchmark:support" do |_, args|
107
- require "benchmarks/memory_profiler"
97
+ require "benchmarks/profile_memory"
108
98
  Benchmarks::ProfileMemory.report(
109
99
  columnar: true,
110
100
  full: true,
@@ -133,53 +123,19 @@ namespace :benchmark do
133
123
  end
134
124
 
135
125
  namespace :profile do
136
- directory "tmp/profile"
137
-
138
- CLEAN.add "tmp"
139
-
140
- def ruby_prof(script)
141
- require "pathname"
142
- output = Pathname("tmp/profile").join(script)
143
- output.mkpath
144
- script = Pathname("support/profile").join("#{script}.rb")
145
-
146
- args = [
147
- "-W0",
148
- "-Ilib",
149
- "-S", "ruby-prof",
150
- "-R", "mime/types",
151
- "-s", "self",
152
- "-p", "multi",
153
- "-f", output.to_s,
154
- script.to_s
155
- ]
156
- ruby args.join(" ")
157
- end
158
-
159
- task full: "tmp/profile" do
160
- ruby_prof "full"
126
+ task full: "benchmark:support" do
127
+ require "profile"
128
+ profile_full
161
129
  end
162
130
 
163
- task columnar: :support do
164
- ruby_prof "columnar"
131
+ task columnar: "benchmark:support" do
132
+ require "profile"
133
+ profile_columnar
165
134
  end
166
135
 
167
- task "columnar:full" => :support do
168
- ruby_prof "columnar_full"
169
- end
170
- end
171
-
172
- if Gem::Version.new(RUBY_VERSION) >= Gem::Version.new("2.0")
173
- namespace :test do
174
- desc "Run test coverage"
175
- task :coverage do
176
- spec.test_prelude = [
177
- 'require "simplecov"',
178
- 'SimpleCov.start("test_frameworks") { command_name "Minitest" }',
179
- 'gem "minitest"'
180
- ].join("; ")
181
- Rake::Task["test"].execute
182
- end
136
+ task "columnar:full" => "benchmark:support" do
137
+ require "profile"
138
+ profile_columnar_full
183
139
  end
184
140
  end
185
141
 
data/SECURITY.md ADDED
@@ -0,0 +1,7 @@
1
+ # mime-types Security
2
+
3
+ ## Security contact information
4
+
5
+ To report a security vulnerability, please use the
6
+ [Tidelift security contact](https://tidelift.com/security). Tidelift will
7
+ coordinate the fix and disclosure.
data/lib/mime/type.rb CHANGED
@@ -94,9 +94,6 @@ class MIME::Type
94
94
  # :startdoc:
95
95
  end
96
96
 
97
- # The released version of the mime-types library.
98
- VERSION = "3.6.0"
99
-
100
97
  include Comparable
101
98
 
102
99
  # :stopdoc:
@@ -683,3 +680,5 @@ class MIME::Type
683
680
  "http://www.iana.org/assignments/media-types/%s" % value
684
681
  end
685
682
  end
683
+
684
+ require "mime/types/version"
@@ -1,7 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require "set"
4
- require "forwardable"
5
4
 
6
5
  # MIME::Types requires a serializable keyed container that returns an empty Set
7
6
  # on a key miss. Hash#default_value cannot be used because, while it traverses
@@ -10,8 +9,6 @@ require "forwardable"
10
9
  # Hash#default_proc cannot be used without a wrapper because it prevents
11
10
  # Marshal serialization (and does not survive the round-trip).
12
11
  class MIME::Types::Container # :nodoc:
13
- extend Forwardable
14
-
15
12
  def initialize(hash = {})
16
13
  @container = {}
17
14
  merge!(hash)
@@ -47,16 +44,49 @@ class MIME::Types::Container # :nodoc:
47
44
  container
48
45
  end
49
46
 
50
- def_delegators :@container,
51
- :==,
52
- :count,
53
- :each,
54
- :each_value,
55
- :empty?,
56
- :flat_map,
57
- :keys,
58
- :select,
59
- :values
47
+ def ==(other)
48
+ container == other
49
+ end
50
+
51
+ def count(*args, &block)
52
+ if args.size == 0
53
+ container.count
54
+ elsif block
55
+ container.count(&block)
56
+ else
57
+ container.count(args.first)
58
+ end
59
+ end
60
+
61
+ def each_pair(&block)
62
+ container.each_pair(&block)
63
+ end
64
+
65
+ alias_method :each, :each_pair
66
+
67
+ def each_value(&block)
68
+ container.each_value(&block)
69
+ end
70
+
71
+ def empty?
72
+ container.empty?
73
+ end
74
+
75
+ def flat_map(&block)
76
+ container.flat_map(&block)
77
+ end
78
+
79
+ def keys
80
+ container.keys
81
+ end
82
+
83
+ def values
84
+ container.values
85
+ end
86
+
87
+ def select(&block)
88
+ container.select(&block)
89
+ end
60
90
 
61
91
  def add(key, value)
62
92
  (container[key] ||= Set.new).add(value)
@@ -9,7 +9,18 @@ module MIME
9
9
  class << self
10
10
  # Configure the MIME::Types logger. This defaults to an instance of a
11
11
  # logger that passes messages (unformatted) through to Kernel#warn.
12
- attr_accessor :logger
12
+ # :attr_accessor: logger
13
+ attr_reader :logger
14
+
15
+ ##
16
+ def logger=(logger) # :nodoc
17
+ @logger =
18
+ if logger.nil?
19
+ NullLogger.new
20
+ else
21
+ logger
22
+ end
23
+ end
13
24
  end
14
25
 
15
26
  class WarnLogger < ::Logger # :nodoc:
@@ -25,13 +36,33 @@ module MIME
25
36
  end
26
37
  end
27
38
 
28
- def initialize(_one, _two = nil, _three = nil)
39
+ def initialize(*)
29
40
  super(nil)
30
41
  @logdev = WarnLogDevice.new
31
42
  @formatter = ->(_s, _d, _p, m) { m }
32
43
  end
33
44
  end
34
45
 
35
- self.logger = WarnLogger.new(nil)
46
+ class NullLogger < ::Logger
47
+ def initialize(*)
48
+ super(nil)
49
+ @logdev = nil
50
+ end
51
+
52
+ def reopen(_)
53
+ self
54
+ end
55
+
56
+ def <<(_)
57
+ end
58
+
59
+ def close
60
+ end
61
+
62
+ def add(_severity, _message = nil, _progname = nil)
63
+ end
64
+ end
65
+
66
+ self.logger = WarnLogger.new
36
67
  end
37
68
  end
@@ -0,0 +1,14 @@
1
+ # frozen_string_literal: true
2
+
3
+ ##
4
+ module MIME
5
+ class Types
6
+ # The released version of the mime-types library.
7
+ VERSION = "3.6.1"
8
+ end
9
+
10
+ class Type
11
+ # The released version of the mime-types library.
12
+ VERSION = MIME::Types::VERSION
13
+ end
14
+ end
data/lib/mime/types.rb CHANGED
@@ -66,9 +66,6 @@ require "mime/type"
66
66
  # puts MIME::Type.simplified('x-appl/x-zip') # => 'appl/zip'
67
67
  #
68
68
  class MIME::Types
69
- # The release version of Ruby MIME::Types
70
- VERSION = MIME::Type::VERSION
71
-
72
69
  include Enumerable
73
70
 
74
71
  # Creates a new MIME::Types registry.
@@ -231,3 +228,4 @@ require "mime/types/loader"
231
228
  require "mime/types/logger"
232
229
  require "mime/types/_columnar"
233
230
  require "mime/types/registry"
231
+ require "mime/types/version"
@@ -1,10 +1,10 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require "mime/type"
4
- require "fileutils"
5
-
6
3
  gem "minitest"
7
4
  require "minitest/focus"
8
5
  require "minitest/hooks"
9
6
 
7
+ require "fileutils"
8
+
9
+ require "mime/type"
10
10
  ENV["RUBY_MIME_TYPES_LAZY_LOAD"] = "yes"