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
1c1e37f2
Commit
1c1e37f2
authored
May 26, 2016
by
Rob Cherry
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add support for returning all possible mime types by magic.
parent
99290c4a
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
9 additions
and
10 deletions
+9
-10
lib/mimemagic.rb
+9
-10
No files found.
lib/mimemagic.rb
View file @
1c1e37f2
...
@@ -107,16 +107,15 @@ class MimeMagic
...
@@ -107,16 +107,15 @@ class MimeMagic
end
end
def
self
.
magic_match
(
io
,
method
)
def
self
.
magic_match
(
io
,
method
)
mime_or_mimes
=
if
io
.
respond_to?
(
:seek
)
&&
io
.
respond_to?
(
:read
)
if
io
.
respond_to?
(
:seek
)
&&
io
.
respond_to?
(
:read
)
io
.
binmode
io
.
binmode
io
.
set_encoding
(
Encoding
::
BINARY
)
if
io
.
respond_to?
(
:set_encoding
)
io
.
set_encoding
(
Encoding
::
BINARY
)
if
io
.
respond_to?
(
:set_encoding
)
MAGIC
.
send
(
method
)
{
|
type
,
matches
|
magic_match_io
(
io
,
matches
)
}
MAGIC
.
send
(
method
)
{
|
type
,
matches
|
magic_match_io
(
io
,
matches
)
}
else
else
str
=
io
.
respond_to?
(
:read
)
?
io
.
read
:
io
.
to_s
str
=
io
.
respond_to?
(
:read
)
?
io
.
read
:
io
.
to_s
str
=
str
.
force_encoding
(
Encoding
::
BINARY
)
if
str
.
respond_to?
(
:force_encoding
)
str
=
str
.
force_encoding
(
Encoding
::
BINARY
)
if
str
.
respond_to?
(
:force_encoding
)
MAGIC
.
send
(
method
)
{
|
type
,
matches
|
magic_match_str
(
str
,
matches
)
}
MAGIC
.
send
(
method
)
{
|
type
,
matches
|
magic_match_str
(
str
,
matches
)
}
end
end
method
==
:find
?
[
mime_or_mimes
]
:
mime_or_mimes
end
end
def
self
.
magic_match_io
(
io
,
matches
)
def
self
.
magic_match_io
(
io
,
matches
)
...
...
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