Commit 1c1e37f2 by Rob Cherry

Add support for returning all possible mime types by magic.

parent 99290c4a
...@@ -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)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment