mime-types 1.24 → 1.25

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.
@@ -0,0 +1,15 @@
1
+ ---
2
+ !binary "U0hBMQ==":
3
+ metadata.gz: !binary |-
4
+ ZjkzNjc3YzY2ZTY3YTU2MDhkYjE3MzQ0MThmZWI0NjU5NWEzMDA1Mg==
5
+ data.tar.gz: !binary |-
6
+ MzY2ZmU2Nzc4YzNhZjJiMTYzNjc0ODdiMzc2NjE3NzQ1MTk3YzE5ZQ==
7
+ !binary "U0hBNTEy":
8
+ metadata.gz: !binary |-
9
+ ZmU3NTI2ZDQ3MjdlNWQ2YWYwNjNkNDkwNDEyNGYzZGRiZTYyMjNjMzY1MTQw
10
+ MjIxZmFkZmRhNTNmNmJhNWZmYWExZjllYWMxOWZjZjFmZGI1ODc4MTZiOGEz
11
+ YWI2NGVjNjAyNmIyYzI5MTc0MzNjNjJiMDRlZDdkN2I1NzVhNGE=
12
+ data.tar.gz: !binary |-
13
+ Nzk0Mjg1NWViZTRkZWRjNzliZmY4OTFlOTQ3ODgxYjI2MWJjY2IzNTg5NDlk
14
+ Nzc5OGY3MTY0NDA1Y2Q5ZjUwYzQ1YzRkZmE1N2M2MWEwMjVkNDMzMjFmZmVi
15
+ YjJkY2U0MzMzM2QwYjg0ZDNhODlhNDQ4OTMxOTZiN2Y0MjRjZDY=
Binary file
data.tar.gz.sig CHANGED
Binary file
@@ -17,8 +17,8 @@ rvm:
17
17
  - rbx-19mode
18
18
  - rbx-18mode
19
19
  - ree
20
- - ruby-head
21
- - jruby-head
20
+ # - ruby-head
21
+ # - jruby-head
22
22
  matrix:
23
23
  allow_failures:
24
24
  - rvm:
@@ -57,12 +57,13 @@ Here's the most direct way to get your work merged into the project:
57
57
 
58
58
  Thanks to everyone else who has contributed to MIME::Types:
59
59
 
60
- * Andre Pankratz
61
- * Mauricio Linhares
62
- * Richard Hirner
63
- * Todd Carrico
64
- * Garret Alfert
65
- * Hans de Graaff
66
- * Henrik Hodne
67
- * Martin d'Allens
68
- * cgat
60
+ * Andre Pankratz
61
+ * Mauricio Linhares
62
+ * Richard Hirner
63
+ * Todd Carrico
64
+ * Garret Alfert
65
+ * Hans de Graaff
66
+ * Henrik Hodne
67
+ * Martin d'Allens
68
+ * cgat
69
+ * Greg Brockman
@@ -1,3 +1,17 @@
1
+ == 1.25 / 2013-08-30
2
+
3
+ * New Features:
4
+ * Adding lazy loading and caching functionality to the default data based on
5
+ work done by Greg Brockman (gdb).
6
+ * Bugs:
7
+ * Force the default internal application encoding to be used when reading the
8
+ MIME types database. Based on a change by briangamble, found in the rapid7
9
+ fork.
10
+ * New extensions:
11
+ * mjpeg (video/x-motion-jpeg) based on a change by punkrats, found in the
12
+ vidibus fork.
13
+ * Modernized MiniTest configuration.
14
+
1
15
  == 1.24 / 2013-08-14
2
16
 
3
17
  * Code Climate:
@@ -38,3 +38,5 @@ lib/mime/types/video.nonstandard
38
38
  lib/mime/types/video.obsolete
39
39
  test/test_mime_type.rb
40
40
  test/test_mime_types.rb
41
+ test/test_mime_types_cache.rb
42
+ test/test_mime_types_lazy.rb
@@ -10,8 +10,34 @@ continuous integration :: {<img src="https://travis-ci.org/halostatue/mime-types
10
10
  == Description
11
11
 
12
12
  This library allows for the identification of a file's likely MIME content
13
- type. This is release 1.24, adding and updating a few MIME types and fixing
14
- some issues with documentation.
13
+ type. This is release 1.25, adding experimental caching and lazy loading
14
+ functionality.
15
+
16
+ The caching and lazy loading features were initially implemented by Greg
17
+ Brockman (gdb). As these features are experimental, they are disabled by
18
+ default and must be enabled through the use of environment variables. The cache
19
+ is invalidated on a per-version basis; the cache for version 1.25 will not be
20
+ reused for version 1.26.
21
+
22
+ To use lazy loading, set the environment variable +RUBY_MIME_TYPES_LAZY_LOAD+
23
+ to any value other than 'false'. When using lazy loading, the initial startup
24
+ of MIME::Types is around 12–25× faster than normal startup (on my system,
25
+ normal startup is about 90 ms; lazy startup is about 4 ms). This isn't
26
+ generally useful, however, as the MIME::Types database has not been loaded.
27
+ Lazy startup and load is just *slightly* faster—around 1 ms. The real advantage
28
+ comes from using the cache.
29
+
30
+ To enable the cache, set the environment variable +RUBY_MIME_TYPES_CACHE+ to a
31
+ filename where MIME::Types will have read-write access. The first time a new
32
+ version of MIME::Types is run using this file, it will be created, taking a
33
+ little longer than normal. Subsequent loads using the same cache file will be
34
+ approximately 3½× faster (25 ms) than normal loads. This can be combined with
35
+ +RUBY_MIME_TYPES_LAZY_LOAD+, but this is *not* recommended in a multithreaded
36
+ or multiprocess environment where all threads or processes will be using the
37
+ same cache file.
38
+
39
+ As the caching interface is still experimental, the only values cached are the
40
+ default MIME::Types database, not any custom MIME::Types added by users.
15
41
 
16
42
  MIME types are used in MIME-compliant communications, as in e-mail or HTTP
17
43
  traffic, to indicate the type of content which is transmitted. MIME::Types
data/Rakefile CHANGED
@@ -33,6 +33,46 @@ spec = Hoe.spec 'mime-types' do
33
33
  self.extra_dev_deps << ['rake', '~> 10.0']
34
34
  end
35
35
 
36
+ def reload_mime_types(repeats = 1, force_load = false)
37
+ repeats.times {
38
+ Object.send(:remove_const, :MIME) if defined? MIME
39
+ load 'lib/mime/types.rb'
40
+ MIME::Types.send(:__types__) if force_load
41
+ }
42
+ end
43
+
44
+ desc 'Benchmark'
45
+ task :benchmark, :repeats do |t, args|
46
+ repeats = args.repeats.to_i
47
+ repeats = 50 if repeats.zero?
48
+ require 'benchmark'
49
+ $LOAD_PATH.unshift 'lib'
50
+
51
+ cache_file = File.expand_path('../cache.mtx', __FILE__)
52
+ rm cache_file if File.exist? cache_file
53
+
54
+ Benchmark.bm(17) do |x|
55
+ x.report("Normal:") { reload_mime_types repeats }
56
+
57
+ ENV['RUBY_MIME_TYPES_LAZY_LOAD'] = 'yes'
58
+ x.report("Lazy:") { reload_mime_types repeats }
59
+ x.report("Lazy+Load:") { reload_mime_types repeats, true }
60
+
61
+ ENV.delete('RUBY_MIME_TYPES_LAZY_LOAD')
62
+
63
+ ENV['RUBY_MIME_TYPES_CACHE'] = cache_file
64
+ reload_mime_types
65
+
66
+ x.report("Cached:") { reload_mime_types repeats }
67
+ ENV['RUBY_MIME_TYPES_LAZY_LOAD'] = 'yes'
68
+ x.report("Lazy Cached:") { reload_mime_types repeats }
69
+ x.report("Lazy Cached Load:") { reload_mime_types repeats, true }
70
+
71
+ end
72
+
73
+ rm cache_file
74
+ end
75
+
36
76
  namespace :mime do
37
77
  desc "Download the current MIME type registrations from IANA."
38
78
  task :iana, :save, :destination do |t, args|
@@ -33,7 +33,7 @@ module MIME
33
33
  #
34
34
  class Type
35
35
  # The released version of Ruby MIME::Types
36
- VERSION = '1.24'
36
+ VERSION = '1.25'
37
37
 
38
38
  include Comparable
39
39
 
@@ -557,28 +557,39 @@ module MIME
557
557
  # ftp://ftp.iana.org/assignments/media-types with some unofficial types
558
558
  # added from the the collection at
559
559
  # http://www.ltsw.se/knbase/internet/mime.htp
560
- #
561
- # This is originally based on Perl MIME::Types by Mark Overmeer.
562
- #
563
- # = Author
564
- # Copyright:: Copyright 2002–2013 by Austin Ziegler
565
- # <austin@rubyforge.org>
566
- # Version:: 1.20.1
567
- # Licence:: See Licence.rdoc
568
- # See Also:: http://www.iana.org/assignments/media-types/
569
- # http://www.ltsw.se/knbase/internet/mime.htp
570
- #
571
560
  class Types
572
561
  # The released version of Ruby MIME::Types
573
- VERSION = MIME::Type::VERSION
562
+ VERSION = MIME::Type::VERSION
563
+ DATA_VERSION = (VERSION.to_f * 100).to_i
574
564
 
575
- # The data version.
565
+ # The data version.
576
566
  attr_reader :data_version
577
567
 
578
- def initialize(data_version = nil)
579
- @type_variants = Hash.new { |h, k| h[k] = [] }
580
- @extension_index = Hash.new { |h, k| h[k] = [] }
581
- @data_version = data_version
568
+ class HashWithArrayDefault < Hash # :nodoc:
569
+ def initialize
570
+ super { |h, k| h[k] = [] }
571
+ end
572
+
573
+ def marshal_dump
574
+ {}.merge(self)
575
+ end
576
+
577
+ def marshal_load(hash)
578
+ self.merge!(hash)
579
+ end
580
+ end
581
+
582
+ class CacheContainer # :nodoc:
583
+ attr_reader :version, :data
584
+ def initialize(version, data)
585
+ @version, @data = version, data
586
+ end
587
+ end
588
+
589
+ def initialize(data_version = DATA_VERSION)
590
+ @type_variants = HashWithArrayDefault.new
591
+ @extension_index = HashWithArrayDefault.new
592
+ @data_version = data_version
582
593
  end
583
594
 
584
595
  def add_type_variant(mime_type) #:nodoc:
@@ -592,19 +603,19 @@ module MIME
592
603
  def defined_types #:nodoc:
593
604
  @type_variants.values.flatten
594
605
  end
595
-
606
+
596
607
  # Returns the number of known types. A shortcut of MIME::Types[//].size.
597
608
  # (Keep in mind that this is memory intensive, cache the result to spare
598
609
  # resources)
599
610
  def count
600
611
  defined_types.size
601
612
  end
602
-
613
+
603
614
  def each
604
615
  defined_types.each { |t| yield t }
605
616
  end
606
617
 
607
- @__types__ = self.new(VERSION)
618
+ @__types__ = nil
608
619
 
609
620
  # Returns a list of MIME::Type objects, which may be empty. The optional
610
621
  # flag parameters are :complete (finds only complete MIME::Type objects)
@@ -633,22 +644,16 @@ module MIME
633
644
  # 6. Obsolete definitions use-instead clauses are compared.
634
645
  # 7. Sort on name.
635
646
  def [](type_id, flags = {})
636
- if type_id.kind_of?(Regexp)
637
- matches = []
638
- @type_variants.each_key do |k|
639
- matches << @type_variants[k] if k =~ type_id
640
- end
641
- matches.flatten!
642
- elsif type_id.kind_of?(MIME::Type)
643
- matches = [type_id]
644
- else
645
- matches = @type_variants[MIME::Type.simplified(type_id)]
646
- end
647
+ matches = case type_id
648
+ when MIME::Type
649
+ @type_variants[type_id.simplified]
650
+ when Regexp
651
+ match(type_id)
652
+ else
653
+ @type_variants[MIME::Type.simplified(type_id)]
654
+ end
647
655
 
648
- matches.delete_if { |e| not e.complete? } if flags[:complete]
649
- matches.delete_if { |e| not e.platform? } if flags[:platform]
650
-
651
- matches.sort { |a, b| a.priority_compare(b) }
656
+ prune_matches(matches, flags).sort { |a, b| a.priority_compare(b) }
652
657
  end
653
658
 
654
659
  # Return the list of MIME::Types which belongs to the file based on its
@@ -686,7 +691,7 @@ module MIME
686
691
  else
687
692
  if @type_variants.include?(mime_type.simplified)
688
693
  if @type_variants[mime_type.simplified].include?(mime_type)
689
- warn "Type #{mime_type} already registered as a variant of #{mime_type.simplified}." unless defined? MIME::Types::STARTUP
694
+ warn "Type #{mime_type} already registered as a variant of #{mime_type.simplified}." unless defined? MIME::Types::LOAD
690
695
  end
691
696
  end
692
697
  add_type_variant(mime_type)
@@ -695,13 +700,29 @@ module MIME
695
700
  end
696
701
  end
697
702
 
703
+ private
704
+ def prune_matches(matches, flags)
705
+ matches.delete_if { |e| not e.complete? } if flags[:complete]
706
+ matches.delete_if { |e| not e.platform? } if flags[:platform]
707
+ matches
708
+ end
709
+
710
+ def match(pattern)
711
+ matches = @type_variants.select { |k, v| k =~ pattern }
712
+ if matches.respond_to? :values
713
+ matches.values.flatten
714
+ else
715
+ matches.map { |m| m.last }.flatten
716
+ end
717
+ end
718
+
698
719
  class << self
699
720
  def add_type_variant(mime_type) #:nodoc:
700
- @__types__.add_type_variant(mime_type)
721
+ __types__.add_type_variant(mime_type)
701
722
  end
702
723
 
703
724
  def index_extensions(mime_type) #:nodoc:
704
- @__types__.index_extensions(mime_type)
725
+ __types__.index_extensions(mime_type)
705
726
  end
706
727
 
707
728
  # The regular expression used to match a file-based MIME type
@@ -760,7 +781,7 @@ module MIME
760
781
  # be provided.
761
782
  def load_from_file(filename) #:nodoc:
762
783
  if defined? ::Encoding
763
- data = File.open(filename, 'r:UTF-8') { |f| f.read }
784
+ data = File.open(filename, 'r:UTF-8:-') { |f| f.read }
764
785
  else
765
786
  data = File.open(filename) { |f| f.read }
766
787
  end
@@ -824,17 +845,17 @@ module MIME
824
845
  # puts t.to_a.join(", ")
825
846
  # end
826
847
  def [](type_id, flags = {})
827
- @__types__[type_id, flags]
848
+ __types__[type_id, flags]
828
849
  end
829
850
 
830
851
  include Enumerable
831
-
852
+
832
853
  def count
833
- @__types__.count
854
+ __types__.count
834
855
  end
835
856
 
836
857
  def each
837
- @__types__.each {|t| yield t }
858
+ __types__.each {|t| yield t }
838
859
  end
839
860
 
840
861
  # Return the list of MIME::Types which belongs to the file based on
@@ -848,12 +869,12 @@ module MIME
848
869
  # puts "MIME::Types.type_for('citydesk.gif')
849
870
  # => [image/gif]
850
871
  def type_for(filename, platform = false)
851
- @__types__.type_for(filename, platform)
872
+ __types__.type_for(filename, platform)
852
873
  end
853
874
 
854
875
  # A synonym for MIME::Types.type_for
855
876
  def of(filename, platform = false)
856
- @__types__.type_for(filename, platform)
877
+ __types__.type_for(filename, platform)
857
878
  end
858
879
 
859
880
  # Add one or more MIME::Type objects to the set of known types. Each
@@ -863,14 +884,82 @@ module MIME
863
884
  # <strong>Please inform the maintainer of this module when registered
864
885
  # types are missing.</strong>
865
886
  def add(*types)
866
- @__types__.add(*types)
887
+ __types__.add(*types)
888
+ end
889
+
890
+ # Returns the currently defined cache file, if any.
891
+ def cache_file
892
+ ENV['RUBY_MIME_TYPES_CACHE']
893
+ end
894
+
895
+ private
896
+ def load_mime_types_from_cache
897
+ load_mime_types_from_cache! if cache_file
898
+ end
899
+
900
+ def load_mime_types_from_cache!
901
+ raise ArgumentError, "No RUBY_MIME_TYPES_CACHE set." unless cache_file
902
+ return false unless File.exists? cache_file
903
+
904
+ begin
905
+ data = File.read(cache_file)
906
+ container = Marshal.load(data)
907
+
908
+ if container.version == VERSION
909
+ @__types__ = Marshal.load(container.data)
910
+ true
911
+ else
912
+ false
913
+ end
914
+ rescue => e
915
+ warn "Could not load MIME::Types cache: #{e}"
916
+ false
917
+ end
918
+ end
919
+
920
+ def write_mime_types_to_cache
921
+ write_mime_types_to_cache! if cache_file
922
+ end
923
+
924
+ def write_mime_types_to_cache!
925
+ raise ArgumentError, "No RUBY_MIME_TYPES_CACHE set." unless cache_file
926
+
927
+ File.open(cache_file, 'w') do |f|
928
+ cache = MIME::Types::CacheContainer.new(VERSION,
929
+ Marshal.dump(__types__))
930
+ f.write Marshal.dump(cache)
931
+ end
932
+
933
+ true
934
+ end
935
+
936
+ def load_and_parse_mime_types
937
+ const_set(:LOAD, true) unless $DEBUG
938
+ Dir[File.join(File.dirname(__FILE__), 'types', '*')].sort.each { |f|
939
+ add(load_from_file(f))
940
+ }
941
+ remove_const :LOAD if defined? LOAD
942
+ end
943
+
944
+ def lazy_load?
945
+ (lazy = ENV['RUBY_MIME_TYPES_LAZY_LOAD']) && (lazy != 'false')
946
+ end
947
+
948
+ def __types__
949
+ load_mime_types unless @__types__
950
+ @__types__
951
+ end
952
+
953
+ def load_mime_types
954
+ @__types__ = new(VERSION)
955
+ unless load_mime_types_from_cache
956
+ load_and_parse_mime_types
957
+ write_mime_types_to_cache
958
+ end
867
959
  end
868
960
  end
869
961
 
870
- files = Dir[File.join(File.dirname(__FILE__), 'types', '*')]
871
- MIME::Types::STARTUP = true unless $DEBUG
872
- files.sort.each { |file| add load_from_file(file) }
873
- remove_const :STARTUP if defined? STARTUP
962
+ load_mime_types unless lazy_load?
874
963
  end
875
964
  end
876
965
 
@@ -5,7 +5,7 @@ video/x-flv @flv :base64
5
5
  video/x-gl @gl :base64
6
6
  video/x-ivf @ivf
7
7
  video/x-matroska @mkv
8
- video/x-motion-jpeg @mjpg
8
+ video/x-motion-jpeg @mjpg,mjpeg
9
9
  video/x-ms-asf @asf,asx
10
10
  video/x-ms-wm @wm
11
11
  video/x-ms-wmv @wmv
@@ -1,11 +1,8 @@
1
1
  # -*- ruby encoding: utf-8 -*-
2
2
 
3
- $LOAD_PATH.unshift("#{File.dirname(__FILE__)}/../lib") if __FILE__ == $0
4
-
5
3
  require 'mime/types'
6
- require 'minitest/autorun'
7
4
 
8
- class TestMIME_Type < MiniTest::Unit::TestCase
5
+ class TestMIMEType < Minitest::Test
9
6
  def yaml_mime_type_from_array
10
7
  MIME::Type.from_array('text/x-yaml', %w(yaml yml), '8bit', 'd9d172f608')
11
8
  end
@@ -1,10 +1,13 @@
1
1
  # -*- ruby encoding: utf-8 -*-
2
2
 
3
- $LOAD_PATH.unshift("#{File.dirname(__FILE__)}/../lib") if __FILE__ == $0
4
-
5
3
  require 'mime/types'
6
4
 
7
- class TestMIME_Types < MiniTest::Unit::TestCase #:nodoc:
5
+ class TestMIMETypes < Minitest::Test
6
+ def setup
7
+ MIME::Types.instance_variable_set(:@__types__, nil)
8
+ MIME::Types.send(:load_mime_types)
9
+ end
10
+
8
11
  def test_class_index_1
9
12
  text_plain = MIME::Type.new('text/plain') do |t|
10
13
  t.encoding = '8bit'
@@ -0,0 +1,77 @@
1
+ # -*- ruby encoding: utf-8 -*-
2
+
3
+ require 'mime/types'
4
+
5
+ class TestMIMETypesCache < Minitest::Test
6
+ def setup
7
+ require 'fileutils'
8
+ @cache_file = File.expand_path('../cache.tst', __FILE__)
9
+ ENV['RUBY_MIME_TYPES_CACHE'] = @cache_file
10
+ clear_cache_file
11
+ end
12
+
13
+ def teardown
14
+ clear_cache_file
15
+ ENV.delete('RUBY_MIME_TYPES_CACHE')
16
+ end
17
+
18
+ def reset_mime_types
19
+ MIME::Types.instance_variable_set(:@__types__, nil)
20
+ MIME::Types.send(:load_mime_types)
21
+ end
22
+
23
+ def clear_cache_file
24
+ FileUtils.rm @cache_file if File.exist? @cache_file
25
+ end
26
+
27
+ def test_uses_correct_cache_file
28
+ assert_equal(@cache_file, MIME::Types.cache_file)
29
+ end
30
+
31
+ def test_does_not_use_cache_when_unset
32
+ ENV.delete('RUBY_MIME_TYPES_CACHE')
33
+ assert_equal(nil, MIME::Types.send(:load_mime_types_from_cache))
34
+ end
35
+
36
+ def test_raises_exception_when_load_forced_without_cache_file
37
+ assert_raises(ArgumentError) {
38
+ ENV.delete('RUBY_MIME_TYPES_CACHE')
39
+ MIME::Types.send(:load_mime_types_from_cache!)
40
+ }
41
+ end
42
+
43
+ def test_does_not_use_cache_when_missing
44
+ assert_equal(false, MIME::Types.send(:load_mime_types_from_cache))
45
+ end
46
+
47
+ def test_does_not_create_cache_when_unset
48
+ ENV.delete('RUBY_MIME_TYPES_CACHE')
49
+ assert_equal(nil, MIME::Types.send(:write_mime_types_to_cache))
50
+ end
51
+
52
+ def test_raises_exception_when_write_forced_without_cache_file
53
+ assert_raises(ArgumentError) {
54
+ ENV.delete('RUBY_MIME_TYPES_CACHE')
55
+ MIME::Types.send(:write_mime_types_to_cache!)
56
+ }
57
+ end
58
+
59
+ def test_creates_cache
60
+ assert_equal(false, File.exist?(@cache_file))
61
+ MIME::Types.send(:write_mime_types_to_cache)
62
+ assert_equal(true, File.exist?(@cache_file))
63
+ end
64
+
65
+ def test_uses_cache
66
+ html = MIME::Types['text/html'].first
67
+ html.extensions << 'hex'
68
+ MIME::Types.send(:write_mime_types_to_cache)
69
+ MIME::Types.instance_variable_set(:@__types__, nil)
70
+
71
+ assert_equal(true, MIME::Types.send(:load_mime_types_from_cache))
72
+ html = MIME::Types['text/html'].first
73
+ assert_includes(html.extensions, 'hex')
74
+
75
+ reset_mime_types
76
+ end
77
+ end
@@ -0,0 +1,40 @@
1
+ # -*- ruby encoding: utf-8 -*-
2
+
3
+ require 'mime/types'
4
+
5
+ class TestMIMETypesLazy < Minitest::Test
6
+ def setup
7
+ ENV['RUBY_MIME_TYPES_LAZY_LOAD'] = 'true'
8
+ ENV['RUBY_MIME_TYPES_CACHE'] = File.expand_path('../cache.tst', __FILE__)
9
+ MIME::Types.send(:write_mime_types_to_cache)
10
+ end
11
+
12
+ def teardown
13
+ reset_mime_types
14
+ if File.exist? ENV['RUBY_MIME_TYPES_CACHE']
15
+ FileUtils.rm ENV['RUBY_MIME_TYPES_CACHE']
16
+ ENV.delete('RUBY_MIME_TYPES_CACHE')
17
+ end
18
+ ENV.delete('RUBY_MIME_TYPES_LAZY_LOAD')
19
+ end
20
+
21
+ def reset_mime_types
22
+ MIME::Types.instance_variable_set(:@__types__, nil)
23
+ MIME::Types.send(:load_mime_types)
24
+ end
25
+
26
+ def test_lazy_load?
27
+ assert_equal(true, MIME::Types.send(:lazy_load?))
28
+ ENV['RUBY_MIME_TYPES_LAZY_LOAD'] = nil
29
+ assert_equal(nil, MIME::Types.send(:lazy_load?))
30
+ ENV['RUBY_MIME_TYPES_LAZY_LOAD'] = 'false'
31
+ assert_equal(false, MIME::Types.send(:lazy_load?))
32
+ end
33
+
34
+ def test_lazy_loading
35
+ MIME::Types.instance_variable_set(:@__types__, nil)
36
+ assert_nil(MIME::Types.instance_variable_get(:@__types__))
37
+ refute_nil(MIME::Types['text/html'].first)
38
+ refute_nil(MIME::Types.instance_variable_get(:@__types__))
39
+ end
40
+ end
metadata CHANGED
@@ -1,61 +1,46 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mime-types
3
3
  version: !ruby/object:Gem::Version
4
- version: '1.24'
5
- prerelease:
4
+ version: '1.25'
6
5
  platform: ruby
7
6
  authors:
8
7
  - Austin Ziegler
9
8
  autorequire:
10
9
  bindir: bin
11
10
  cert_chain:
12
- - ! '-----BEGIN CERTIFICATE-----
13
-
14
- MIIDNjCCAh6gAwIBAgIBADANBgkqhkiG9w0BAQUFADBBMQ8wDQYDVQQDDAZhdXN0
15
-
16
- aW4xGTAXBgoJkiaJk/IsZAEZFglydWJ5Zm9yZ2UxEzARBgoJkiaJk/IsZAEZFgNv
17
-
18
- cmcwHhcNMTMwMjA0MDMzMzI3WhcNMTQwMjA0MDMzMzI3WjBBMQ8wDQYDVQQDDAZh
19
-
20
- dXN0aW4xGTAXBgoJkiaJk/IsZAEZFglydWJ5Zm9yZ2UxEzARBgoJkiaJk/IsZAEZ
21
-
22
- FgNvcmcwggEiMA0GCSqGSIb3DQEBAQUAA4IBDwAwggEKAoIBAQC2mPNf4L37GhKI
23
-
24
- SPCYsvYWXA2/R9u5+pyUnbJ2R1o2CiRq2ZA/AIzY6N3hGnsgoWnh5RzvgTN1Lt08
25
-
26
- DNIrsIG2VDYk/JVt6f9J6zZ8EQHbznWa3cWYoCFaaICdk7jV1n/42hg70jEDYXl9
27
-
28
- gDOl0k6JmyF/rtfFu/OIkFGWeFYIuFHvRuLyUbw66+QDTOzKb3t8o55Ihgy1GVwT
29
-
30
- i6pkDs8LhZWXdOD+921l2Z1NZGZa9KNbJIg6vtgYKU98jQ5qr9iY3ikBAspHrFas
31
-
32
- K6USvGgAg8fCD5YiotBEvCBMYtfqmfrhpdU2p+gvTgeLW1Kaevwqd7ngQmFUrFG1
33
-
34
- eUJSURv5AgMBAAGjOTA3MAkGA1UdEwQCMAAwHQYDVR0OBBYEFAtJKMp6YYNqlgR3
35
-
36
- 9TiZLWqvLagSMAsGA1UdDwQEAwIEsDANBgkqhkiG9w0BAQUFAAOCAQEApTPkvDm8
37
-
38
- 7gJlUT4FfumXPvtuqP67LxUtGE8syvR0A4As+0P/wylLJFUOsGTTdZYtThhxCSJG
39
-
40
- +7KG2FfIcH4Zz2d97arZGAzBoi8iPht2/UtSl1fCcUI5vmJa1MiXZT2oqdW7Wydq
41
-
42
- rAZcBPlrYYuiwtGI0yqIOgBfXSZCWWsJsuyTKELep6mCLgz0YZUfmvKr8W/Ab3ax
43
-
44
- DuLzH92LSRjZJyjyAUpw/Vc2rM4giiP5jtByrb1Y1dGnQhHTMHf1GfucWm7Nw/V9
45
-
46
- twEPVw8+0f88JQucxOTmTF1NbLFpiRwQUZ1zoZbNg2e7mShc/eexnVLWKFKxRoP6
47
-
48
- KPj3WoD+spB8fA==
49
-
50
- -----END CERTIFICATE-----
51
-
52
- '
53
- date: 2013-08-14 00:00:00.000000000 Z
11
+ - !binary |-
12
+ LS0tLS1CRUdJTiBDRVJUSUZJQ0FURS0tLS0tCk1JSUROakNDQWg2Z0F3SUJB
13
+ Z0lCQURBTkJna3Foa2lHOXcwQkFRVUZBREJCTVE4d0RRWURWUVFEREFaaGRY
14
+ TjAKYVc0eEdUQVhCZ29Ka2lhSmsvSXNaQUVaRmdseWRXSjVabTl5WjJVeEV6
15
+ QVJCZ29Ka2lhSmsvSXNaQUVaRmdOdgpjbWN3SGhjTk1UTXdNakEwTURNek16
16
+ STNXaGNOTVRRd01qQTBNRE16TXpJM1dqQkJNUTh3RFFZRFZRUUREQVpoCmRY
17
+ TjBhVzR4R1RBWEJnb0praWFKay9Jc1pBRVpGZ2x5ZFdKNVptOXlaMlV4RXpB
18
+ UkJnb0praWFKay9Jc1pBRVoKRmdOdmNtY3dnZ0VpTUEwR0NTcUdTSWIzRFFF
19
+ QkFRVUFBNElCRHdBd2dnRUtBb0lCQVFDMm1QTmY0TDM3R2hLSQpTUENZc3ZZ
20
+ V1hBMi9SOXU1K3B5VW5iSjJSMW8yQ2lScTJaQS9BSXpZNk4zaEduc2dvV25o
21
+ NVJ6dmdUTjFMdDA4CkROSXJzSUcyVkRZay9KVnQ2ZjlKNnpaOEVRSGJ6bldh
22
+ M2NXWW9DRmFhSUNkazdqVjFuLzQyaGc3MGpFRFlYbDkKZ0RPbDBrNkpteUYv
23
+ cnRmRnUvT0lrRkdXZUZZSXVGSHZSdUx5VWJ3NjYrUURUT3pLYjN0OG81NUlo
24
+ Z3kxR1Z3VAppNnBrRHM4TGhaV1hkT0QrOTIxbDJaMU5aR1phOUtOYkpJZzZ2
25
+ dGdZS1U5OGpRNXFyOWlZM2lrQkFzcEhyRmFzCks2VVN2R2dBZzhmQ0Q1WWlv
26
+ dEJFdkNCTVl0ZnFtZnJocGRVMnArZ3ZUZ2VMVzFLYWV2d3FkN25nUW1GVXJG
27
+ RzEKZVVKU1VSdjVBZ01CQUFHak9UQTNNQWtHQTFVZEV3UUNNQUF3SFFZRFZS
28
+ ME9CQllFRkF0SktNcDZZWU5xbGdSMwo5VGlaTFdxdkxhZ1NNQXNHQTFVZER3
29
+ UUVBd0lFc0RBTkJna3Foa2lHOXcwQkFRVUZBQU9DQVFFQXBUUGt2RG04Cjdn
30
+ SmxVVDRGZnVtWFB2dHVxUDY3THhVdEdFOHN5dlIwQTRBcyswUC93eWxMSkZV
31
+ T3NHVFRkWll0VGhoeENTSkcKKzdLRzJGZkljSDRaejJkOTdhclpHQXpCb2k4
32
+ aVBodDIvVXRTbDFmQ2NVSTV2bUphMU1pWFpUMm9xZFc3V3lkcQpyQVpjQlBs
33
+ cllZdWl3dEdJMHlxSU9nQmZYU1pDV1dzSnN1eVRLRUxlcDZtQ0xnejBZWlVm
34
+ bXZLcjhXL0FiM2F4CkR1THpIOTJMU1JqWkp5anlBVXB3L1ZjMnJNNGdpaVA1
35
+ anRCeXJiMVkxZEduUWhIVE1IZjFHZnVjV203TncvVjkKdHdFUFZ3OCswZjg4
36
+ SlF1Y3hPVG1URjFOYkxGcGlSd1FVWjF6b1piTmcyZTdtU2hjL2VleG5WTFdL
37
+ Rkt4Um9QNgpLUGozV29EK3NwQjhmQT09Ci0tLS0tRU5EIENFUlRJRklDQVRF
38
+ LS0tLS0K
39
+ date: 2013-08-30 00:00:00.000000000 Z
54
40
  dependencies:
55
41
  - !ruby/object:Gem::Dependency
56
42
  name: rubyforge
57
43
  requirement: !ruby/object:Gem::Requirement
58
- none: false
59
44
  requirements:
60
45
  - - ! '>='
61
46
  - !ruby/object:Gem::Version
@@ -63,7 +48,6 @@ dependencies:
63
48
  type: :development
64
49
  prerelease: false
65
50
  version_requirements: !ruby/object:Gem::Requirement
66
- none: false
67
51
  requirements:
68
52
  - - ! '>='
69
53
  - !ruby/object:Gem::Version
@@ -71,7 +55,6 @@ dependencies:
71
55
  - !ruby/object:Gem::Dependency
72
56
  name: minitest
73
57
  requirement: !ruby/object:Gem::Requirement
74
- none: false
75
58
  requirements:
76
59
  - - ~>
77
60
  - !ruby/object:Gem::Version
@@ -79,7 +62,6 @@ dependencies:
79
62
  type: :development
80
63
  prerelease: false
81
64
  version_requirements: !ruby/object:Gem::Requirement
82
- none: false
83
65
  requirements:
84
66
  - - ~>
85
67
  - !ruby/object:Gem::Version
@@ -87,7 +69,6 @@ dependencies:
87
69
  - !ruby/object:Gem::Dependency
88
70
  name: rdoc
89
71
  requirement: !ruby/object:Gem::Requirement
90
- none: false
91
72
  requirements:
92
73
  - - ~>
93
74
  - !ruby/object:Gem::Version
@@ -95,7 +76,6 @@ dependencies:
95
76
  type: :development
96
77
  prerelease: false
97
78
  version_requirements: !ruby/object:Gem::Requirement
98
- none: false
99
79
  requirements:
100
80
  - - ~>
101
81
  - !ruby/object:Gem::Version
@@ -103,7 +83,6 @@ dependencies:
103
83
  - !ruby/object:Gem::Dependency
104
84
  name: hoe-bundler
105
85
  requirement: !ruby/object:Gem::Requirement
106
- none: false
107
86
  requirements:
108
87
  - - ~>
109
88
  - !ruby/object:Gem::Version
@@ -111,7 +90,6 @@ dependencies:
111
90
  type: :development
112
91
  prerelease: false
113
92
  version_requirements: !ruby/object:Gem::Requirement
114
- none: false
115
93
  requirements:
116
94
  - - ~>
117
95
  - !ruby/object:Gem::Version
@@ -119,7 +97,6 @@ dependencies:
119
97
  - !ruby/object:Gem::Dependency
120
98
  name: hoe-doofus
121
99
  requirement: !ruby/object:Gem::Requirement
122
- none: false
123
100
  requirements:
124
101
  - - ~>
125
102
  - !ruby/object:Gem::Version
@@ -127,7 +104,6 @@ dependencies:
127
104
  type: :development
128
105
  prerelease: false
129
106
  version_requirements: !ruby/object:Gem::Requirement
130
- none: false
131
107
  requirements:
132
108
  - - ~>
133
109
  - !ruby/object:Gem::Version
@@ -135,7 +111,6 @@ dependencies:
135
111
  - !ruby/object:Gem::Dependency
136
112
  name: hoe-gemspec2
137
113
  requirement: !ruby/object:Gem::Requirement
138
- none: false
139
114
  requirements:
140
115
  - - ~>
141
116
  - !ruby/object:Gem::Version
@@ -143,7 +118,6 @@ dependencies:
143
118
  type: :development
144
119
  prerelease: false
145
120
  version_requirements: !ruby/object:Gem::Requirement
146
- none: false
147
121
  requirements:
148
122
  - - ~>
149
123
  - !ruby/object:Gem::Version
@@ -151,7 +125,6 @@ dependencies:
151
125
  - !ruby/object:Gem::Dependency
152
126
  name: hoe-git
153
127
  requirement: !ruby/object:Gem::Requirement
154
- none: false
155
128
  requirements:
156
129
  - - ~>
157
130
  - !ruby/object:Gem::Version
@@ -159,7 +132,6 @@ dependencies:
159
132
  type: :development
160
133
  prerelease: false
161
134
  version_requirements: !ruby/object:Gem::Requirement
162
- none: false
163
135
  requirements:
164
136
  - - ~>
165
137
  - !ruby/object:Gem::Version
@@ -167,7 +139,6 @@ dependencies:
167
139
  - !ruby/object:Gem::Dependency
168
140
  name: hoe-rubygems
169
141
  requirement: !ruby/object:Gem::Requirement
170
- none: false
171
142
  requirements:
172
143
  - - ~>
173
144
  - !ruby/object:Gem::Version
@@ -175,7 +146,6 @@ dependencies:
175
146
  type: :development
176
147
  prerelease: false
177
148
  version_requirements: !ruby/object:Gem::Requirement
178
- none: false
179
149
  requirements:
180
150
  - - ~>
181
151
  - !ruby/object:Gem::Version
@@ -183,7 +153,6 @@ dependencies:
183
153
  - !ruby/object:Gem::Dependency
184
154
  name: hoe-travis
185
155
  requirement: !ruby/object:Gem::Requirement
186
- none: false
187
156
  requirements:
188
157
  - - ~>
189
158
  - !ruby/object:Gem::Version
@@ -191,7 +160,6 @@ dependencies:
191
160
  type: :development
192
161
  prerelease: false
193
162
  version_requirements: !ruby/object:Gem::Requirement
194
- none: false
195
163
  requirements:
196
164
  - - ~>
197
165
  - !ruby/object:Gem::Version
@@ -199,7 +167,6 @@ dependencies:
199
167
  - !ruby/object:Gem::Dependency
200
168
  name: rake
201
169
  requirement: !ruby/object:Gem::Requirement
202
- none: false
203
170
  requirements:
204
171
  - - ~>
205
172
  - !ruby/object:Gem::Version
@@ -207,7 +174,6 @@ dependencies:
207
174
  type: :development
208
175
  prerelease: false
209
176
  version_requirements: !ruby/object:Gem::Requirement
210
- none: false
211
177
  requirements:
212
178
  - - ~>
213
179
  - !ruby/object:Gem::Version
@@ -215,7 +181,6 @@ dependencies:
215
181
  - !ruby/object:Gem::Dependency
216
182
  name: hoe
217
183
  requirement: !ruby/object:Gem::Requirement
218
- none: false
219
184
  requirements:
220
185
  - - ~>
221
186
  - !ruby/object:Gem::Version
@@ -223,7 +188,6 @@ dependencies:
223
188
  type: :development
224
189
  prerelease: false
225
190
  version_requirements: !ruby/object:Gem::Requirement
226
- none: false
227
191
  requirements:
228
192
  - - ~>
229
193
  - !ruby/object:Gem::Version
@@ -231,9 +195,57 @@ dependencies:
231
195
  description: ! 'This library allows for the identification of a file''s likely MIME
232
196
  content
233
197
 
234
- type. This is release 1.24, adding and updating a few MIME types and fixing
198
+ type. This is release 1.25, adding experimental caching and lazy loading
199
+
200
+ functionality.
201
+
202
+
203
+ The caching and lazy loading features were initially implemented by Greg
204
+
205
+ Brockman (gdb). As these features are experimental, they are disabled by
206
+
207
+ default and must be enabled through the use of environment variables. The cache
208
+
209
+ is invalidated on a per-version basis; the cache for version 1.25 will not be
210
+
211
+ reused for version 1.26.
212
+
213
+
214
+ To use lazy loading, set the environment variable +RUBY_MIME_TYPES_LAZY_LOAD+
215
+
216
+ to any value other than ''false''. When using lazy loading, the initial startup
217
+
218
+ of MIME::Types is around 12–25× faster than normal startup (on my system,
219
+
220
+ normal startup is about 90 ms; lazy startup is about 4 ms). This isn''t
221
+
222
+ generally useful, however, as the MIME::Types database has not been loaded.
223
+
224
+ Lazy startup and load is just *slightly* faster—around 1 ms. The real advantage
225
+
226
+ comes from using the cache.
227
+
228
+
229
+ To enable the cache, set the environment variable +RUBY_MIME_TYPES_CACHE+ to a
230
+
231
+ filename where MIME::Types will have read-write access. The first time a new
232
+
233
+ version of MIME::Types is run using this file, it will be created, taking a
234
+
235
+ little longer than normal. Subsequent loads using the same cache file will be
236
+
237
+ approximately 3½× faster (25 ms) than normal loads. This can be combined with
238
+
239
+ +RUBY_MIME_TYPES_LAZY_LOAD+, but this is *not* recommended in a multithreaded
240
+
241
+ or multiprocess environment where all threads or processes will be using the
242
+
243
+ same cache file.
244
+
245
+
246
+ As the caching interface is still experimental, the only values cached are the
235
247
 
236
- some issues with documentation.
248
+ default MIME::Types database, not any custom MIME::Types added by users.
237
249
 
238
250
 
239
251
  MIME types are used in MIME-compliant communications, as in e-mail or HTTP
@@ -320,11 +332,14 @@ files:
320
332
  - lib/mime/types/video.obsolete
321
333
  - test/test_mime_type.rb
322
334
  - test/test_mime_types.rb
335
+ - test/test_mime_types_cache.rb
336
+ - test/test_mime_types_lazy.rb
323
337
  homepage: http://mime-types.rubyforge.org/
324
338
  licenses:
325
339
  - MIT
326
340
  - Artistic 2.0
327
341
  - GPL-2
342
+ metadata: {}
328
343
  post_install_message:
329
344
  rdoc_options:
330
345
  - --main
@@ -332,24 +347,24 @@ rdoc_options:
332
347
  require_paths:
333
348
  - lib
334
349
  required_ruby_version: !ruby/object:Gem::Requirement
335
- none: false
336
350
  requirements:
337
351
  - - ! '>='
338
352
  - !ruby/object:Gem::Version
339
353
  version: '0'
340
354
  required_rubygems_version: !ruby/object:Gem::Requirement
341
- none: false
342
355
  requirements:
343
356
  - - ! '>='
344
357
  - !ruby/object:Gem::Version
345
358
  version: '0'
346
359
  requirements: []
347
360
  rubyforge_project: mime-types
348
- rubygems_version: 1.8.25
361
+ rubygems_version: 2.0.7
349
362
  signing_key:
350
- specification_version: 3
363
+ specification_version: 4
351
364
  summary: This library allows for the identification of a file's likely MIME content
352
365
  type
353
366
  test_files:
354
367
  - test/test_mime_type.rb
355
368
  - test/test_mime_types.rb
369
+ - test/test_mime_types_cache.rb
370
+ - test/test_mime_types_lazy.rb
metadata.gz.sig CHANGED
Binary file