mini_mime 1.0.1 → 1.1.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.
- checksums.yaml +4 -4
- data/.github/workflows/ci.yml +40 -0
- data/.github/workflows/db.yml +26 -0
- data/.rubocop.yml +5 -0
- data/CHANGELOG +16 -0
- data/Gemfile +3 -0
- data/README.md +35 -16
- data/Rakefile +9 -8
- data/bench/bench.rb +1 -2
- data/bin/console +1 -0
- data/bin/db_pull_request +20 -0
- data/lib/db/content_type_mime.db +27 -2
- data/lib/db/ext_mime.db +32 -5
- data/lib/mini_mime.rb +19 -8
- data/lib/mini_mime/version.rb +2 -1
- data/mini_mime.gemspec +5 -3
- metadata +50 -20
- data/.travis.yml +0 -30
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 55bbfe99751f28efbb29008a1cbff40f7e16f6f376aa08be5b0928ca19e57fe3
|
4
|
+
data.tar.gz: e99bc29ec1a02a7ce08fe3cc6d997cdce7a073750ba728d97400fe41a9024799
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f6b99913c9255b3d71114bdb8c221d583b5d257669cb4f3f06ea9826143906a184f81b34e62b8c6502a7f65827709e4b0c5634323c2f6636aa05c776fd6df294
|
7
|
+
data.tar.gz: 3a61ba35ba3cba331415df05034724025e917b6fccfc9aa78268a9cffe44887758f8c049bb67c4e4635f88a180ec93bd7ce2339130a034a361a3a54503b432a0
|
@@ -0,0 +1,40 @@
|
|
1
|
+
name: Mini Mime Tests
|
2
|
+
|
3
|
+
on:
|
4
|
+
pull_request:
|
5
|
+
push:
|
6
|
+
branches:
|
7
|
+
- master
|
8
|
+
|
9
|
+
jobs:
|
10
|
+
build:
|
11
|
+
runs-on: ubuntu-latest
|
12
|
+
name: "Ruby ${{ matrix.ruby }} / Failure allowed: ${{ matrix.experimental }}"
|
13
|
+
continue-on-error: ${{ matrix.experimental }}
|
14
|
+
strategy:
|
15
|
+
fail-fast: false
|
16
|
+
matrix:
|
17
|
+
ruby: ["2.4", "2.5", "2.6", "2.7"]
|
18
|
+
experimental: [false]
|
19
|
+
include:
|
20
|
+
- ruby: "ruby-head"
|
21
|
+
experimental: true
|
22
|
+
- ruby: "truffleruby-head"
|
23
|
+
experimental: true
|
24
|
+
- ruby: "jruby-head"
|
25
|
+
experimental: true
|
26
|
+
- ruby: "jruby-9.1.17.0"
|
27
|
+
experimental: true
|
28
|
+
- ruby: "jruby-9.2.13.0"
|
29
|
+
experimental: true
|
30
|
+
steps:
|
31
|
+
- uses: actions/checkout@v2
|
32
|
+
- uses: ruby/setup-ruby@v1
|
33
|
+
with:
|
34
|
+
ruby-version: ${{ matrix.ruby }}
|
35
|
+
bundler-cache: true
|
36
|
+
- name: Rubocop
|
37
|
+
run: bundle exec rubocop
|
38
|
+
if: "!contains(matrix.ruby, 'jruby')"
|
39
|
+
- name: Tests
|
40
|
+
run: bundle exec rake test
|
@@ -0,0 +1,26 @@
|
|
1
|
+
name: Update MIME type DB
|
2
|
+
|
3
|
+
on:
|
4
|
+
schedule:
|
5
|
+
# 10am on the 1st every month https://crontab.guru/#0_10_1_*_*
|
6
|
+
- cron: "0 10 1 * *"
|
7
|
+
workflow_dispatch:
|
8
|
+
|
9
|
+
jobs:
|
10
|
+
update_db:
|
11
|
+
runs-on: ubuntu-latest
|
12
|
+
name: "Update MIME type DB"
|
13
|
+
steps:
|
14
|
+
- uses: actions/checkout@v2
|
15
|
+
- uses: ruby/setup-ruby@v1
|
16
|
+
with:
|
17
|
+
ruby-version: "2.7"
|
18
|
+
bundler-cache: true
|
19
|
+
- name: Update mime-types-data
|
20
|
+
run: bundle update mime-types-data
|
21
|
+
- name: Update DB
|
22
|
+
run: bundle exec rake rebuild_db
|
23
|
+
- name: Create PR
|
24
|
+
run: bin/db_pull_request
|
25
|
+
env:
|
26
|
+
GITHUB_TOKEN: ${{secrets.GITHUB_TOKEN}}
|
data/.rubocop.yml
ADDED
data/CHANGELOG
CHANGED
@@ -1,3 +1,19 @@
|
|
1
|
+
23-08-2021
|
2
|
+
- Version 1.1.1
|
3
|
+
- update mime types from upstream
|
4
|
+
|
5
|
+
05-04-2021
|
6
|
+
- Version 1.1.0
|
7
|
+
- MiniMime.lookup_by_extension is now case insensitive
|
8
|
+
|
9
|
+
26-03-2021
|
10
|
+
- Version 1.0.3
|
11
|
+
- Update mime types from upstream
|
12
|
+
|
13
|
+
08-07-2019
|
14
|
+
- Version 1.0.2
|
15
|
+
- Update mime types from upstream
|
16
|
+
|
1
17
|
14-08-2018
|
2
18
|
- Version 1.0.1
|
3
19
|
- Update mime types from upstream
|
data/Gemfile
CHANGED
data/README.md
CHANGED
@@ -26,6 +26,9 @@ require 'mini_mime'
|
|
26
26
|
MiniMime.lookup_by_filename("a.txt").content_type
|
27
27
|
# => "text/plain"
|
28
28
|
|
29
|
+
MiniMime.lookup_by_extension("txt").content_type
|
30
|
+
# => "text/plain"
|
31
|
+
|
29
32
|
MiniMime.lookup_by_content_type("text/plain").extension
|
30
33
|
# => "txt"
|
31
34
|
|
@@ -34,46 +37,63 @@ MiniMime.lookup_by_content_type("text/plain").binary?
|
|
34
37
|
|
35
38
|
```
|
36
39
|
|
40
|
+
## Configuration
|
41
|
+
|
42
|
+
If you'd like to add your own mime types, try using custom database files:
|
43
|
+
|
44
|
+
```
|
45
|
+
MiniMime::Configuration.ext_db_path = "path_to_file_extension_db"
|
46
|
+
MiniMime::Configuration.content_type_db_path = "path_to_content_type_db"
|
47
|
+
```
|
48
|
+
|
49
|
+
Check out the [default databases](lib/db) for proper formatting and structure hints.
|
50
|
+
|
37
51
|
## Performance
|
38
52
|
|
39
|
-
MiniMime is optimised to minimize memory usage. It keeps a cache of 100 mime type lookups (and 100 misses). There are benchmarks in the [bench directory](https://github.com/discourse/mini_mime/bench/bench.rb)
|
53
|
+
MiniMime is optimised to minimize memory usage. It keeps a cache of 100 mime type lookups (and 100 misses). There are benchmarks in the [bench directory](https://github.com/discourse/mini_mime/blob/master/bench/bench.rb)
|
40
54
|
|
41
55
|
```
|
42
56
|
Memory stats for requiring mime/types/columnar
|
43
|
-
Total allocated:
|
44
|
-
Total retained:
|
57
|
+
Total allocated: 8712144 bytes (98242 objects)
|
58
|
+
Total retained: 3372545 bytes (33599 objects)
|
45
59
|
|
46
60
|
Memory stats for requiring mini_mime
|
47
|
-
Total allocated:
|
48
|
-
Total retained:
|
61
|
+
Total allocated: 42625 bytes (369 objects)
|
62
|
+
Total retained: 8992 bytes (72 objects)
|
49
63
|
Warming up --------------------------------------
|
50
64
|
cached content_type lookup MiniMime
|
51
|
-
|
65
|
+
85.109k i/100ms
|
52
66
|
content_type lookup MIME::Types
|
53
|
-
|
67
|
+
17.879k i/100ms
|
54
68
|
Calculating -------------------------------------
|
55
69
|
cached content_type lookup MiniMime
|
56
|
-
|
70
|
+
1.105M (± 4.1%) i/s - 5.532M in 5.014895s
|
57
71
|
content_type lookup MIME::Types
|
58
|
-
|
72
|
+
193.528k (± 7.1%) i/s - 965.466k in 5.013925s
|
59
73
|
Warming up --------------------------------------
|
60
74
|
uncached content_type lookup MiniMime
|
61
|
-
|
75
|
+
1.410k i/100ms
|
62
76
|
content_type lookup MIME::Types
|
63
|
-
|
77
|
+
18.012k i/100ms
|
64
78
|
Calculating -------------------------------------
|
65
79
|
uncached content_type lookup MiniMime
|
66
|
-
|
80
|
+
14.689k (± 4.2%) i/s - 73.320k in 5.000779s
|
67
81
|
content_type lookup MIME::Types
|
68
|
-
|
82
|
+
193.459k (± 6.9%) i/s - 972.648k in 5.050731s
|
69
83
|
```
|
70
84
|
|
71
|
-
As a general guideline, cached lookups are
|
85
|
+
As a general guideline, cached lookups are 6x faster than MIME::Types equivalent. Uncached lookups are 10x slower.
|
72
86
|
|
87
|
+
Note: It was run on macOS 10.14.2, and versions of Ruby and gems are below.
|
88
|
+
|
89
|
+
- Ruby 2.6.0
|
90
|
+
- mini_mime (1.0.1)
|
91
|
+
- mime-types (3.2.2)
|
92
|
+
- mime-types-data (3.2018.0812)
|
73
93
|
|
74
94
|
## Development
|
75
95
|
|
76
|
-
MiniMime uses the officially maintained list of mime types at [mime-types-data](https://github.com/mime-types/mime-types-data)repo to build the internal database.
|
96
|
+
MiniMime uses the officially maintained list of mime types at [mime-types-data](https://github.com/mime-types/mime-types-data) repo to build the internal database.
|
77
97
|
|
78
98
|
To update the database run:
|
79
99
|
|
@@ -89,7 +109,6 @@ To install this gem onto your local machine, run `bundle exec rake install`. To
|
|
89
109
|
|
90
110
|
Bug reports and pull requests are welcome on GitHub at https://github.com/discourse/mini_mime. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
|
91
111
|
|
92
|
-
|
93
112
|
## License
|
94
113
|
|
95
114
|
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
data/Rakefile
CHANGED
@@ -1,3 +1,4 @@
|
|
1
|
+
# frozen_string_literal: true
|
1
2
|
require "bundler/gem_tasks"
|
2
3
|
require "rake/testtask"
|
3
4
|
|
@@ -7,7 +8,7 @@ Rake::TestTask.new(:test) do |t|
|
|
7
8
|
t.test_files = FileList['test/**/*_test.rb']
|
8
9
|
end
|
9
10
|
|
10
|
-
task :
|
11
|
+
task default: :test
|
11
12
|
|
12
13
|
def pad(array)
|
13
14
|
max = []
|
@@ -36,11 +37,11 @@ task :rebuild_db do
|
|
36
37
|
index = {}
|
37
38
|
|
38
39
|
MIME::Types.each do |type|
|
39
|
-
type.extensions.each {|ext| (index[ext.downcase] ||= []) << type}
|
40
|
+
type.extensions.each { |ext| (index[ext.downcase] ||= []) << type }
|
40
41
|
end
|
41
42
|
|
42
|
-
index.each do |k,list|
|
43
|
-
list.sort!{|a,b| a.priority_compare(b)}
|
43
|
+
index.each do |k, list|
|
44
|
+
list.sort! { |a, b| a.priority_compare(b) }
|
44
45
|
end
|
45
46
|
|
46
47
|
buffer = []
|
@@ -54,9 +55,9 @@ task :rebuild_db do
|
|
54
55
|
|
55
56
|
pad(buffer)
|
56
57
|
|
57
|
-
buffer.sort!{|a,b| a[0] <=> b[0]}
|
58
|
+
buffer.sort! { |a, b| a[0] <=> b[0] }
|
58
59
|
|
59
|
-
File.open("lib/db/ext_mime.db", File::CREAT|File::TRUNC|File::RDWR) do |f|
|
60
|
+
File.open("lib/db/ext_mime.db", File::CREAT | File::TRUNC | File::RDWR) do |f|
|
60
61
|
buffer.each do |row|
|
61
62
|
f.write "#{row[0]} #{row[1]} #{row[2]}\n"
|
62
63
|
end
|
@@ -64,7 +65,7 @@ task :rebuild_db do
|
|
64
65
|
|
65
66
|
puts "#{buffer.count} rows written to lib/db/ext_mime.db"
|
66
67
|
|
67
|
-
buffer.sort!{|a,b| [a[1], a[0]] <=> [b[1], b[0]]}
|
68
|
+
buffer.sort! { |a, b| [a[1], a[0]] <=> [b[1], b[0]] }
|
68
69
|
|
69
70
|
# strip cause we are going to re-pad
|
70
71
|
buffer.each do |row|
|
@@ -80,7 +81,7 @@ task :rebuild_db do
|
|
80
81
|
|
81
82
|
pad(buffer)
|
82
83
|
|
83
|
-
File.open("lib/db/content_type_mime.db", File::CREAT|File::TRUNC|File::RDWR) do |f|
|
84
|
+
File.open("lib/db/content_type_mime.db", File::CREAT | File::TRUNC | File::RDWR) do |f|
|
84
85
|
last = nil
|
85
86
|
count = 0
|
86
87
|
buffer.each do |row|
|
data/bench/bench.rb
CHANGED
@@ -1,9 +1,9 @@
|
|
1
|
+
# frozen_string_literal: true
|
1
2
|
require 'memory_profiler'
|
2
3
|
require 'benchmark/ips'
|
3
4
|
|
4
5
|
$: << File.expand_path('../../lib', __FILE__)
|
5
6
|
|
6
|
-
|
7
7
|
puts
|
8
8
|
puts "Memory stats for requiring mime/types/columnar"
|
9
9
|
result = MemoryProfiler.report do
|
@@ -22,7 +22,6 @@ end
|
|
22
22
|
puts "Total allocated: #{result.total_allocated_memsize} bytes (#{result.total_allocated} objects)"
|
23
23
|
puts "Total retained: #{result.total_retained_memsize} bytes (#{result.total_retained} objects)"
|
24
24
|
|
25
|
-
|
26
25
|
Benchmark.ips do |bm|
|
27
26
|
bm.report 'cached content_type lookup MiniMime' do
|
28
27
|
MiniMime.lookup_by_filename("a.txt").content_type
|
data/bin/console
CHANGED
data/bin/db_pull_request
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
require "time"
|
5
|
+
|
6
|
+
if `git status --porcelain lib/db`.empty?
|
7
|
+
puts "Skipping, no DB changes to commit..."
|
8
|
+
return
|
9
|
+
end
|
10
|
+
|
11
|
+
moment = Time.now.utc
|
12
|
+
branch_name = "db-updates-#{moment.strftime("%Y%m%d%H%M%S")}"
|
13
|
+
|
14
|
+
system("git", "checkout", "-b", branch_name) || abort("Unable to create branch")
|
15
|
+
system("git", "add", "lib/db")
|
16
|
+
system("git", "config", "--local", "user.email", "actions@github.com")
|
17
|
+
system("git", "config", "--local", "user.name", "github-actions")
|
18
|
+
system("git", "commit", "-m", "DB updates #{moment.iso8601}") || abort("Unable to commit changes")
|
19
|
+
system("git", "push", "-u", "origin", branch_name) || abort("Unable to push branch")
|
20
|
+
system("gh", "pr", "create", "--title", "DB updates #{moment.iso8601}", "--body", "From Github Actions") || abort("Unable to create PR")
|
data/lib/db/content_type_mime.db
CHANGED
@@ -35,6 +35,7 @@ jsonml application/jsonml+json
|
|
35
35
|
lostxml application/lost+xml base64
|
36
36
|
hqx application/mac-binhex40 8bit
|
37
37
|
mads application/mads+xml base64
|
38
|
+
webmanifest application/manifest+json base64
|
38
39
|
mrc application/marc base64
|
39
40
|
mrcx application/marcxml+xml base64
|
40
41
|
ma application/mathematica base64
|
@@ -71,7 +72,7 @@ crl application/pkix-crl
|
|
71
72
|
pkipath application/pkix-pkipath base64
|
72
73
|
pki application/pkixcmp base64
|
73
74
|
pls application/pls+xml base64
|
74
|
-
|
75
|
+
eps application/postscript 8bit
|
75
76
|
cw application/prs.cww base64
|
76
77
|
rnd application/prs.nprend base64
|
77
78
|
pskcxml application/pskc+xml base64
|
@@ -487,6 +488,7 @@ cmp application/vnd.yellowriver-custom-menu
|
|
487
488
|
zir application/vnd.zul base64
|
488
489
|
zaz application/vnd.zzazz.deck+xml base64
|
489
490
|
vxml application/voicexml+xml base64
|
491
|
+
wasm application/wasm 8bit
|
490
492
|
wif application/watcherinfo+xml base64
|
491
493
|
wgt application/widget base64
|
492
494
|
wp5 application/wordperfect5.1 base64
|
@@ -560,6 +562,7 @@ cpt application/x-mac-compactpro
|
|
560
562
|
mie application/x-mie base64
|
561
563
|
mobi application/x-mobipocket-ebook base64
|
562
564
|
application application/x-ms-application base64
|
565
|
+
exe application/x-ms-dos-executable base64
|
563
566
|
lnk application/x-ms-shortcut base64
|
564
567
|
wmd application/x-ms-wmd base64
|
565
568
|
wmz application/x-ms-wmz base64
|
@@ -594,6 +597,7 @@ sh application/x-sh
|
|
594
597
|
shar application/x-shar 8bit
|
595
598
|
swf application/x-shockwave-flash base64
|
596
599
|
xap application/x-silverlight-app base64
|
600
|
+
notebook application/x-smarttech-notebook base64
|
597
601
|
sav application/x-spss base64
|
598
602
|
sql application/x-sql base64
|
599
603
|
sit application/x-stuffit base64
|
@@ -663,6 +667,7 @@ ecelp9600 audio/vnd.nuera.ecelp9600
|
|
663
667
|
qcp audio/vnd.qcelp base64
|
664
668
|
rip audio/vnd.rip base64
|
665
669
|
smp3 audio/vnd.sealedmedia.softseal.mpeg base64
|
670
|
+
wav audio/wav base64
|
666
671
|
weba audio/webm base64
|
667
672
|
aac audio/x-aac base64
|
668
673
|
aif audio/x-aiff base64
|
@@ -675,7 +680,6 @@ wma audio/x-ms-wma
|
|
675
680
|
wmv audio/x-ms-wmv base64
|
676
681
|
ra audio/x-pn-realaudio base64
|
677
682
|
rmp audio/x-pn-realaudio-plugin base64
|
678
|
-
wav audio/x-wav base64
|
679
683
|
xm audio/xm base64
|
680
684
|
cdx chemical/x-cdx base64
|
681
685
|
cif chemical/x-cif base64
|
@@ -687,9 +691,14 @@ otf font/otf
|
|
687
691
|
ttf font/ttf base64
|
688
692
|
woff font/woff base64
|
689
693
|
woff2 font/woff2 base64
|
694
|
+
avif image/avif base64
|
690
695
|
cgm image/cgm base64
|
691
696
|
g3 image/g3fax base64
|
692
697
|
gif image/gif base64
|
698
|
+
heic image/heic base64
|
699
|
+
heics image/heic-sequence base64
|
700
|
+
heif image/heif base64
|
701
|
+
heifs image/heif-sequence base64
|
693
702
|
ief image/ief base64
|
694
703
|
jp2 image/jp2 base64
|
695
704
|
jpeg image/jpeg base64
|
@@ -721,21 +730,37 @@ wbmp image/vnd.wap.wbmp
|
|
721
730
|
xif image/vnd.xiff base64
|
722
731
|
webp image/webp base64
|
723
732
|
3ds image/x-3ds base64
|
733
|
+
dng image/x-adobe-dng base64
|
724
734
|
bmp image/x-bmp base64
|
735
|
+
cr2 image/x-canon-cr2 base64
|
736
|
+
crw image/x-canon-crw base64
|
725
737
|
ras image/x-cmu-raster base64
|
726
738
|
cmx image/x-cmx base64
|
727
739
|
xcfbz2 image/x-compressed-xcf base64
|
740
|
+
erf image/x-epson-erf base64
|
728
741
|
fh image/x-freehand base64
|
742
|
+
raf image/x-fuji-raf base64
|
729
743
|
3fr image/x-hasselblad-3fr base64
|
744
|
+
k25 image/x-kodak-k25 base64
|
745
|
+
kdc image/x-kodak-kdc base64
|
746
|
+
mrw image/x-minolta-mrw base64
|
730
747
|
sid image/x-mrsid-image base64
|
748
|
+
nef image/x-nikon-nef base64
|
749
|
+
orf image/x-olympus-orf base64
|
731
750
|
psp image/x-paintshoppro base64
|
751
|
+
raw image/x-panasonic-raw base64
|
732
752
|
pcx image/x-pcx base64
|
753
|
+
pef image/x-pentax-pef base64
|
733
754
|
pct image/x-pict base64
|
734
755
|
pnm image/x-portable-anymap base64
|
735
756
|
pbm image/x-portable-bitmap base64
|
736
757
|
pgm image/x-portable-graymap base64
|
737
758
|
ppm image/x-portable-pixmap base64
|
738
759
|
rgb image/x-rgb base64
|
760
|
+
x3f image/x-sigma-x3f base64
|
761
|
+
arw image/x-sony-arw base64
|
762
|
+
sr2 image/x-sony-sr2 base64
|
763
|
+
srf image/x-sony-srf base64
|
739
764
|
tga image/x-targa base64
|
740
765
|
dgn image/x-vnd.dgn base64
|
741
766
|
xbm image/x-xbitmap 7bit
|
data/lib/db/ext_mime.db
CHANGED
@@ -24,7 +24,7 @@ aep application/vnd.audiograph
|
|
24
24
|
afm application/x-font-type1 base64
|
25
25
|
afp application/vnd.ibm.modcap base64
|
26
26
|
ahead application/vnd.ahead.space base64
|
27
|
-
ai application/
|
27
|
+
ai application/pdf base64
|
28
28
|
aif audio/x-aiff base64
|
29
29
|
aifc audio/x-aiff base64
|
30
30
|
aiff audio/x-aiff base64
|
@@ -38,6 +38,7 @@ appcache text/cache-manifest
|
|
38
38
|
application application/x-ms-application base64
|
39
39
|
apr application/vnd.lotus-approach base64
|
40
40
|
arc application/x-freearc base64
|
41
|
+
arw image/x-sony-arw base64
|
41
42
|
asc application/pgp-signature base64
|
42
43
|
asf application/vnd.ms-asf base64
|
43
44
|
asm text/x-asm quoted-printable
|
@@ -50,6 +51,7 @@ atomsvc application/atomsvc+xml
|
|
50
51
|
atx application/vnd.antix.game-component base64
|
51
52
|
au audio/basic base64
|
52
53
|
avi video/x-msvideo base64
|
54
|
+
avif image/avif base64
|
53
55
|
aw application/applixware base64
|
54
56
|
awb audio/AMR-WB base64
|
55
57
|
azf application/vnd.airzip.filesecure.azf base64
|
@@ -142,9 +144,11 @@ cpi video/MP2T
|
|
142
144
|
cpio application/x-cpio base64
|
143
145
|
cpp text/plain quoted-printable
|
144
146
|
cpt application/x-mac-compactpro base64
|
147
|
+
cr2 image/x-canon-cr2 base64
|
145
148
|
crd application/x-mscardfile base64
|
146
149
|
crl application/pkix-crl base64
|
147
150
|
crt application/x-x509-ca-cert base64
|
151
|
+
crw image/x-canon-crw base64
|
148
152
|
crx application/x-chrome-extension base64
|
149
153
|
cryptonote application/vnd.rig.cryptonote base64
|
150
154
|
csh application/x-csh 8bit
|
@@ -192,6 +196,7 @@ dmg application/x-apple-diskimage
|
|
192
196
|
dmp application/vnd.tcpdump.pcap base64
|
193
197
|
dms application/octet-stream base64
|
194
198
|
dna application/vnd.dna base64
|
199
|
+
dng image/x-adobe-dng base64
|
195
200
|
doc application/msword base64
|
196
201
|
docm application/vnd.ms-word.document.macroEnabled.12 base64
|
197
202
|
docx application/vnd.openxmlformats-officedocument.wordprocessingml.document base64
|
@@ -237,6 +242,8 @@ eol audio/vnd.digital-winds
|
|
237
242
|
eot application/vnd.ms-fontobject base64
|
238
243
|
eps application/postscript 8bit
|
239
244
|
epub application/epub+zip base64
|
245
|
+
erf image/x-epson-erf base64
|
246
|
+
es application/ecmascript base64
|
240
247
|
es3 application/vnd.eszigno3+xml base64
|
241
248
|
esa application/vnd.osgi.subsystem base64
|
242
249
|
esf application/vnd.epson.esf base64
|
@@ -245,7 +252,7 @@ etx text/x-setext
|
|
245
252
|
eva application/x-eva base64
|
246
253
|
evc audio/EVRC base64
|
247
254
|
evy application/x-envoy base64
|
248
|
-
exe application/
|
255
|
+
exe application/x-ms-dos-executable base64
|
249
256
|
exi application/exi base64
|
250
257
|
ext application/vnd.novadigm.EXT base64
|
251
258
|
ez application/andrew-inset base64
|
@@ -339,8 +346,13 @@ hal application/vnd.hal+xml
|
|
339
346
|
hbc application/vnd.hbci base64
|
340
347
|
hbci application/vnd.hbci base64
|
341
348
|
hdf application/x-hdf base64
|
349
|
+
heic image/heic base64
|
350
|
+
heics image/heic-sequence base64
|
351
|
+
heif image/heif base64
|
352
|
+
heifs image/heif-sequence base64
|
342
353
|
hep application/x-hep base64
|
343
354
|
hh text/plain quoted-printable
|
355
|
+
hif image/heic base64
|
344
356
|
hlp text/plain quoted-printable
|
345
357
|
hpgl application/vnd.hp-HPGL base64
|
346
358
|
hpid application/vnd.hp-hpid base64
|
@@ -410,12 +422,14 @@ jpgm image/jpm
|
|
410
422
|
jpgv video/JPEG base64
|
411
423
|
jpm image/jpm base64
|
412
424
|
jpx image/jpx base64
|
413
|
-
js application/
|
425
|
+
js application/javascript 8bit
|
414
426
|
json application/json 8bit
|
415
427
|
jsonml application/jsonml+json base64
|
428
|
+
k25 image/x-kodak-k25 base64
|
416
429
|
kar audio/midi base64
|
417
430
|
karbon application/vnd.kde.karbon base64
|
418
431
|
kcm application/vnd.nervana base64
|
432
|
+
kdc image/x-kodak-kdc base64
|
419
433
|
key application/x-iwork-keynote-sffkey base64
|
420
434
|
kfo application/vnd.kde.kformula base64
|
421
435
|
kia application/vnd.kidspiration base64
|
@@ -507,7 +521,7 @@ mj2 video/MJ2
|
|
507
521
|
mjp2 video/MJ2 base64
|
508
522
|
mjpeg video/x-motion-jpeg base64
|
509
523
|
mjpg video/x-motion-jpeg base64
|
510
|
-
mjs application/
|
524
|
+
mjs application/javascript 8bit
|
511
525
|
mk3d video/x-matroska base64
|
512
526
|
mka audio/x-matroska base64
|
513
527
|
mkd text/markdown quoted-printable
|
@@ -549,6 +563,7 @@ mpy application/vnd.ibm.MiniPay
|
|
549
563
|
mqy application/vnd.Mobius.MQY base64
|
550
564
|
mrc application/marc base64
|
551
565
|
mrcx application/marcxml+xml base64
|
566
|
+
mrw image/x-minolta-mrw base64
|
552
567
|
ms text/troff 8bit
|
553
568
|
mscml application/mediaservercontrol+xml base64
|
554
569
|
mseed application/vnd.fdsn.mseed base64
|
@@ -576,6 +591,7 @@ nb application/mathematica
|
|
576
591
|
nbp application/vnd.wolfram.player base64
|
577
592
|
nc application/netcdf base64
|
578
593
|
ncx application/x-dtbncx+xml base64
|
594
|
+
nef image/x-nikon-nef base64
|
579
595
|
nfo text/x-nfo quoted-printable
|
580
596
|
ngdat application/vnd.nokia.n-gage.data base64
|
581
597
|
nim video/vnd.nokia.interleaved-multimedia base64
|
@@ -585,6 +601,7 @@ nml application/vnd.enliven
|
|
585
601
|
nnd application/vnd.noblenet-directory base64
|
586
602
|
nns application/vnd.noblenet-sealer base64
|
587
603
|
nnw application/vnd.noblenet-web base64
|
604
|
+
notebook application/x-smarttech-notebook base64
|
588
605
|
npx image/vnd.net-fpx base64
|
589
606
|
nsc application/x-conference base64
|
590
607
|
nsf application/vnd.lotus-notes base64
|
@@ -620,6 +637,8 @@ onetoc2 application/onenote
|
|
620
637
|
opf application/oebps-package+xml base64
|
621
638
|
opml text/x-opml quoted-printable
|
622
639
|
oprc application/vnd.palm base64
|
640
|
+
opus audio/ogg base64
|
641
|
+
orf image/x-olympus-orf base64
|
623
642
|
org application/vnd.lotus-organizer base64
|
624
643
|
osf application/vnd.yamaha.openscoreformat base64
|
625
644
|
osfpvg application/vnd.yamaha.openscoreformat.osfpvg+xml base64
|
@@ -657,6 +676,7 @@ pcurl application/vnd.curl.pcurl
|
|
657
676
|
pcx image/x-pcx base64
|
658
677
|
pdb application/vnd.palm base64
|
659
678
|
pdf application/pdf base64
|
679
|
+
pef image/x-pentax-pef base64
|
660
680
|
pfa application/x-font-type1 base64
|
661
681
|
pfb application/x-font-type1 base64
|
662
682
|
pfm application/x-font-type1 base64
|
@@ -735,9 +755,11 @@ qxd application/vnd.Quark.QuarkXPress
|
|
735
755
|
qxl application/vnd.Quark.QuarkXPress 8bit
|
736
756
|
qxt application/vnd.Quark.QuarkXPress 8bit
|
737
757
|
ra audio/x-pn-realaudio base64
|
758
|
+
raf image/x-fuji-raf base64
|
738
759
|
ram audio/x-pn-realaudio base64
|
739
760
|
rar application/x-rar-compressed base64
|
740
761
|
ras image/x-cmu-raster base64
|
762
|
+
raw image/x-panasonic-raw base64
|
741
763
|
rb application/x-ruby 8bit
|
742
764
|
rbw application/x-ruby 8bit
|
743
765
|
rcprofile application/vnd.ipunplugged.rcprofile base64
|
@@ -882,7 +904,9 @@ spq application/scvp-vp-request
|
|
882
904
|
sps application/x-spss base64
|
883
905
|
spx audio/ogg base64
|
884
906
|
sql application/x-sql base64
|
907
|
+
sr2 image/x-sony-sr2 base64
|
885
908
|
src application/x-wais-source base64
|
909
|
+
srf image/x-sony-srf base64
|
886
910
|
srt application/x-subrip base64
|
887
911
|
sru application/sru+xml base64
|
888
912
|
srx application/sparql-results+xml base64
|
@@ -1035,7 +1059,8 @@ vtu model/vnd.vtu
|
|
1035
1059
|
vxml application/voicexml+xml base64
|
1036
1060
|
w3d application/x-director base64
|
1037
1061
|
wad application/x-doom base64
|
1038
|
-
|
1062
|
+
wasm application/wasm 8bit
|
1063
|
+
wav audio/wav base64
|
1039
1064
|
wax audio/x-ms-wax base64
|
1040
1065
|
wbmp image/vnd.wap.wbmp base64
|
1041
1066
|
wbs application/vnd.criticaltools.wbs+xml base64
|
@@ -1046,6 +1071,7 @@ wdp image/vnd.ms-photo
|
|
1046
1071
|
weba audio/webm base64
|
1047
1072
|
webapp application/x-web-app-manifest+json base64
|
1048
1073
|
webm audio/webm base64
|
1074
|
+
webmanifest application/manifest+json base64
|
1049
1075
|
webp image/webp base64
|
1050
1076
|
wg application/vnd.pmi.widget base64
|
1051
1077
|
wgt application/widget base64
|
@@ -1089,6 +1115,7 @@ x3dbz model/x3d+binary
|
|
1089
1115
|
x3dv model/x3d+vrml base64
|
1090
1116
|
x3dvz model/x3d+vrml base64
|
1091
1117
|
x3dz model/x3d+xml base64
|
1118
|
+
x3f image/x-sigma-x3f base64
|
1092
1119
|
x_b model/vnd.parasolid.transmit.binary base64
|
1093
1120
|
x_t model/vnd.parasolid.transmit.text quoted-printable
|
1094
1121
|
xaml application/xaml+xml base64
|
data/lib/mini_mime.rb
CHANGED
@@ -1,3 +1,4 @@
|
|
1
|
+
# frozen_string_literal: true
|
1
2
|
require "mini_mime/version"
|
2
3
|
require "thread"
|
3
4
|
|
@@ -14,6 +15,16 @@ module MiniMime
|
|
14
15
|
Db.lookup_by_content_type(mime)
|
15
16
|
end
|
16
17
|
|
18
|
+
module Configuration
|
19
|
+
class << self
|
20
|
+
attr_accessor :ext_db_path
|
21
|
+
attr_accessor :content_type_db_path
|
22
|
+
end
|
23
|
+
|
24
|
+
self.ext_db_path = File.expand_path("../db/ext_mime.db", __FILE__)
|
25
|
+
self.content_type_db_path = File.expand_path("../db/content_type_mime.db", __FILE__)
|
26
|
+
end
|
27
|
+
|
17
28
|
class Info
|
18
29
|
BINARY_ENCODINGS = %w(base64 8bit)
|
19
30
|
|
@@ -45,14 +56,14 @@ module MiniMime
|
|
45
56
|
extension = File.extname(filename)
|
46
57
|
return if extension.empty?
|
47
58
|
extension = extension[1..-1]
|
48
|
-
extension.downcase!
|
49
59
|
lookup_by_extension(extension)
|
50
60
|
end
|
51
61
|
|
52
62
|
def self.lookup_by_extension(extension)
|
53
63
|
LOCK.synchronize do
|
54
64
|
@db ||= new
|
55
|
-
@db.lookup_by_extension(extension)
|
65
|
+
@db.lookup_by_extension(extension) ||
|
66
|
+
@db.lookup_by_extension(extension.downcase)
|
56
67
|
end
|
57
68
|
end
|
58
69
|
|
@@ -83,8 +94,8 @@ module MiniMime
|
|
83
94
|
class RandomAccessDb
|
84
95
|
MAX_CACHED = 100
|
85
96
|
|
86
|
-
def initialize(
|
87
|
-
@path =
|
97
|
+
def initialize(path, sort_order)
|
98
|
+
@path = path
|
88
99
|
@file = File.open(@path)
|
89
100
|
|
90
101
|
@row_length = @file.readline.length
|
@@ -119,7 +130,7 @@ module MiniMime
|
|
119
130
|
result = nil
|
120
131
|
|
121
132
|
while from <= to do
|
122
|
-
midpoint = from + (to-from).div(2)
|
133
|
+
midpoint = from + (to - from).div(2)
|
123
134
|
current = resolve(midpoint)
|
124
135
|
data = current[@sort_order]
|
125
136
|
if data > val
|
@@ -135,14 +146,14 @@ module MiniMime
|
|
135
146
|
end
|
136
147
|
|
137
148
|
def resolve(row)
|
138
|
-
@file.seek(row
|
149
|
+
@file.seek(row * @row_length)
|
139
150
|
Info.new(@file.readline)
|
140
151
|
end
|
141
152
|
end
|
142
153
|
|
143
154
|
def initialize
|
144
|
-
@ext_db = RandomAccessDb.new(
|
145
|
-
@content_type_db = RandomAccessDb.new(
|
155
|
+
@ext_db = RandomAccessDb.new(Configuration.ext_db_path, 0)
|
156
|
+
@content_type_db = RandomAccessDb.new(Configuration.content_type_db_path, 1)
|
146
157
|
end
|
147
158
|
|
148
159
|
def lookup_by_extension(extension)
|
data/lib/mini_mime/version.rb
CHANGED
data/mini_mime.gemspec
CHANGED
@@ -22,7 +22,9 @@ Gem::Specification.new do |spec|
|
|
22
22
|
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
23
23
|
spec.require_paths = ["lib"]
|
24
24
|
|
25
|
-
spec.add_development_dependency "bundler"
|
26
|
-
spec.add_development_dependency "rake"
|
27
|
-
spec.add_development_dependency "minitest"
|
25
|
+
spec.add_development_dependency "bundler"
|
26
|
+
spec.add_development_dependency "rake"
|
27
|
+
spec.add_development_dependency "minitest"
|
28
|
+
spec.add_development_dependency "rubocop"
|
29
|
+
spec.add_development_dependency "rubocop-discourse"
|
28
30
|
end
|
metadata
CHANGED
@@ -1,57 +1,85 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mini_mime
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Sam Saffron
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2021-08-23 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- - "
|
17
|
+
- - ">="
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: '
|
19
|
+
version: '0'
|
20
20
|
type: :development
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
|
-
- - "
|
24
|
+
- - ">="
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: '
|
26
|
+
version: '0'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: rake
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
|
-
- - "
|
31
|
+
- - ">="
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version: '
|
33
|
+
version: '0'
|
34
34
|
type: :development
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
|
-
- - "
|
38
|
+
- - ">="
|
39
39
|
- !ruby/object:Gem::Version
|
40
|
-
version: '
|
40
|
+
version: '0'
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: minitest
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
44
44
|
requirements:
|
45
|
-
- - "
|
45
|
+
- - ">="
|
46
46
|
- !ruby/object:Gem::Version
|
47
|
-
version: '
|
47
|
+
version: '0'
|
48
48
|
type: :development
|
49
49
|
prerelease: false
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
52
|
-
- - "
|
52
|
+
- - ">="
|
53
53
|
- !ruby/object:Gem::Version
|
54
|
-
version: '
|
54
|
+
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rubocop
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: rubocop-discourse
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
55
83
|
description: A lightweight mime type lookup toy
|
56
84
|
email:
|
57
85
|
- sam.saffron@gmail.com
|
@@ -59,8 +87,10 @@ executables: []
|
|
59
87
|
extensions: []
|
60
88
|
extra_rdoc_files: []
|
61
89
|
files:
|
90
|
+
- ".github/workflows/ci.yml"
|
91
|
+
- ".github/workflows/db.yml"
|
62
92
|
- ".gitignore"
|
63
|
-
- ".
|
93
|
+
- ".rubocop.yml"
|
64
94
|
- CHANGELOG
|
65
95
|
- CODE_OF_CONDUCT.md
|
66
96
|
- Gemfile
|
@@ -69,6 +99,7 @@ files:
|
|
69
99
|
- Rakefile
|
70
100
|
- bench/bench.rb
|
71
101
|
- bin/console
|
102
|
+
- bin/db_pull_request
|
72
103
|
- bin/setup
|
73
104
|
- lib/db/content_type_mime.db
|
74
105
|
- lib/db/ext_mime.db
|
@@ -79,7 +110,7 @@ homepage: https://github.com/discourse/mini_mime
|
|
79
110
|
licenses:
|
80
111
|
- MIT
|
81
112
|
metadata: {}
|
82
|
-
post_install_message:
|
113
|
+
post_install_message:
|
83
114
|
rdoc_options: []
|
84
115
|
require_paths:
|
85
116
|
- lib
|
@@ -94,9 +125,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
94
125
|
- !ruby/object:Gem::Version
|
95
126
|
version: '0'
|
96
127
|
requirements: []
|
97
|
-
|
98
|
-
|
99
|
-
signing_key:
|
128
|
+
rubygems_version: 3.1.6
|
129
|
+
signing_key:
|
100
130
|
specification_version: 4
|
101
131
|
summary: A lightweight mime type lookup toy
|
102
132
|
test_files: []
|
data/.travis.yml
DELETED
@@ -1,30 +0,0 @@
|
|
1
|
-
language: ruby
|
2
|
-
sudo: false
|
3
|
-
cache: bundler
|
4
|
-
|
5
|
-
before_install: gem install bundler -v 1.13.6
|
6
|
-
|
7
|
-
rvm:
|
8
|
-
- 1.8.7
|
9
|
-
- 1.9.2
|
10
|
-
- 1.9.3
|
11
|
-
- 2.0.0
|
12
|
-
- 2.1.10
|
13
|
-
- 2.2.7
|
14
|
-
- 2.3.4
|
15
|
-
- 2.4.1
|
16
|
-
- ruby-head
|
17
|
-
- jruby
|
18
|
-
- jruby-9.0.5.0
|
19
|
-
- jruby-9.1.6.0
|
20
|
-
- jruby-head
|
21
|
-
- rbx-2
|
22
|
-
|
23
|
-
matrix:
|
24
|
-
allow_failures:
|
25
|
-
- rvm: ruby-head
|
26
|
-
- rvm: jruby-9.0.5.0
|
27
|
-
- rvm: jruby-9.1.6.0
|
28
|
-
- rvm: jruby-head
|
29
|
-
- rvm: rbx-2
|
30
|
-
fast_finish: true
|