binary?(file)
public
Determines if the file is a “binary” file which basically means it has
content that an RDoc parser shouldn’t try to
consume.
# File lib/rdoc/parser.rb, line 69
def self.binary?(file)
s = File.read(file, 1024) or return false
if s[0, 2] == Marshal.dump('')[0, 2] then
true
elsif file =~ /erb\.rb$/ then
false
elsif s.scan(/<%|%>/).length >= 4 || s.index("\x00") then
true
elsif 0.respond_to? :fdiv then
s.count("\x00-\x7F", "^ -~\t\r\n").fdiv(s.size) > 0.3
else # HACK 1.8.6
(s.count("\x00-\x7F", "^ -~\t\r\n").to_f / s.size) > 0.3
end
end