mimetype-fu 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- data/MIT-LICENSE +20 -0
- data/README +20 -0
- data/Rakefile +56 -0
- data/VERSION +1 -0
- data/init.rb +2 -0
- data/install.rb +1 -0
- data/lib/extensions_const.rb +3 -0
- data/lib/mime_types.yml +780 -0
- data/lib/mimetype_fu.rb +33 -0
- data/mimetype-fu.gemspec +60 -0
- data/spec/fixtures/file.jpg +0 -0
- data/spec/fixtures/file.rb +0 -0
- data/spec/fixtures/file.unknown +0 -0
- data/spec/mime_type_spec.rb +129 -0
- data/spec/spec_helper.rb +42 -0
- data/tasks/mimetype_fu_tasks.rake +4 -0
- data/test/mimetype_fu_test.rb +8 -0
- data/uninstall.rb +1 -0
- metadata +75 -0
data/MIT-LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2007 [name of plugin creator]
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
MimetypeFu
|
2
|
+
==========
|
3
|
+
|
4
|
+
#
|
5
|
+
# NOTICE: I am So Awesome Man! I'm just forking this to put on gemcutter... the designated maintainer can have the namespace overthere whenever (I want to make a few changes for my convenience too)
|
6
|
+
#
|
7
|
+
|
8
|
+
Some great Rails plugins like attachment_fu use the content type/mime type of a file to validate the instance of an object.
|
9
|
+
The plugin usually gets the mime type using the CGI request, however, if the file is already in the system, this approach won't work.
|
10
|
+
Adobe Flash is also known not to send the proper mime type.
|
11
|
+
As an alternative, I wrote mimetype_fu, a simple plugin which will try to guess the mimetype of a file based on its extension.
|
12
|
+
|
13
|
+
Note that mimetype_fu only looks at the extension to define its mime type if you are using Windows!
|
14
|
+
|
15
|
+
http://github.com/mattetti/mimetype-fu
|
16
|
+
|
17
|
+
Thanks to forestcarlisle for his big report and patch.
|
18
|
+
|
19
|
+
|
20
|
+
Copyright (c) 2008 Matt Aimonetti, released under the MIT license
|
data/Rakefile
ADDED
@@ -0,0 +1,56 @@
|
|
1
|
+
require 'rake'
|
2
|
+
require 'rake/testtask'
|
3
|
+
require 'rake/rdoctask'
|
4
|
+
require 'spec/rake/spectask'
|
5
|
+
|
6
|
+
begin
|
7
|
+
require 'jeweler'
|
8
|
+
Jeweler::Tasks.new do |gem|
|
9
|
+
gem.name = "mimetype-fu"
|
10
|
+
gem.summary = "get the mimetype of a file directly in Ruby"
|
11
|
+
gem.description = "get the mimetype of a file directly in Ruby"
|
12
|
+
gem.email = "josh@vitamin-j.com"
|
13
|
+
gem.homepage = "http://github.com/jfrench/mimetype-fu"
|
14
|
+
gem.authors = ["Josh French"]
|
15
|
+
end
|
16
|
+
|
17
|
+
rescue LoadError
|
18
|
+
puts "Jeweler (or a dependency) not available. Install it with: sudo gem install jeweler"
|
19
|
+
end
|
20
|
+
|
21
|
+
desc 'Default: run unit tests.'
|
22
|
+
task :default => :spec
|
23
|
+
|
24
|
+
desc 'Test the mimetype_fu plugin.'
|
25
|
+
Rake::TestTask.new(:test) do |t|
|
26
|
+
t.libs << 'lib'
|
27
|
+
t.pattern = 'test/**/*_test.rb'
|
28
|
+
t.verbose = true
|
29
|
+
end
|
30
|
+
|
31
|
+
desc 'Generate documentation for the mimetype_fu plugin.'
|
32
|
+
Rake::RDocTask.new(:rdoc) do |rdoc|
|
33
|
+
rdoc.rdoc_dir = 'rdoc'
|
34
|
+
rdoc.title = 'MimetypeFu'
|
35
|
+
rdoc.options << '--line-numbers' << '--inline-source'
|
36
|
+
rdoc.rdoc_files.include('README')
|
37
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
38
|
+
end
|
39
|
+
|
40
|
+
desc 'Run the RSpec tests.'
|
41
|
+
Spec::Rake::SpecTask.new(:spec) do |t|
|
42
|
+
t.spec_files = FileList['spec/**/*_spec.rb']
|
43
|
+
end
|
44
|
+
|
45
|
+
begin
|
46
|
+
require 'rcov/rcovtask'
|
47
|
+
Rcov::RcovTask.new do |test|
|
48
|
+
test.libs << 'test'
|
49
|
+
test.pattern = 'test/**/*_test.rb'
|
50
|
+
test.verbose = true
|
51
|
+
end
|
52
|
+
rescue LoadError
|
53
|
+
task :rcov do
|
54
|
+
abort "RCov is not available. In order to run rcov, you must: sudo gem install spicycode-rcov"
|
55
|
+
end
|
56
|
+
end
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
0.1.1
|
data/init.rb
ADDED
data/install.rb
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
# Install hook code here
|
data/lib/mime_types.yml
ADDED
@@ -0,0 +1,780 @@
|
|
1
|
+
# EXTENSIONS => CONTENT TYPE
|
2
|
+
\"123\": application/vnd.lotus-1-2-3
|
3
|
+
\"602\": application/x-t602
|
4
|
+
\"669\": audio/x-mod
|
5
|
+
3ds: image/x-3ds
|
6
|
+
3g2: video/3gpp2
|
7
|
+
3gp: video/3gpp
|
8
|
+
3gpp: video/3gpp
|
9
|
+
7z: application/x-7z-compressed
|
10
|
+
a: application/x-archive
|
11
|
+
aac: audio/mp4
|
12
|
+
abw: application/x-abiword
|
13
|
+
ac3: audio/ac3
|
14
|
+
ace: application/x-ace
|
15
|
+
acutc: application/vnd.acucorp
|
16
|
+
adb: text/x-adasrc
|
17
|
+
ads: text/x-adasrc
|
18
|
+
afm: application/x-font-afm
|
19
|
+
ag: image/x-applix-graphics
|
20
|
+
ai: application/illustrator
|
21
|
+
aif: audio/x-aiff
|
22
|
+
aifc: audio/x-aiff
|
23
|
+
aiff: audio/x-aiff
|
24
|
+
al: application/x-perl
|
25
|
+
ami: application/vnd.amiga.ami
|
26
|
+
amr: audio/AMR
|
27
|
+
ani: application/octet-stream
|
28
|
+
ape: audio/x-ape
|
29
|
+
arj: application/x-arj
|
30
|
+
arw: image/x-sony-arw
|
31
|
+
as: application/x-applix-spreadsheet
|
32
|
+
asc: application/pgp-encrypted
|
33
|
+
asf: video/x-ms-asf
|
34
|
+
asp: application/x-asp
|
35
|
+
ass: text/x-ssa
|
36
|
+
asx: audio/x-ms-asx
|
37
|
+
atc: application/vnd.acucorp
|
38
|
+
atom: application/atom+xml
|
39
|
+
au: audio/basic
|
40
|
+
avi: video/x-msvideo
|
41
|
+
aw: application/x-applix-word
|
42
|
+
awb: audio/AMR-WB
|
43
|
+
bak: application/x-trash
|
44
|
+
bcpio: application/x-bcpio
|
45
|
+
bdf: application/x-font-bdf
|
46
|
+
bib: text/x-bibtex
|
47
|
+
bin: application/x-mac
|
48
|
+
bkm: application/vnd.nervana
|
49
|
+
blend: application/x-blender
|
50
|
+
blender: application/x-blender
|
51
|
+
bmp: image/bmp
|
52
|
+
bpd: application/vnd.hbci
|
53
|
+
builder: application/x-ruby
|
54
|
+
bz: application/x-bzip
|
55
|
+
bz2: application/x-bzip
|
56
|
+
c: text/x-csrc
|
57
|
+
c++: text/x-c++src
|
58
|
+
cab: application/vnd.ms-cab-compressed
|
59
|
+
cbr: application/x-cbr
|
60
|
+
cbz: application/x-cbz
|
61
|
+
cc: text/x-c++src
|
62
|
+
ccc: text/vnd.net2phone.commcenter.command
|
63
|
+
cdf: application/x-netcdf
|
64
|
+
cdr: application/vnd.corel-draw
|
65
|
+
cdy: application/vnd.cinderella
|
66
|
+
cer: application/x-x509-ca-cert
|
67
|
+
cert: application/x-x509-ca-cert
|
68
|
+
cgi: application/x-cgi
|
69
|
+
cgm: image/cgm
|
70
|
+
chm: application/x-chm
|
71
|
+
chrt: application/x-kchart
|
72
|
+
chrt: application/vnd.kde.kchart
|
73
|
+
cil: application/vnd.ms-artgalry
|
74
|
+
class: application/x-java
|
75
|
+
cls: text/x-tex
|
76
|
+
cmc: application/vnd.cosmocaller
|
77
|
+
cpio: application/x-cpio
|
78
|
+
cpp: text/x-c++src
|
79
|
+
cr2: image/x-canon-cr2
|
80
|
+
crl: application/pkix-crl
|
81
|
+
crt: application/x-x509-ca-cert
|
82
|
+
crw: image/x-canon-crw
|
83
|
+
cs: text/x-csharp
|
84
|
+
csh: application/x-csh
|
85
|
+
css: text/css
|
86
|
+
cssl: text/css
|
87
|
+
csv: text/csv
|
88
|
+
cue: application/x-cue
|
89
|
+
cur: image/x-win-bitmap
|
90
|
+
curl: application/vnd.curl
|
91
|
+
cw: application/prs.cww
|
92
|
+
cww: application/prs.cww
|
93
|
+
cxx: text/x-c++src
|
94
|
+
d: text/x-dsrc
|
95
|
+
dar: application/x-dar
|
96
|
+
dat: text/plain
|
97
|
+
dbf: application/x-dbf
|
98
|
+
dc: application/x-dc-rom
|
99
|
+
dcl: text/x-dcl
|
100
|
+
dcm: application/dicom
|
101
|
+
dcr: image/x-kodak-dcr
|
102
|
+
dds: image/x-dds
|
103
|
+
deb: application/x-deb
|
104
|
+
der: application/x-x509-ca-cert
|
105
|
+
desktop: application/x-desktop
|
106
|
+
dfac: application/vnd.dreamfactory
|
107
|
+
dgn: image/x-vnd.dgn
|
108
|
+
dia: application/x-dia-diagram
|
109
|
+
diff: text/x-patch
|
110
|
+
divx: video/x-msvideo
|
111
|
+
djv: image/vnd.djvu
|
112
|
+
djvu: image/vnd.djvu
|
113
|
+
dl: video/dl
|
114
|
+
dms: application/octet-stream
|
115
|
+
dng: image/x-adobe-dng
|
116
|
+
doc: application/msword
|
117
|
+
docx: application/msword
|
118
|
+
docbook: application/docbook+xml
|
119
|
+
dot: application/msword
|
120
|
+
dsl: text/x-dsl
|
121
|
+
dtd: text/x-dtd
|
122
|
+
dtx: text/x-tex
|
123
|
+
dv: video/dv
|
124
|
+
dvi: application/x-dvi
|
125
|
+
dwf: x-drawing/dwf
|
126
|
+
dwg: image/vnd.dwg
|
127
|
+
dxf: image/vnd.dxf
|
128
|
+
ecelp4800: audio/vnd.nuera.ecelp4800
|
129
|
+
ecelp7470: audio/vnd.nuera.ecelp7470
|
130
|
+
ecelp9600: audio/vnd.nuera.ecelp9600
|
131
|
+
efif: application/vnd.picsel
|
132
|
+
egon: application/x-egon
|
133
|
+
el: text/x-emacs-lisp
|
134
|
+
emf: image/x-emf
|
135
|
+
emm: application/vnd.ibm.electronic-media
|
136
|
+
emp: application/vnd.emusic-emusic_package
|
137
|
+
ent: application/vnd.nervana
|
138
|
+
entity: application/vnd.nervana
|
139
|
+
eol: audio/vnd.digital-winds
|
140
|
+
eps: image/x-eps
|
141
|
+
epsf: image/x-eps
|
142
|
+
epsi: image/x-eps
|
143
|
+
erb: text/rhtml
|
144
|
+
erl: text/x-erlang
|
145
|
+
es: application/ecmascript
|
146
|
+
etheme: application/x-e-theme
|
147
|
+
etx: text/x-setext
|
148
|
+
evc: audio/EVRC
|
149
|
+
exe: application/x-executable
|
150
|
+
ez: application/andrew-inset
|
151
|
+
fig: image/x-xfig
|
152
|
+
fits: image/x-fits
|
153
|
+
flac: audio/x-flac
|
154
|
+
flc: video/x-flic
|
155
|
+
fli: video/x-flic
|
156
|
+
flo: application/vnd.micrografx.flo
|
157
|
+
flv: application/x-flash-video
|
158
|
+
flw: application/x-kivio
|
159
|
+
fo: text/x-xslfo
|
160
|
+
for: text/x-fortran
|
161
|
+
fsc: application/vnd.fsc.weblaunch
|
162
|
+
g3: image/fax-g3
|
163
|
+
gb: application/x-gameboy-rom
|
164
|
+
gba: application/x-gba-rom
|
165
|
+
gcrd: text/directory
|
166
|
+
ged: application/x-gedcom
|
167
|
+
gedcom: application/x-gedcom
|
168
|
+
gen: application/x-genesis-rom
|
169
|
+
gf: application/x-tex-gf
|
170
|
+
gg: application/x-sms-rom
|
171
|
+
gif: image/gif
|
172
|
+
gif: image/gif
|
173
|
+
gl: video/gl
|
174
|
+
glade: application/x-glade
|
175
|
+
gmo: application/x-gettext-translation
|
176
|
+
gnc: application/x-gnucash
|
177
|
+
gnucash: application/x-gnucash
|
178
|
+
gnumeric: application/x-gnumeric
|
179
|
+
gnuplot: application/x-gnuplot
|
180
|
+
gp: application/x-gnuplot
|
181
|
+
gpg: application/pgp-encrypted
|
182
|
+
gplt: application/x-gnuplot
|
183
|
+
gra: application/x-graphite
|
184
|
+
gsf: application/x-font-type1
|
185
|
+
gtar: application/x-tar
|
186
|
+
gvp: text/x-google-video-pointer
|
187
|
+
gz: application/x-gzip
|
188
|
+
h: text/x-chdr
|
189
|
+
h++: text/x-c++hdr
|
190
|
+
hbc: application/vnd.hbci
|
191
|
+
hbci: application/vnd.hbci
|
192
|
+
hdf: application/x-hdf
|
193
|
+
hh: text/x-c++hdr
|
194
|
+
hh: text/plain
|
195
|
+
hlp: text/plain
|
196
|
+
hp: text/x-c++hdr
|
197
|
+
hpgl: application/vnd.hp-hpgl
|
198
|
+
hpp: text/x-c++hdr
|
199
|
+
hqx: application/mac-binhex40
|
200
|
+
hs: text/x-haskell
|
201
|
+
htc: text/x-component
|
202
|
+
htke: application/vnd.kenameaapp
|
203
|
+
htm: text/html
|
204
|
+
html: text/html
|
205
|
+
htmlx: text/html
|
206
|
+
htx: text/html
|
207
|
+
hvd: application/vnd.yamaha.hv-dic
|
208
|
+
hvp: application/vnd.yamaha.hv-voice
|
209
|
+
hvs: application/vnd.yamaha.hv-script
|
210
|
+
hwp: application/x-hwp
|
211
|
+
hwt: application/x-hwt
|
212
|
+
hxx: text/x-c++hdr
|
213
|
+
ica: application/x-ica
|
214
|
+
icb: image/x-tga
|
215
|
+
ice: x-conference/x-cooltalk
|
216
|
+
icns: image/x-icns
|
217
|
+
ico: image/x-ico
|
218
|
+
ics: text/calendar
|
219
|
+
idl: text/x-idl
|
220
|
+
ief: image/ief
|
221
|
+
iff: image/x-iff
|
222
|
+
iges: model/iges
|
223
|
+
igs: model/iges
|
224
|
+
igx: application/vnd.micrografx.igx
|
225
|
+
ilbm: image/x-ilbm
|
226
|
+
ins: text/x-tex
|
227
|
+
irm: application/vnd.ibm.rights-management
|
228
|
+
irp: application/vnd.irepository.package+xml
|
229
|
+
iso: application/x-cd-image
|
230
|
+
iso9660: application/x-cd-image
|
231
|
+
it: audio/x-it
|
232
|
+
j2k: image/jp2
|
233
|
+
jad: text/vnd.sun.j2me.app-descriptor
|
234
|
+
jar: application/x-java-archive
|
235
|
+
java: text/x-java
|
236
|
+
jisp: application/vnd.jisp
|
237
|
+
jng: image/x-jng
|
238
|
+
jnlp: application/x-java-jnlp-file
|
239
|
+
jp2: image/jp2
|
240
|
+
jpc: image/jp2
|
241
|
+
jpe: image/jpeg
|
242
|
+
jpeg: image/jpeg
|
243
|
+
jpf: image/jp2
|
244
|
+
jpg: image/jpeg
|
245
|
+
jpm: image/jpm
|
246
|
+
jpr: application/x-jbuilder-project
|
247
|
+
jpx: image/jpx
|
248
|
+
js: application/javascript
|
249
|
+
k25: image/x-kodak-k25
|
250
|
+
kar: audio/midi
|
251
|
+
karbon: application/x-karbon
|
252
|
+
kcm: application/vnd.nervana
|
253
|
+
kdc: image/x-kodak-kdc
|
254
|
+
kdelnk: application/x-desktop
|
255
|
+
kfo: application/x-kformula
|
256
|
+
kia: application/vnd.kidspiration
|
257
|
+
kil: application/x-killustrator
|
258
|
+
kino: application/smil
|
259
|
+
kne: application/vnd.Kinar
|
260
|
+
knp: application/vnd.Kinar
|
261
|
+
kom: application/vnd.hbci
|
262
|
+
kon: application/x-kontour
|
263
|
+
kon: application/vnd.kde.kontour
|
264
|
+
kpm: application/x-kpovmodeler
|
265
|
+
kpr: application/x-kpresenter
|
266
|
+
kpt: application/x-kpresenter
|
267
|
+
kra: application/x-krita
|
268
|
+
ksp: application/x-kspread
|
269
|
+
kud: application/x-kugar
|
270
|
+
kwd: application/x-kword
|
271
|
+
kwt: application/x-kword
|
272
|
+
l16: audio/L16
|
273
|
+
la: application/x-shared-library-la
|
274
|
+
latex: text/x-tex
|
275
|
+
lbd: application/vnd.llamagraphics.life-balance.desktop
|
276
|
+
lbe: application/vnd.llamagraphics.life-balance.exchange+xml
|
277
|
+
ldif: text/x-ldif
|
278
|
+
les: application/vnd.hhe.lesson-player
|
279
|
+
lha: application/x-lha
|
280
|
+
lhs: text/x-literate-haskell
|
281
|
+
lhz: application/x-lhz
|
282
|
+
log: text/x-log
|
283
|
+
lrm: application/vnd.ms-lrm
|
284
|
+
ltx: text/x-tex
|
285
|
+
lua: text/x-lua
|
286
|
+
lvp: audio/vnd.lucent.voice
|
287
|
+
lwo: image/x-lwo
|
288
|
+
lwob: image/x-lwo
|
289
|
+
lws: image/x-lws
|
290
|
+
lyx: application/x-lyx
|
291
|
+
lzh: application/x-lha
|
292
|
+
lzo: application/x-lzop
|
293
|
+
m: text/x-objcsrc
|
294
|
+
m15: audio/x-mod
|
295
|
+
m2t: video/mpeg
|
296
|
+
m3u: audio/x-mpegurl
|
297
|
+
m4: application/x-m4
|
298
|
+
m4a: audio/mp4
|
299
|
+
m4b: audio/x-m4b
|
300
|
+
m4u: video/vnd.mpegurl
|
301
|
+
m4v: video/mp4
|
302
|
+
mab: application/x-markaby
|
303
|
+
man: application/x-troff-man
|
304
|
+
mcd: application/vnd.mcd
|
305
|
+
md: application/x-genesis-rom
|
306
|
+
mdb: application/vnd.ms-access
|
307
|
+
mdi: image/vnd.ms-modi
|
308
|
+
me: text/x-troff-me
|
309
|
+
me: application/x-troff-me
|
310
|
+
mesh: model/mesh
|
311
|
+
mfm: application/vnd.mfmp
|
312
|
+
mgp: application/x-magicpoint
|
313
|
+
mid: audio/midi
|
314
|
+
midi: audio/midi
|
315
|
+
mif: application/x-mif
|
316
|
+
minipsf: audio/x-minipsf
|
317
|
+
mj2: video/MJ2
|
318
|
+
mjp2: video/MJ2
|
319
|
+
mka: audio/x-matroska
|
320
|
+
mkv: video/x-matroska
|
321
|
+
ml: text/x-ocaml
|
322
|
+
mli: text/x-ocaml
|
323
|
+
mm: text/x-troff-mm
|
324
|
+
mmf: application/vnd.smaf
|
325
|
+
mml: text/mathml
|
326
|
+
mng: video/x-mng
|
327
|
+
mo: application/x-gettext-translation
|
328
|
+
moc: text/x-moc
|
329
|
+
mod: audio/x-mod
|
330
|
+
moov: video/quicktime
|
331
|
+
mov: video/quicktime
|
332
|
+
movie: video/x-sgi-movie
|
333
|
+
\"mp+\": audio/x-musepack
|
334
|
+
mp2: audio/mp2
|
335
|
+
mp2: video/mpeg
|
336
|
+
mp3: audio/mpeg
|
337
|
+
mp3g: video/mpeg
|
338
|
+
mp4: video/mp4
|
339
|
+
mpc: audio/x-musepack
|
340
|
+
mpe: video/mpeg
|
341
|
+
mpeg: video/mpeg
|
342
|
+
mpg: video/mpeg
|
343
|
+
mpga: audio/mpeg
|
344
|
+
mpm: application/vnd.blueice.multipass
|
345
|
+
mpn: application/vnd.mophun.application
|
346
|
+
mpp: application/vnd.ms-project
|
347
|
+
mrw: image/x-minolta-mrw
|
348
|
+
ms: text/x-troff-ms
|
349
|
+
mseq: application/vnd.mseq
|
350
|
+
msh: model/mesh
|
351
|
+
msod: image/x-msod
|
352
|
+
msx: application/x-msx-rom
|
353
|
+
mtm: audio/x-mod
|
354
|
+
mup: text/x-mup
|
355
|
+
mxmf: audio/vnd.nokia.mobile-xmf
|
356
|
+
mxu: video/vnd.mpegurl
|
357
|
+
n64: application/x-n64-rom
|
358
|
+
nb: application/mathematica
|
359
|
+
nc: application/x-netcdf
|
360
|
+
nds: application/x-nintendo-ds-rom
|
361
|
+
nef: image/x-nikon-nef
|
362
|
+
nes: application/x-nes-rom
|
363
|
+
nfo: text/x-readme
|
364
|
+
nim: video/vnd.nokia.interleaved-multimedia
|
365
|
+
not: text/x-mup
|
366
|
+
nsc: application/x-netshow-channel
|
367
|
+
nsv: video/x-nsv
|
368
|
+
o: application/x-object
|
369
|
+
obj: application/x-tgif
|
370
|
+
ocl: text/x-ocl
|
371
|
+
oda: application/oda
|
372
|
+
odb: application/vnd.oasis.opendocument.database
|
373
|
+
odc: application/vnd.oasis.opendocument.chart
|
374
|
+
odf: application/vnd.oasis.opendocument.formula
|
375
|
+
odg: application/vnd.oasis.opendocument.graphics
|
376
|
+
odi: application/vnd.oasis.opendocument.image
|
377
|
+
odm: application/vnd.oasis.opendocument.text-master
|
378
|
+
odp: application/vnd.oasis.opendocument.presentation
|
379
|
+
ods: application/vnd.oasis.opendocument.spreadsheet
|
380
|
+
odt: application/vnd.oasis.opendocument.text
|
381
|
+
oga: audio/ogg
|
382
|
+
ogg: application/ogg
|
383
|
+
ogm: video/x-ogm+ogg
|
384
|
+
ogv: video/ogg
|
385
|
+
ogx: application/ogg
|
386
|
+
old: application/x-trash
|
387
|
+
oleo: application/x-oleo
|
388
|
+
opml: text/x-opml+xml
|
389
|
+
oprc: application/vnd.palm
|
390
|
+
orf: image/x-olympus-orf
|
391
|
+
otg: application/vnd.oasis.opendocument.graphics-template
|
392
|
+
oth: application/vnd.oasis.opendocument.text-web
|
393
|
+
otp: application/vnd.oasis.opendocument.presentation-template
|
394
|
+
ots: application/vnd.oasis.opendocument.spreadsheet-template
|
395
|
+
ott: application/vnd.oasis.opendocument.text-template
|
396
|
+
owl: text/rdf
|
397
|
+
p: text/x-pascal
|
398
|
+
p10: application/pkcs10
|
399
|
+
p12: application/x-pkcs12
|
400
|
+
p7c: application/pkcs7-mime
|
401
|
+
p7m: application/pkcs7-mime
|
402
|
+
p7s: application/pkcs7-signature
|
403
|
+
pak: application/x-pak
|
404
|
+
par2: application/x-par2
|
405
|
+
pas: text/x-pascal
|
406
|
+
patch: text/x-patch
|
407
|
+
pbm: image/x-portable-bitmap
|
408
|
+
pcd: image/x-photo-cd
|
409
|
+
pcf: application/x-font-pcf
|
410
|
+
pcl: application/vnd.hp-pcl
|
411
|
+
pdb: application/x-palm-database
|
412
|
+
pdf: application/pdf
|
413
|
+
pef: image/x-pentax-pef
|
414
|
+
pem: application/x-x509-ca-cert
|
415
|
+
perl: application/x-perl
|
416
|
+
pfa: application/x-font-type1
|
417
|
+
pfb: application/x-font-type1
|
418
|
+
pfr: application/font-tdpfr
|
419
|
+
pfx: application/x-pkcs12
|
420
|
+
pgb: image/vnd.globalgraphics.pgb
|
421
|
+
pgm: image/x-portable-graymap
|
422
|
+
pgn: application/x-chess-pgn
|
423
|
+
pgp: application/pgp-encrypted
|
424
|
+
php: application/x-php
|
425
|
+
php3: application/x-php
|
426
|
+
php4: application/x-php
|
427
|
+
pict: image/x-pict
|
428
|
+
pict1: image/x-pict
|
429
|
+
pict2: image/x-pict
|
430
|
+
pk: application/x-tex-pk
|
431
|
+
pkd: application/vnd.hbci
|
432
|
+
pki: application/pkixcmp
|
433
|
+
pkipath: application/pkix-pkipath
|
434
|
+
pkr: application/pgp-keys
|
435
|
+
pl: application/x-perl
|
436
|
+
pla: audio/x-iriver-pla
|
437
|
+
plb: application/vnd.3gpp.pic-bw-large
|
438
|
+
plj: audio/vnd.everad.plj
|
439
|
+
pln: application/x-planperfect
|
440
|
+
pls: audio/x-scpls
|
441
|
+
plt: application/vnd.hp-HPGL
|
442
|
+
pm: application/x-perl
|
443
|
+
png: image/png
|
444
|
+
pnm: image/x-portable-anymap
|
445
|
+
pntg: image/x-macpaint
|
446
|
+
po: text/x-gettext-translation
|
447
|
+
pot: application/vnd.ms-powerpoint
|
448
|
+
ppm: image/x-portable-pixmap
|
449
|
+
pps: application/vnd.ms-powerpoint
|
450
|
+
ppt: application/vnd.ms-powerpoint
|
451
|
+
pptx: application/vnd.ms-powerpoint
|
452
|
+
ppz: application/vnd.ms-powerpoint
|
453
|
+
pqa: application/vnd.palm
|
454
|
+
prc: application/x-palm-database
|
455
|
+
ps: application/postscript
|
456
|
+
psb: application/vnd.3gpp.pic-bw-small
|
457
|
+
psd: image/x-psd
|
458
|
+
psf: application/x-font-linux-psf
|
459
|
+
psf: audio/x-psf
|
460
|
+
psflib: audio/x-psflib
|
461
|
+
psid: audio/prs.sid
|
462
|
+
psp: image/x-paintshoppro
|
463
|
+
pspimage: image/x-paintshoppro
|
464
|
+
pti: application/vnd.pvi.ptid1
|
465
|
+
ptid: application/vnd.pvi.ptid1
|
466
|
+
pvb: application/vnd.3gpp.pic-bw-var
|
467
|
+
pw: application/x-pw
|
468
|
+
py: text/x-python
|
469
|
+
pyc: application/x-python-bytecode
|
470
|
+
pyo: application/x-python-bytecode
|
471
|
+
qcp: audio/QCELP
|
472
|
+
qif: image/x-quicktime
|
473
|
+
qt: video/quicktime
|
474
|
+
qtif: image/x-quicktime
|
475
|
+
qtl: application/x-quicktime-media-link
|
476
|
+
qtvr: video/quicktime
|
477
|
+
qwd: application/vnd.Quark.QuarkXPress
|
478
|
+
qwt: application/vnd.Quark.QuarkXPress
|
479
|
+
qxb: application/vnd.Quark.QuarkXPress
|
480
|
+
qxd: application/vnd.Quark.QuarkXPress
|
481
|
+
qxl: application/vnd.Quark.QuarkXPress
|
482
|
+
qxt: application/vnd.Quark.QuarkXPress
|
483
|
+
ra: audio/vnd.rn-realaudio
|
484
|
+
raf: image/x-fuji-raf
|
485
|
+
ram: audio/x-pn-realaudio
|
486
|
+
rar: application/x-rar
|
487
|
+
ras: image/x-cmu-raster
|
488
|
+
raw: image/x-panasonic-raw
|
489
|
+
rax: audio/vnd.rn-realaudio
|
490
|
+
rb: application/x-ruby
|
491
|
+
rcprofile: application/vnd.ipunplugged.rcprofile
|
492
|
+
rct: application/prs.nprend
|
493
|
+
rdf: text/rdf
|
494
|
+
rdfs: text/rdf
|
495
|
+
rdz: application/vnd.data-vision.rdz
|
496
|
+
rej: application/x-reject
|
497
|
+
req: application/vnd.nervana
|
498
|
+
request: application/vnd.nervana
|
499
|
+
rgb: image/x-rgb
|
500
|
+
rhtml: text/rhtml
|
501
|
+
rle: image/rle
|
502
|
+
rm: application/vnd.rn-realmedia
|
503
|
+
rmj: application/vnd.rn-realmedia
|
504
|
+
rmm: application/vnd.rn-realmedia
|
505
|
+
rms: application/vnd.rn-realmedia
|
506
|
+
rmvb: application/vnd.rn-realmedia
|
507
|
+
rmx: application/vnd.rn-realmedia
|
508
|
+
rnd: application/prs.nprend
|
509
|
+
roff: text/troff
|
510
|
+
rp: image/vnd.rn-realpix
|
511
|
+
rpm: application/x-rpm
|
512
|
+
rpss: application/vnd.nokia.radio-presets
|
513
|
+
rpst: application/vnd.nokia.radio-preset
|
514
|
+
rss: application/rss+xml
|
515
|
+
rst: text/prs.fallenstein.rst
|
516
|
+
rt: text/vnd.rn-realtext
|
517
|
+
rtf: application/rtf
|
518
|
+
rtx: text/richtext
|
519
|
+
rxml: application/x-ruby
|
520
|
+
rv: video/vnd.rn-realvideo
|
521
|
+
rvx: video/vnd.rn-realvideo
|
522
|
+
s11: video/vnd.sealed.mpeg1
|
523
|
+
s14: video/vnd.sealed.mpeg4
|
524
|
+
s1a: application/vnd.sealedmedia.softseal.pdf
|
525
|
+
s1e: application/vnd.sealed.xls
|
526
|
+
s1g: image/vnd.sealedmedia.softseal.gif
|
527
|
+
s1h: application/vnd.sealedmedia.softseal.html
|
528
|
+
s1j: image/vnd.sealedmedia.softseal.jpg
|
529
|
+
s1m: audio/vnd.sealedmedia.softseal.mpeg
|
530
|
+
s1n: image/vnd.sealed.png
|
531
|
+
s1p: application/vnd.sealed.ppt
|
532
|
+
s1q: video/vnd.sealedmedia.softseal.mov
|
533
|
+
s1w: application/vnd.sealed.doc
|
534
|
+
s3m: audio/x-s3m
|
535
|
+
saf: application/vnd.yamaha.smaf-audio
|
536
|
+
sam: application/x-amipro
|
537
|
+
sami: application/x-sami
|
538
|
+
sc: application/vnd.ibm.secure-container
|
539
|
+
scm: text/x-scheme
|
540
|
+
sda: application/vnd.stardivision.draw
|
541
|
+
sdc: application/vnd.stardivision.calc
|
542
|
+
sdd: application/vnd.stardivision.impress
|
543
|
+
sdf: application/vnd.Kinar
|
544
|
+
sdo: application/vnd.sealed.doc
|
545
|
+
sdoc: application/vnd.sealed.doc
|
546
|
+
sdp: application/vnd.stardivision.impress
|
547
|
+
sds: application/vnd.stardivision.chart
|
548
|
+
sdw: application/vnd.stardivision.writer
|
549
|
+
see: application/vnd.seemail
|
550
|
+
sem: application/vnd.sealed.eml
|
551
|
+
seml: application/vnd.sealed.eml
|
552
|
+
ser: application/x-java-serialized-object
|
553
|
+
sgf: application/x-go-sgf
|
554
|
+
sgi: image/vnd.sealedmedia.softseal.gif
|
555
|
+
sgif: image/vnd.sealedmedia.softseal.gif
|
556
|
+
sgl: application/vnd.stardivision.writer
|
557
|
+
sgm: text/sgml
|
558
|
+
sgml: text/sgml
|
559
|
+
sh: application/x-shellscript
|
560
|
+
shar: application/x-shar
|
561
|
+
shn: application/x-shorten
|
562
|
+
shtml: text/html
|
563
|
+
si: text/vnd.wap.si
|
564
|
+
siag: application/x-siag
|
565
|
+
sic: application/vnd.wap.sic
|
566
|
+
sid: audio/prs.sid
|
567
|
+
sig: application/pgp-signature
|
568
|
+
sik: application/x-trash
|
569
|
+
silo: model/mesh
|
570
|
+
sis: application/vnd.symbian.install
|
571
|
+
sisx: x-epoc/x-sisx-app
|
572
|
+
sit: application/stuffit
|
573
|
+
siv: application/sieve
|
574
|
+
sjp: image/vnd.sealedmedia.softseal.jpg
|
575
|
+
sjpg: image/vnd.sealedmedia.softseal.jpg
|
576
|
+
skr: application/pgp-keys
|
577
|
+
sl: text/vnd.wap.sl
|
578
|
+
slc: application/vnd.wap.slc
|
579
|
+
slk: text/spreadsheet
|
580
|
+
smc: application/x-snes-rom
|
581
|
+
smd: application/vnd.stardivision.mail
|
582
|
+
smf: application/vnd.stardivision.math
|
583
|
+
smh: application/vnd.sealed.mht
|
584
|
+
smht: application/vnd.sealed.mht
|
585
|
+
smi: application/smil
|
586
|
+
smil: application/smil
|
587
|
+
sml: application/smil
|
588
|
+
smo: video/vnd.sealedmedia.softseal.mov
|
589
|
+
smov: video/vnd.sealedmedia.softseal.mov
|
590
|
+
smp: audio/vnd.sealedmedia.softseal.mpeg
|
591
|
+
smp3: audio/vnd.sealedmedia.softseal.mpeg
|
592
|
+
smpg: video/vnd.sealed.mpeg4
|
593
|
+
sms: application/vnd.3gpp.sms
|
594
|
+
smv: audio/SMV
|
595
|
+
snd: audio/basic
|
596
|
+
so: application/x-sharedlib
|
597
|
+
soc: application/sgml-open-catalog
|
598
|
+
spd: application/vnd.sealedmedia.softseal.pdf
|
599
|
+
spdf: application/vnd.sealedmedia.softseal.pdf
|
600
|
+
spec: text/x-rpm-spec
|
601
|
+
spf: application/vnd.yamaha.smaf-phrase
|
602
|
+
spl: application/x-shockwave-flash
|
603
|
+
spn: image/vnd.sealed.png
|
604
|
+
spng: image/vnd.sealed.png
|
605
|
+
spp: application/vnd.sealed.ppt
|
606
|
+
sppt: application/vnd.sealed.ppt
|
607
|
+
spx: audio/x-speex
|
608
|
+
sql: text/x-sql
|
609
|
+
sr2: image/x-sony-sr2
|
610
|
+
src: application/x-wais-source
|
611
|
+
srf: image/x-sony-srf
|
612
|
+
srt: application/x-subrip
|
613
|
+
ssa: text/x-ssa
|
614
|
+
ssw: video/vnd.sealed.swf
|
615
|
+
sswf: video/vnd.sealed.swf
|
616
|
+
stc: application/vnd.sun.xml.calc.template
|
617
|
+
std: application/vnd.sun.xml.draw.template
|
618
|
+
sti: application/vnd.sun.xml.impress.template
|
619
|
+
stk: application/hyperstudio
|
620
|
+
stm: application/vnd.sealedmedia.softseal.html
|
621
|
+
stml: application/vnd.sealedmedia.softseal.html
|
622
|
+
stw: application/vnd.sun.xml.writer.template
|
623
|
+
sty: text/x-tex
|
624
|
+
sub: text/x-mpsub
|
625
|
+
sun: image/x-sun-raster
|
626
|
+
sus: application/vnd.sus-calendar
|
627
|
+
susp: application/vnd.sus-calendar
|
628
|
+
sv4cpio: application/x-sv4cpio
|
629
|
+
sv4crc: application/x-sv4crc
|
630
|
+
svg: image/svg+xml
|
631
|
+
svgz: image/svg+xml-compressed
|
632
|
+
swf: application/x-shockwave-flash
|
633
|
+
sxc: application/vnd.sun.xml.calc
|
634
|
+
sxd: application/vnd.sun.xml.draw
|
635
|
+
sxg: application/vnd.sun.xml.writer.global
|
636
|
+
sxl: application/vnd.sealed.xls
|
637
|
+
sxls: application/vnd.sealed.xls
|
638
|
+
sxm: application/vnd.sun.xml.math
|
639
|
+
sxw: application/vnd.sun.xml.writer
|
640
|
+
sylk: text/spreadsheet
|
641
|
+
t: text/troff
|
642
|
+
t2t: text/x-txt2tags
|
643
|
+
tar: application/x-tar
|
644
|
+
tbz: application/x-bzip-compressed-tar
|
645
|
+
tbz2: application/x-bzip-compressed-tar
|
646
|
+
tcl: text/x-tcl
|
647
|
+
tex: text/x-tex
|
648
|
+
texi: text/x-texinfo
|
649
|
+
texinfo: text/x-texinfo
|
650
|
+
tga: image/x-tga
|
651
|
+
tgz: application/x-compressed-tar
|
652
|
+
theme: application/x-theme
|
653
|
+
tif: image/tiff
|
654
|
+
tiff: image/tiff
|
655
|
+
tk: text/x-tcl
|
656
|
+
tnef: application/vnd.ms-tnef
|
657
|
+
tnf: application/vnd.ms-tnef
|
658
|
+
torrent: application/x-bittorrent
|
659
|
+
tpic: image/x-tga
|
660
|
+
tr: text/troff
|
661
|
+
troff: text/troff
|
662
|
+
ts: application/x-linguist
|
663
|
+
tsv: text/tab-separated-values
|
664
|
+
tta: audio/x-tta
|
665
|
+
ttc: application/x-font-ttf
|
666
|
+
ttf: application/x-font-ttf
|
667
|
+
txd: application/vnd.genomatix.tuxedo
|
668
|
+
txt: text/plain
|
669
|
+
tzo: application/x-tzo
|
670
|
+
ufraw: application/x-ufraw
|
671
|
+
ui: application/x-designer
|
672
|
+
uil: text/x-uil
|
673
|
+
ult: audio/x-mod
|
674
|
+
uni: audio/x-mod
|
675
|
+
upa: application/vnd.hbci
|
676
|
+
url: text/x-uri
|
677
|
+
ustar: application/x-ustar
|
678
|
+
vala: text/x-vala
|
679
|
+
vbk: audio/vnd.nortel.vbk
|
680
|
+
vcf: text/x-vcard
|
681
|
+
vcs: text/x-vcalendar
|
682
|
+
vct: text/directory
|
683
|
+
vda: image/x-tga
|
684
|
+
vhd: text/x-vhdl
|
685
|
+
vhdl: text/x-vhdl
|
686
|
+
vis: application/vnd.visionary
|
687
|
+
viv: video/vivo
|
688
|
+
vivo: video/vivo
|
689
|
+
vlc: audio/x-mpegurl
|
690
|
+
vob: video/mpeg
|
691
|
+
voc: audio/x-voc
|
692
|
+
vor: application/vnd.stardivision.writer
|
693
|
+
vrml: x-world/x-vrml
|
694
|
+
vsc: application/vnd.vidsoft.vidconference
|
695
|
+
vsd: application/vnd.visio
|
696
|
+
vss: application/vnd.visio
|
697
|
+
vst: application/vnd.visio
|
698
|
+
vsw: application/vnd.visio
|
699
|
+
wav: audio/x-wav
|
700
|
+
wax: audio/x-ms-asx
|
701
|
+
wb1: application/x-quattropro
|
702
|
+
wb2: application/x-quattropro
|
703
|
+
wb3: application/x-quattropro
|
704
|
+
wbmp: image/vnd.wap.wbmp
|
705
|
+
wbs: application/vnd.criticaltools.wbs+xml
|
706
|
+
wbxml: application/vnd.wap.wbxml
|
707
|
+
wif: application/watcherinfo+xml
|
708
|
+
wk1: application/vnd.lotus-1-2-3
|
709
|
+
wk3: application/vnd.lotus-1-2-3
|
710
|
+
wk4: application/vnd.lotus-1-2-3
|
711
|
+
wks: application/vnd.lotus-1-2-3
|
712
|
+
wm: video/x-ms-wm
|
713
|
+
wma: audio/x-ms-wma
|
714
|
+
wmd: application/x-ms-wmd
|
715
|
+
wmf: image/x-wmf
|
716
|
+
wml: text/vnd.wap.wml
|
717
|
+
wmlc: application/vnd.wap.wmlc
|
718
|
+
wmls: text/vnd.wap.wmlscript
|
719
|
+
wmlsc: application/vnd.wap.wmlscriptc
|
720
|
+
wmv: video/x-ms-wmv
|
721
|
+
wmx: audio/x-ms-asx
|
722
|
+
wmz: application/x-ms-wmz
|
723
|
+
wp: application/vnd.wordperfect
|
724
|
+
wp4: application/vnd.wordperfect
|
725
|
+
wp5: application/vnd.wordperfect
|
726
|
+
wp6: application/vnd.wordperfect
|
727
|
+
wpd: application/vnd.wordperfect
|
728
|
+
wpg: application/x-wpg
|
729
|
+
wpl: application/vnd.ms-wpl
|
730
|
+
wpp: application/vnd.wordperfect
|
731
|
+
wqd: application/vnd.wqd
|
732
|
+
wri: application/x-mswrite
|
733
|
+
wrl: x-world/x-vrml
|
734
|
+
wtb: application/vnd.webturbo
|
735
|
+
wv: audio/x-wavpack
|
736
|
+
wvc: audio/x-wavpack-correction
|
737
|
+
wvp: audio/x-wavpack
|
738
|
+
wvx: audio/x-ms-asx
|
739
|
+
x_b: model/vnd.parasolid.transmit.binary
|
740
|
+
x_t: model/vnd.parasolid.transmit.text
|
741
|
+
x3f: image/x-sigma-x3f
|
742
|
+
xac: application/x-gnucash
|
743
|
+
xbel: application/x-xbel
|
744
|
+
xbl: application/xml
|
745
|
+
xbm: image/x-xbitmap
|
746
|
+
xcf: image/x-xcf
|
747
|
+
xfdf: application/vnd.adobe.xfdf
|
748
|
+
xhtml: application/xhtml+xml
|
749
|
+
xi: audio/x-xi
|
750
|
+
xla: application/vnd.ms-excel
|
751
|
+
xlc: application/vnd.ms-excel
|
752
|
+
xld: application/vnd.ms-excel
|
753
|
+
xlf: application/x-xliff
|
754
|
+
xliff: application/x-xliff
|
755
|
+
xll: application/vnd.ms-excel
|
756
|
+
xlm: application/vnd.ms-excel
|
757
|
+
xls: application/vnd.ms-excel
|
758
|
+
xlsx: application/vnd.ms-excel
|
759
|
+
xlt: application/vnd.ms-excel
|
760
|
+
xlw: application/vnd.ms-excel
|
761
|
+
xm: audio/x-xm
|
762
|
+
xmi: text/x-xmi
|
763
|
+
xml: text/xml
|
764
|
+
xmt_bin: model/vnd.parasolid.transmit.binary
|
765
|
+
xmt_txt: model/vnd.parasolid.transmit.text
|
766
|
+
xpm: image/x-xpixmap
|
767
|
+
xps: application/vnd.ms-xpsdocument
|
768
|
+
xsl: application/xml
|
769
|
+
xslfo: text/x-xslfo
|
770
|
+
xslt: application/xml
|
771
|
+
xspf: application/xspf+xml
|
772
|
+
xul: application/vnd.mozilla.xul+xml
|
773
|
+
xwd: image/x-xwindowdump
|
774
|
+
xyz: x-chemical/x-xyz
|
775
|
+
yaml: text/x-yaml
|
776
|
+
yml: text/x-yaml
|
777
|
+
z: application/x-compressed
|
778
|
+
zabw: application/x-abiword
|
779
|
+
zip: application/zip
|
780
|
+
zoo: application/x-zoo
|
data/lib/mimetype_fu.rb
ADDED
@@ -0,0 +1,33 @@
|
|
1
|
+
require 'tempfile'
|
2
|
+
require 'extensions_const'
|
3
|
+
|
4
|
+
class File
|
5
|
+
|
6
|
+
def self.mime_type?(file)
|
7
|
+
case file
|
8
|
+
when File, Tempfile
|
9
|
+
unless RUBY_PLATFORM.include? 'mswin32'
|
10
|
+
mime = `file --mime -br "#{file.path}"`.strip
|
11
|
+
else
|
12
|
+
mime = EXTENSIONS[File.extname(file.path).gsub('.','').downcase.to_sym]
|
13
|
+
end
|
14
|
+
when String
|
15
|
+
mime = EXTENSIONS[(file[file.rindex('.')+1, file.size]).downcase.to_sym] unless file.rindex('.').nil?
|
16
|
+
when StringIO
|
17
|
+
temp = File.open(Dir.tmpdir + '/upload_file.' + Process.pid.to_s, "wb")
|
18
|
+
temp << file.string
|
19
|
+
temp.close
|
20
|
+
mime = `file --mime -br "#{temp.path}"`
|
21
|
+
mime = mime.gsub(/^.*: */,"")
|
22
|
+
mime = mime.gsub(/;.*$/,"")
|
23
|
+
mime = mime.gsub(/,.*$/,"")
|
24
|
+
File.delete(temp.path)
|
25
|
+
end
|
26
|
+
return mime || 'unknown/unknown'
|
27
|
+
end
|
28
|
+
|
29
|
+
def self.extensions
|
30
|
+
EXTENSIONS
|
31
|
+
end
|
32
|
+
|
33
|
+
end
|
data/mimetype-fu.gemspec
ADDED
@@ -0,0 +1,60 @@
|
|
1
|
+
# Generated by jeweler
|
2
|
+
# DO NOT EDIT THIS FILE DIRECTLY
|
3
|
+
# Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
|
4
|
+
# -*- encoding: utf-8 -*-
|
5
|
+
|
6
|
+
Gem::Specification.new do |s|
|
7
|
+
s.name = %q{mimetype-fu}
|
8
|
+
s.version = "0.1.1"
|
9
|
+
|
10
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
|
+
s.authors = ["Josh French"]
|
12
|
+
s.date = %q{2010-01-08}
|
13
|
+
s.description = %q{get the mimetype of a file directly in Ruby}
|
14
|
+
s.email = %q{josh@vitamin-j.com}
|
15
|
+
s.extra_rdoc_files = [
|
16
|
+
"README"
|
17
|
+
]
|
18
|
+
s.files = [
|
19
|
+
"MIT-LICENSE",
|
20
|
+
"README",
|
21
|
+
"Rakefile",
|
22
|
+
"VERSION",
|
23
|
+
"init.rb",
|
24
|
+
"install.rb",
|
25
|
+
"lib/extensions_const.rb",
|
26
|
+
"lib/mime_types.yml",
|
27
|
+
"lib/mimetype_fu.rb",
|
28
|
+
"mimetype-fu.gemspec",
|
29
|
+
"spec/fixtures/file.jpg",
|
30
|
+
"spec/fixtures/file.rb",
|
31
|
+
"spec/fixtures/file.unknown",
|
32
|
+
"spec/mime_type_spec.rb",
|
33
|
+
"spec/spec_helper.rb",
|
34
|
+
"tasks/mimetype_fu_tasks.rake",
|
35
|
+
"test/mimetype_fu_test.rb",
|
36
|
+
"uninstall.rb"
|
37
|
+
]
|
38
|
+
s.homepage = %q{http://github.com/jfrench/mimetype-fu}
|
39
|
+
s.rdoc_options = ["--charset=UTF-8"]
|
40
|
+
s.require_paths = ["lib"]
|
41
|
+
s.rubygems_version = %q{1.3.5}
|
42
|
+
s.summary = %q{get the mimetype of a file directly in Ruby}
|
43
|
+
s.test_files = [
|
44
|
+
"spec/fixtures/file.rb",
|
45
|
+
"spec/mime_type_spec.rb",
|
46
|
+
"spec/spec_helper.rb",
|
47
|
+
"test/mimetype_fu_test.rb"
|
48
|
+
]
|
49
|
+
|
50
|
+
if s.respond_to? :specification_version then
|
51
|
+
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
52
|
+
s.specification_version = 3
|
53
|
+
|
54
|
+
if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
|
55
|
+
else
|
56
|
+
end
|
57
|
+
else
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
File without changes
|
File without changes
|
File without changes
|
@@ -0,0 +1,129 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/spec_helper'
|
2
|
+
require File.dirname(__FILE__) + '/../lib/mimetype_fu'
|
3
|
+
|
4
|
+
# Ideally, the two solutions (`file` command versus simply looking at the extension)
|
5
|
+
# would return identical results, but thats not the case. `file` differentiates
|
6
|
+
# between file sizes, and has a tendency to classify files into the 'application/octet-stream'
|
7
|
+
# mimetype, whereas, looking at the ext results in 'unknown/unknown' more often.
|
8
|
+
|
9
|
+
describe "An open file" do
|
10
|
+
|
11
|
+
describe "with a zero filelength" do
|
12
|
+
|
13
|
+
before {create_file('file.empty')}
|
14
|
+
|
15
|
+
it 'should have a length of zero' do
|
16
|
+
File.size(@file).should == 0
|
17
|
+
end
|
18
|
+
|
19
|
+
it_should_have_a_mime_type_of("application/x-empty")
|
20
|
+
|
21
|
+
end
|
22
|
+
|
23
|
+
describe 'with a known extension' do
|
24
|
+
|
25
|
+
before {write_file('file.png', "\211PNG\r\n\032\n", 'wb')}
|
26
|
+
|
27
|
+
it 'should have a file size of greater than zero' do
|
28
|
+
File.size(@file).should > 0
|
29
|
+
end
|
30
|
+
|
31
|
+
it_should_have_an_extension_of('png')
|
32
|
+
it_should_have_a_mime_type_of("image/png")
|
33
|
+
|
34
|
+
end
|
35
|
+
|
36
|
+
describe 'with spaces in name' do
|
37
|
+
|
38
|
+
before {write_file('file with spaces.png', "\211PNG\r\n\032\n", 'wb')}
|
39
|
+
|
40
|
+
it 'should have an extension' do
|
41
|
+
File.extname(@file.path).should == '.png'
|
42
|
+
end
|
43
|
+
|
44
|
+
it 'should have a mime type' do
|
45
|
+
File.mime_type?(@file).should == "image/png"
|
46
|
+
end
|
47
|
+
|
48
|
+
end
|
49
|
+
|
50
|
+
describe 'with an unknown extension' do
|
51
|
+
|
52
|
+
before {write_file('file.unknown', "\211Random\r\n\032\n", 'wb')}
|
53
|
+
|
54
|
+
it 'should have a file size of greater than zero' do
|
55
|
+
File.size(@file).should > 0
|
56
|
+
end
|
57
|
+
|
58
|
+
it_should_have_an_extension_of('unknown')
|
59
|
+
it_should_have_a_mime_type_of("application/octet-stream")
|
60
|
+
|
61
|
+
end
|
62
|
+
|
63
|
+
describe 'with no extension' do
|
64
|
+
|
65
|
+
before{write_file('file', "Random\r\n\032\n", 'wb')}
|
66
|
+
|
67
|
+
it 'should have a file size of greater than zero' do
|
68
|
+
File.size(@file).should > 0
|
69
|
+
end
|
70
|
+
|
71
|
+
it_should_have_a_mime_type_of("application/octet-stream")
|
72
|
+
|
73
|
+
end
|
74
|
+
|
75
|
+
end
|
76
|
+
|
77
|
+
describe "A filepath (closed file)" do
|
78
|
+
|
79
|
+
after(:each) do
|
80
|
+
delete_file
|
81
|
+
end
|
82
|
+
|
83
|
+
describe "with a zero filelength" do
|
84
|
+
|
85
|
+
before {create_file('file.empty'); close}
|
86
|
+
|
87
|
+
it_should_have_a_mime_type_of("unknown/unknown")
|
88
|
+
|
89
|
+
end
|
90
|
+
|
91
|
+
describe 'with a known extension' do
|
92
|
+
|
93
|
+
before {write_file('file.png', "\211PNG\r\n\032\n", 'wb'); close}
|
94
|
+
|
95
|
+
it 'should have a file size of greater than zero' do
|
96
|
+
File.size(@file).should > 0
|
97
|
+
end
|
98
|
+
|
99
|
+
it_should_have_an_extension_of('png')
|
100
|
+
it_should_have_a_mime_type_of("image/png")
|
101
|
+
|
102
|
+
end
|
103
|
+
|
104
|
+
describe 'with an unknown extension' do
|
105
|
+
|
106
|
+
before {write_file('file.unknown', "\211Random\r\n\032\n", 'wb'); close}
|
107
|
+
|
108
|
+
it 'should have a file size of greater than zero' do
|
109
|
+
File.size(@file).should > 0
|
110
|
+
end
|
111
|
+
|
112
|
+
it_should_have_an_extension_of('unknown')
|
113
|
+
it_should_have_a_mime_type_of("unknown/unknown")
|
114
|
+
|
115
|
+
end
|
116
|
+
|
117
|
+
describe 'with no extension' do
|
118
|
+
|
119
|
+
before{write_file('file', "Random\r\n\032\n", 'wb'); close}
|
120
|
+
|
121
|
+
it 'should have a file size of greater than zero' do
|
122
|
+
File.size(@file).should > 0
|
123
|
+
end
|
124
|
+
|
125
|
+
it_should_have_a_mime_type_of("unknown/unknown")
|
126
|
+
|
127
|
+
end
|
128
|
+
|
129
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,42 @@
|
|
1
|
+
ENV["RAILS_ENV"] = "test"
|
2
|
+
require File.expand_path(File.dirname(__FILE__) + "/../../../../config/environment")
|
3
|
+
require 'test_help'
|
4
|
+
|
5
|
+
def create_file(filename, mode='w')
|
6
|
+
@file = File.new(File.dirname(__FILE__) + "/fixtures/#{filename}", mode)
|
7
|
+
end
|
8
|
+
|
9
|
+
def close
|
10
|
+
@file.close
|
11
|
+
@file = @file.path
|
12
|
+
end
|
13
|
+
|
14
|
+
def open_file(filename, mode='r')
|
15
|
+
@file = File.open(File.dirname(__FILE__) + "/fixtures/#{filename}", mode)
|
16
|
+
end
|
17
|
+
|
18
|
+
def write_file(filename, data, mode='wb')
|
19
|
+
file = create_file(filename, mode)
|
20
|
+
file.write(data)
|
21
|
+
file.flush
|
22
|
+
end
|
23
|
+
|
24
|
+
def file_or_path(file)
|
25
|
+
file.is_a?(File) ? file.path : file
|
26
|
+
end
|
27
|
+
|
28
|
+
def delete_file
|
29
|
+
File.delete file_or_path(@file)
|
30
|
+
end
|
31
|
+
|
32
|
+
def it_should_have_an_extension_of(ext)
|
33
|
+
it "should have an extension of #{ext}" do
|
34
|
+
File.extname(file_or_path(@file)).should == ".#{ext}"
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
def it_should_have_a_mime_type_of(mimetype)
|
39
|
+
it "should have a mime type of #{mimetype}" do
|
40
|
+
File.mime_type?(@file).should == mimetype
|
41
|
+
end
|
42
|
+
end
|
data/uninstall.rb
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
# Uninstall hook code here
|
metadata
ADDED
@@ -0,0 +1,75 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: mimetype-fu
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Josh French
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
|
12
|
+
date: 2010-01-08 00:00:00 -08:00
|
13
|
+
default_executable:
|
14
|
+
dependencies: []
|
15
|
+
|
16
|
+
description: get the mimetype of a file directly in Ruby
|
17
|
+
email: josh@vitamin-j.com
|
18
|
+
executables: []
|
19
|
+
|
20
|
+
extensions: []
|
21
|
+
|
22
|
+
extra_rdoc_files:
|
23
|
+
- README
|
24
|
+
files:
|
25
|
+
- MIT-LICENSE
|
26
|
+
- README
|
27
|
+
- Rakefile
|
28
|
+
- VERSION
|
29
|
+
- init.rb
|
30
|
+
- install.rb
|
31
|
+
- lib/extensions_const.rb
|
32
|
+
- lib/mime_types.yml
|
33
|
+
- lib/mimetype_fu.rb
|
34
|
+
- mimetype-fu.gemspec
|
35
|
+
- spec/fixtures/file.jpg
|
36
|
+
- spec/fixtures/file.rb
|
37
|
+
- spec/fixtures/file.unknown
|
38
|
+
- spec/mime_type_spec.rb
|
39
|
+
- spec/spec_helper.rb
|
40
|
+
- tasks/mimetype_fu_tasks.rake
|
41
|
+
- test/mimetype_fu_test.rb
|
42
|
+
- uninstall.rb
|
43
|
+
has_rdoc: true
|
44
|
+
homepage: http://github.com/jfrench/mimetype-fu
|
45
|
+
licenses: []
|
46
|
+
|
47
|
+
post_install_message:
|
48
|
+
rdoc_options:
|
49
|
+
- --charset=UTF-8
|
50
|
+
require_paths:
|
51
|
+
- lib
|
52
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
53
|
+
requirements:
|
54
|
+
- - ">="
|
55
|
+
- !ruby/object:Gem::Version
|
56
|
+
version: "0"
|
57
|
+
version:
|
58
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
59
|
+
requirements:
|
60
|
+
- - ">="
|
61
|
+
- !ruby/object:Gem::Version
|
62
|
+
version: "0"
|
63
|
+
version:
|
64
|
+
requirements: []
|
65
|
+
|
66
|
+
rubyforge_project:
|
67
|
+
rubygems_version: 1.3.5
|
68
|
+
signing_key:
|
69
|
+
specification_version: 3
|
70
|
+
summary: get the mimetype of a file directly in Ruby
|
71
|
+
test_files:
|
72
|
+
- spec/fixtures/file.rb
|
73
|
+
- spec/mime_type_spec.rb
|
74
|
+
- spec/spec_helper.rb
|
75
|
+
- test/mimetype_fu_test.rb
|