Skip to content

Commit

Permalink
mime-types 2.0
Browse files Browse the repository at this point in the history
A substantial upgrade to the mime-types library. Major features:

- No longer compatible with Ruby 1.8.
- Several major API changes and deprecations.
- The default mime-types registry is now stored as JSON.
- Improved developer tools.
- Improved repackager tools.
- Fixes #28.
- Fixes #36.
- Fixes #37.
- Fixes #42.
- Fixes #43.
- Fixes #44.
  • Loading branch information
halostatue committed Oct 20, 2013
1 parent ade226b commit 954a460
Show file tree
Hide file tree
Showing 72 changed files with 14,871 additions and 4,482 deletions.
5 changes: 5 additions & 0 deletions .autotest
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# -*- ruby encoding: utf-8 -*-

Autotest.add_hook :initialize do |at|
at.testlib = ".minitest"
end
2 changes: 2 additions & 0 deletions .minitest.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
gem "minitest"
require "minitest/autorun"
4 changes: 0 additions & 4 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,8 @@ rvm:
- 2.0.0
- 1.9.3
- 1.9.2
- 1.8.7
- jruby-19mode
- jruby-18mode
- rbx-19mode
- rbx-18mode
- ree
# - ruby-head
# - jruby-head
matrix:
Expand Down
22 changes: 11 additions & 11 deletions Contributing.rdoc
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
== Contributing

I value any contribution to MIME::Types you can provide: a bug report, a feature
I value any contribution to mime-types you can provide: a bug report, a feature
request, or code contributions.

Code contributions to MIME::Types are especially <del>welcome</del>encouraged.
Because MIME::Types is a complex codebase, there are a few guidelines:
Code contributions to mime-types are especially <del>welcome</del>encouraged.
Because mime-types is a complex codebase, there are a few guidelines:

* Changes (aside from new MIME types) <strong>will not</strong> be accepted
without tests. The test suite is written with MiniTest.
Expand All @@ -20,11 +20,11 @@ Because MIME::Types is a complex codebase, there are a few guidelines:
=== Test Dependencies

To run the test suite, you will need to install the development dependencies
for MIME::Types. If you have Bundler, you can accomplish this easily:
for mime-types. If you have Bundler, you can accomplish this easily:

$ bundle install

MIME::Types uses Ryan Davis’s excellent {Hoe}[https://github.com/seattlerb/hoe]
mime-types uses Ryan Davis’s excellent {Hoe}[https://github.com/seattlerb/hoe]
to manage the release process, and it adds a number of rake tasks. You will
mostly be interested in:

Expand All @@ -42,20 +42,20 @@ will do.
Here's the most direct way to get your work merged into the project:

* Fork the project.
* Clone down your fork (+git clone git://github.com/<username>/mime-types.git+).
* Create a topic branch to contain your change (+git checkout -b my\_awesome\_feature+).
* Clone down your fork (<tt>git clone git://github.com/<username>/mime-types.git</tt>).
* Create a topic branch to contain your change (<tt>git checkout -b my\_awesome\_feature</tt>).
* Hack away, add tests. Not necessarily in that order.
* Make sure everything still passes by running `rake`.
* Make sure everything still passes by running +rake+.
* If necessary, rebase your commits into logical chunks, without errors.
* Push the branch up (+git push origin my\_awesome\_feature+).
* Push the branch up (<tt>git push origin my\_awesome\_feature</tt>).
* Create a pull request against halostatue/mime-types and describe what your
change does and the why you think it should be merged.

=== Contributors

* Austin Ziegler created MIME::Types.
* Austin Ziegler created mime-types.

Thanks to everyone else who has contributed to MIME::Types:
Thanks to everyone else who has contributed to mime-types:

* Andre Pankratz
* Mauricio Linhares
Expand Down
71 changes: 69 additions & 2 deletions History.rdoc
Original file line number Diff line number Diff line change
@@ -1,3 +1,70 @@
== 2.0 / YYYY-MM-DD

* API Changes:
* mime-types is no longer compatible with Ruby 1.8.
* MIME::InvalidContentType has been renamed to
MIME::Type::InvalidContentType.
* API Changes (MIME::Type):
* Assignment of an invalid encoding to MIME::Type#encoding= will raise a
MIME::Type::InvalidEncoding exception rather than a plain ArgumentError.
* MIME::Type#url has been renamed to MIME::Type#references.
* MIME::Type#use_instead is now tracked as its own attribute, not as part of
MIME::Type#docs.
* MIME::Type#system, MIME::Type#system?, MIME::Type#platform?,
MIME::Type#to_str, MIME::Type#to_a, MIME::Type#to_hash,
MIME::Type.from_array, MIME::Type.from_hash, and MIME::Type.from_mime_type
have been deprecated for removal.
* Implemented YAML object encoding and decoding methods,
MIME::Type#encode_with and MIME::Type#init_with.
* Implemented JSON hash encoding methods.
* Modified initialization to handle deserialization from JSON.
* API Changes (MIME::Types):
* MIME type caching has been extracted to its own class. It is structurally
similar to what was introduced with mime-types 1.25, but is no longer
considered an experimental interface.
* MIME type loading has been extracted to its own class. Loading has changed
substantially.
* MIME::Types#add_type_variant and MIME::Types#index_extensions have been
deprecated as public methods. They will be private in a future version.
* MIME::Types#defined_types, MIME::Types.cache_file,
MIME::Types.add_type_variant, and MIME::Types.index_extensions have been
deprecated for removal.
* Default Registry Changes:
* The default registry is now a file in the directory data/, located via
MIME::Types::Loader::PATH. +PATH+ is defined in the file
lib/mime/types/path.rb so that system packagers only have to modify one
file in order to put the registry in a location that is not where a gem
version of mime-types would expect it. This resolves issue #36, reported by
postmodern. https://github.com/halostatue/mime-types/pull/36
* The default registry is now a single file in JSON format. This resolves
issue #28 reported by jasonlor (an error with mime-types in MacRuby).
https://github.com/halostatue/mime-types/pull/28
* The default registry is compiled from YAML files in type-lists/, resolving
issue #37 reported by postmodern requesting an easier-to-edit format.
https://github.com/halostatue/mime-types/pull/37
* New or Updated MIME Types:
* Major updates to the registered MIME type list from IANA using the improved
developer tools.
* Added:
* application/xhtml\+xml (HTML5)
* multipart/x-mixed-replace (HTML5)
* application/vnd.apple.pkpass (Apple PassBook) with extension pkpass.
* Modified:
* application/gzip (RFC6713) added extension (gz) and encoding.
* application/epub\+zip is not a registered MIME type.
* application/rss\+xml is not a registered MIME type.
* application/x-director reported incorrect extensions.
* application/x-gzip marked as obsolete (use application/gzip instead).
* application/x-maker marked as obsolete (use application/vnd.framemaker
instead).
* image/webp is not a registered MIME type; added a URL to Google's
proposed standard document.
* text/html added URL to the HTML5 specification.
* text/cache-manifest added URL to the HTML5 specification.
* text/plain (VMS .doc files) marked as non-standard.
* Documentation:
* Administrivia:

== 1.25 / 2013-08-30

* New Features:
Expand All @@ -10,7 +77,7 @@
* New extensions:
* mjpeg (video/x-motion-jpeg) based on a change by punkrats, found in the
vidibus fork.
* Modernized MiniTest configuration.
* Modernized Minitest configuration.

== 1.24 / 2013-08-14

Expand Down Expand Up @@ -137,7 +204,7 @@
* New MIME Types:
* Types reported in https://github.com/halostatue/mime-types/issues/6:
* CoffeeScript (text/x-coffeescript; .coffee; 8bit).
* AIR (application/vnd.adobe.air-applicationinstaller-package+zip, .air; base64).
* AIR (application/vnd.adobe.air-applicationinstaller-package\+zip, .air; base64).
* WOFF (application/font-woff; .woff; base64).
* TrueType (application/x-font-truetype; .ttf; base64).
* OpenType (application/x-font-opentype; .otf; base64).
Expand Down
2 changes: 1 addition & 1 deletion Licence.rdoc
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ licensing terms.

=== MIT License

this software and associated documentation files (the "Software"), to deal in
This software and associated documentation files (the "Software"), to deal in
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
of the Software, and to permit persons to whom the Software is furnished to do
Expand Down
39 changes: 15 additions & 24 deletions Manifest.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
.autotest
.gemtest
.hoerc
.minitest.rb
.travis.yml
Contributing.rdoc
Gemfile
Expand All @@ -8,35 +10,24 @@ Licence.rdoc
Manifest.txt
README.rdoc
Rakefile
data/mime-types.json
docs/COPYING.txt
docs/artistic.txt
lib/mime-types.rb
lib/mime.rb
lib/mime/type.rb
lib/mime/types.rb
lib/mime/types/application
lib/mime/types/application.mac
lib/mime/types/application.nonstandard
lib/mime/types/application.obsolete
lib/mime/types/audio
lib/mime/types/audio.nonstandard
lib/mime/types/audio.obsolete
lib/mime/types/image
lib/mime/types/image.nonstandard
lib/mime/types/image.obsolete
lib/mime/types/message
lib/mime/types/message.obsolete
lib/mime/types/model
lib/mime/types/multipart
lib/mime/types/multipart.nonstandard
lib/mime/types/multipart.obsolete
lib/mime/types/other.nonstandard
lib/mime/types/text
lib/mime/types/text.nonstandard
lib/mime/types/text.obsolete
lib/mime/types/text.vms
lib/mime/types/video
lib/mime/types/video.nonstandard
lib/mime/types/video.obsolete
lib/mime/types/cache.rb
lib/mime/types/loader.rb
lib/mime/types/loader_path.rb
support/benchmarker.rb
support/convert.rb
support/iana_downloader.rb
test/fixture/old-data
test/minitest_helper.rb
test/test_mime_type.rb
test/test_mime_types.rb
test/test_mime_types_cache.rb
test/test_mime_types_class.rb
test/test_mime_types_lazy.rb
test/test_mime_types_loader.rb
72 changes: 26 additions & 46 deletions README.rdoc
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
= MIME::Types for Ruby
= mime-types

home :: http://mime-types.rubyforge.org/
code :: https://github.com/halostatue/mime-types/
Expand All @@ -9,53 +9,33 @@ continuous integration :: {<img src="https://travis-ci.org/halostatue/mime-types

== Description

This library allows for the identification of a file's likely MIME content
type. This is release 1.25, adding experimental caching and lazy loading
functionality.

The caching and lazy loading features were initially implemented by Greg
Brockman (gdb). As these features are experimental, they are disabled by
default and must be enabled through the use of environment variables. The cache
is invalidated on a per-version basis; the cache for version 1.25 will not be
reused for version 1.26.

To use lazy loading, set the environment variable +RUBY_MIME_TYPES_LAZY_LOAD+
to any value other than 'false'. When using lazy loading, the initial startup
of MIME::Types is around 12–25× faster than normal startup (on my system,
normal startup is about 90 ms; lazy startup is about 4 ms). This isn't
generally useful, however, as the MIME::Types database has not been loaded.
Lazy startup and load is just *slightly* faster—around 1 ms. The real advantage
comes from using the cache.

To enable the cache, set the environment variable +RUBY_MIME_TYPES_CACHE+ to a
filename where MIME::Types will have read-write access. The first time a new
version of MIME::Types is run using this file, it will be created, taking a
little longer than normal. Subsequent loads using the same cache file will be
approximately 3½× faster (25 ms) than normal loads. This can be combined with
+RUBY_MIME_TYPES_LAZY_LOAD+, but this is *not* recommended in a multithreaded
or multiprocess environment where all threads or processes will be using the
same cache file.

As the caching interface is still experimental, the only values cached are the
default MIME::Types database, not any custom MIME::Types added by users.

MIME types are used in MIME-compliant communications, as in e-mail or HTTP
traffic, to indicate the type of content which is transmitted. MIME::Types
provides the ability for detailed information about MIME entities (provided as
a set of MIME::Type objects) to be determined and used programmatically. There
are many types defined by RFCs and vendors, so the list is long but not
complete; don't hesitate to ask to add additional information. This library
follows the IANA collection of MIME types (see below for reference).

MIME::Types for Ruby was originally based on MIME::Types for Perl by Mark
Overmeer, copyright 2001 - 2009. As of version 1.15, the data format for the
MIME::Type list has changed and the synchronization will no longer happen.

MIME::Types is built to conform to the MIME types of RFCs 2045 and 2231. It
tracks the {IANA registry}[http://www.iana.org/assignments/media-types/]
The mime-types library provides a library and registry for information about
MIME content type definitions. It can be used to determine defined filename
extensions for MIME types, or to use filename extensions to look up the likely
MIME type definitions.

MIME content types are used in MIME-compliant communications, as in e-mail or
HTTP traffic, to indicate the type of content which is transmitted. The
mime-types library provides the ability for detailed information about MIME
entities (provided as an enumerable collection of MIME::Type objects) to be
determined and used programmatically. There are many types defined by RFCs and
vendors, so the list is long but by definition incomplete; don't hesitate to to
add additional type definitions (see Contributing.rdoc). The primary sources
for MIME type definitions found in mime-types is the IANA collection of
registrations (see below for the link), RFCs, and W3C recommendations.

The mime-types library uses semantic versioning. This is release 2.0; there are
incompatible changes in the API provided by mime-types, mostly around registry
initialization (see History.rdoc for full details), and the removal of support
for Ruby 1.8 interpreters.

mime-types (previously called MIME::Types for Ruby) was originally based on
MIME::Types for Perl by Mark Overmeer, copyright 2001 - 2009. It is built to
conform to the MIME types of RFCs 2045 and 2231. It tracks the {IANA
registry}[http://www.iana.org/assignments/media-types/]
({ftp}[ftp://ftp.iana.org/assignments/media-types]) with some unofficial types
added from the {LTSW collection}[http://www.ltsw.se/knbase/internet/mime.htp]
and added by the users of MIME::Types.
and added by the users of mime-types.

== Synopsis

Expand Down
Loading

0 comments on commit 954a460

Please sign in to comment.