Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
M
mimemagic
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
ikcrm_common
mimemagic
Commits
ddcbcf3f
Commit
ddcbcf3f
authored
Oct 03, 2010
by
Jacques Crocker
Committed by
minad
Oct 03, 2010
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add helper for MimeMagic.by_path
parent
266129fe
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
13 additions
and
0 deletions
+13
-0
lib/mimemagic.rb
+5
-0
test/mimemagic_test.rb
+8
-0
No files found.
lib/mimemagic.rb
View file @
ddcbcf3f
...
@@ -78,6 +78,11 @@ class MimeMagic
...
@@ -78,6 +78,11 @@ class MimeMagic
mime
?
new
(
mime
)
:
nil
mime
?
new
(
mime
)
:
nil
end
end
# Lookup mime type by filename
def
self
.
by_path
(
path
)
by_extension
(
File
.
extname
(
path
))
end
# Lookup mime type by magic content analysis.
# Lookup mime type by magic content analysis.
# This is a slow operation.
# This is a slow operation.
def
self
.
by_magic
(
io
)
def
self
.
by_magic
(
io
)
...
...
test/mimemagic_test.rb
View file @
ddcbcf3f
...
@@ -34,6 +34,14 @@ describe 'MimeMagic' do
...
@@ -34,6 +34,14 @@ describe 'MimeMagic' do
MimeMagic
.
by_extension
(
''
).
should
.
equal
nil
MimeMagic
.
by_extension
(
''
).
should
.
equal
nil
end
end
it
'should recognize by a path'
do
MimeMagic
.
by_path
(
'/adsjkfa/kajsdfkadsf/kajsdfjasdf.html'
).
should
.
equal
'text/html'
MimeMagic
.
by_path
(
'something.html'
).
should
.
equal
'text/html'
MimeMagic
.
by_path
(
'wtf.rb'
).
should
.
equal
'application/x-ruby'
MimeMagic
.
by_path
(
'where/am.html/crazy'
).
should
.
equal
nil
MimeMagic
.
by_path
(
''
).
should
.
equal
nil
end
it
'should recognize by magic'
do
it
'should recognize by magic'
do
Dir
[
'test/files/*'
].
each
do
|
file
|
Dir
[
'test/files/*'
].
each
do
|
file
|
mime
=
file
[
11
..-
1
].
gsub
(
'.'
,
'/'
)
mime
=
file
[
11
..-
1
].
gsub
(
'.'
,
'/'
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment