mime-types 1.16 → 3.5.2

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.rdoc ADDED
@@ -0,0 +1,194 @@
1
+ = mime-types for Ruby
2
+
3
+ home :: https://github.com/mime-types/ruby-mime-types/
4
+ code :: https://github.com/mime-types/ruby-mime-types/
5
+ bugs :: https://github.com/mime-types/ruby-mime-types/issues
6
+ rdoc :: http://rdoc.info/gems/mime-types/
7
+ clog :: https://github.com/mime-types/ruby-mime-types/blob/master/History.md
8
+ continuous integration :: {<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]
9
+ test coverage :: {<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]
10
+
11
+ == Description
12
+
13
+ The mime-types library provides a library and registry for information about
14
+ MIME content type definitions. It can be used to determine defined filename
15
+ extensions for MIME types, or to use filename extensions to look up the likely
16
+ MIME type definitions.
17
+
18
+ Version 3.0 is a major release that requires Ruby 2.0 compatibility and removes
19
+ deprecated functions. The columnar registry format introduced in 2.6 has been
20
+ made the primary format; the registry data has been extracted from this library
21
+ and put into {mime-types-data}[https://github.com/mime-types/mime-types-data].
22
+ Additionally, mime-types is now licensed exclusively under the MIT licence and
23
+ there is a code of conduct in effect. There are a number of other smaller
24
+ changes described in the History file.
25
+
26
+ === About MIME Media Types
27
+
28
+ MIME content types are used in MIME-compliant communications, as in e-mail or
29
+ HTTP traffic, to indicate the type of content which is transmitted. The
30
+ mime-types library provides the ability for detailed information about MIME
31
+ entities (provided as an enumerable collection of MIME::Type objects) to be
32
+ determined and used. There are many types defined by RFCs and vendors, so the
33
+ list is long but by definition incomplete; don't hesitate to add additional
34
+ type definitions. MIME type definitions found in mime-types are from RFCs, W3C
35
+ recommendations, the {IANA Media Types
36
+ registry}[https://www.iana.org/assignments/media-types/media-types.xhtml], and
37
+ user contributions. It conforms to RFCs 2045 and 2231.
38
+
39
+ === mime-types 3.x
40
+
41
+ Users are encouraged to upgrade to mime-types 3.x as soon as is practical.
42
+ mime-types 3.x requires Ruby 2.0 compatibility and a simpler licensing scheme.
43
+
44
+ == Synopsis
45
+
46
+ MIME types are used in MIME entities, as in email or HTTP traffic. It is useful
47
+ at times to have information available about MIME types (or, inversely, about
48
+ files). A MIME::Type stores the known information about one MIME type.
49
+
50
+ require 'mime/types'
51
+
52
+ plaintext = MIME::Types['text/plain'] # => [ text/plain ]
53
+ text = plaintext.first
54
+ puts text.media_type # => 'text'
55
+ puts text.sub_type # => 'plain'
56
+
57
+ puts text.extensions.join(' ') # => 'txt asc c cc h hh cpp hpp dat hlp'
58
+ puts text.preferred_extension # => 'txt'
59
+ puts text.friendly # => 'Text Document'
60
+ puts text.i18n_key # => 'text.plain'
61
+
62
+ puts text.encoding # => quoted-printable
63
+ puts text.default_encoding # => quoted-printable
64
+ puts text.binary? # => false
65
+ puts text.ascii? # => true
66
+ puts text.obsolete? # => false
67
+ puts text.registered? # => true
68
+ puts text.provisional? # => false
69
+ puts text.complete? # => true
70
+
71
+ puts text # => 'text/plain'
72
+
73
+ puts text == 'text/plain' # => true
74
+ puts 'text/plain' == text # => true
75
+ puts text == 'text/x-plain' # => false
76
+ puts 'text/x-plain' == text # => false
77
+
78
+ puts MIME::Type.simplified('x-appl/x-zip') # => 'x-appl/x-zip'
79
+ puts MIME::Type.i18n_key('x-appl/x-zip') # => 'x-appl.x-zip'
80
+
81
+ puts text.like?('text/x-plain') # => true
82
+ puts text.like?(MIME::Type.new('x-text/x-plain')) # => true
83
+
84
+ puts text.xrefs.inspect # => { "rfc" => [ "rfc2046", "rfc3676", "rfc5147" ] }
85
+ puts text.xref_urls # => [ "http://www.iana.org/go/rfc2046",
86
+ # "http://www.iana.org/go/rfc3676",
87
+ # "http://www.iana.org/go/rfc5147" ]
88
+
89
+ xtext = MIME::Type.new('x-text/x-plain')
90
+ puts xtext.media_type # => 'text'
91
+ puts xtext.raw_media_type # => 'x-text'
92
+ puts xtext.sub_type # => 'plain'
93
+ puts xtext.raw_sub_type # => 'x-plain'
94
+ puts xtext.complete? # => false
95
+
96
+ puts MIME::Types.any? { |type| type.content_type == 'text/plain' } # => true
97
+ puts MIME::Types.all?(&:registered?) # => false
98
+
99
+ # Various string representations of MIME types
100
+ qcelp = MIME::Types['audio/QCELP'].first # => audio/QCELP
101
+ puts qcelp.content_type # => 'audio/QCELP'
102
+ puts qcelp.simplified # => 'audio/qcelp'
103
+
104
+ xwingz = MIME::Types['application/x-Wingz'].first # => application/x-Wingz
105
+ puts xwingz.content_type # => 'application/x-Wingz'
106
+ puts xwingz.simplified # => 'application/x-wingz'
107
+
108
+ === Columnar Store
109
+
110
+ mime-types uses as its primary registry storage format a columnar storage
111
+ format reducing the default memory footprint. This is done by selectively
112
+ loading the data on a per-attribute basis. When the registry is first loaded
113
+ from the columnar store, only the canonical MIME content type and known
114
+ extensions and the MIME type will be connected to its loading registry. When
115
+ other data about the type is required (including +preferred_extension+,
116
+ <tt>obsolete?</tt>, and <tt>registered?</tt>) that data is loaded from its own
117
+ column file for all types in the registry.
118
+
119
+ The load of any column data is performed with a Mutex to ensure that types are
120
+ updated safely in a multithreaded environment. Benchmarks show that while
121
+ columnar data loading is slower than the JSON store, it cuts the memory use by
122
+ a third over the JSON store.
123
+
124
+ If you prefer to load all the data at once, this can be specified in your
125
+ application Gemfile as:
126
+
127
+ gem 'mime-types', require: 'mime/types/full'
128
+
129
+ Projects that do not use Bundler should +require+ the same:
130
+
131
+ require 'mime/types/full'
132
+
133
+ Libraries that use mime-types are discouraged from choosing the JSON store.
134
+
135
+ For applications and clients that used mime-types 2.6 when the columnar store
136
+ was introduced, the require used previously will still work through at least
137
+ {version
138
+ 4}[https://github.com/mime-types/ruby-mime-types/pull/96#issuecomment-100725400]
139
+ and possibly beyond; it is effectively an empty operation. You are recommended
140
+ to change your Gemfile as soon as is practical.
141
+
142
+ require 'mime/types/columnar'
143
+
144
+ Note that MIME::Type::Columnar and MIME::Types::Columnar are considered private
145
+ variant implementations of MIME::Type and MIME::Types and the specific
146
+ implementation should not be relied upon by consumers of the mime-types
147
+ library. Instead, depend on the public implementations (MIME::Type and
148
+ MIME::Types) only.
149
+
150
+ === Cached Storage
151
+
152
+ mime-types supports a cache of MIME types using <tt>Marshal.dump</tt>. The
153
+ cache is invalidated for each version of the mime-types-data gem so that data
154
+ version 3.2015.1201 will not be reused with data version 3.2016.0101. If the
155
+ environment variable +RUBY_MIME_TYPES_CACHE+ is set to a cache file, mime-types
156
+ will attempt to load the MIME type registry from the cache file. If it cannot,
157
+ it will load the types normally and then saves the registry to the cache file.
158
+
159
+ The caching works with both full stores and columnar stores. Only the data that
160
+ has been loaded prior to saving the cache will be stored.
161
+
162
+ == mime-types Modified Semantic Versioning
163
+
164
+ The mime-types library has one version number, but this single version number
165
+ tracks both API changes and registry data changes; this is not wholly
166
+ compatible with all aspects of {Semantic Versioning}[http://semver.org/];
167
+ removing a MIME type from the registry *could* be considered a breaking change
168
+ under some interpretations of semantic versioning (as lookups for that
169
+ particular type would no longer work by default).
170
+
171
+ mime-types uses a modified semantic versioning scheme. Given the version
172
+ MAJOR.MINOR:
173
+
174
+ 1. If an incompatible API (code) change is made, the MAJOR version will be
175
+ incremented, MINOR will be set to zero, and PATCH will be reset to the
176
+ implied zero.
177
+
178
+ 2. If an API (code) feature is added that does not break compatibility, the
179
+ MINOR version will be incremented and PATCH will be reset to the implied zero.
180
+
181
+ 3. If there is a bugfix to a feature added in the most recent MAJOR.MINOR
182
+ release, the implied PATCH value will be incremented resulting in
183
+ MAJOR.MINOR.PATCH.
184
+
185
+ In practical terms, there will be fewer releases of mime-types focussing on
186
+ features because of the existence of the [mime-types-data][] gem, and if
187
+ features are marked deprecated in the course of mime-types 3.x, they will not
188
+ be removed until mime-types 4.x or possibly later.
189
+
190
+ {Code of Conduct}[Code-of-Conduct_md.html]
191
+
192
+ {Contributing}[Contributing_md.html]
193
+
194
+ {Licence}[Licence_md.html]