Method: CommentExtractor::File.binary?

Defined in:
lib/comment_extractor/file.rb

.binary?(file_path) ⇒ Boolean

Returns:

  • (Boolean)


18
19
20
21
22
23
24
25
26
27
# File 'lib/comment_extractor/file.rb', line 18

def self.binary?(file_path)
  header = File.read(file_path, File.stat(file_path).blksize) || nil

  if header.nil? || header.empty?
    false
  else
    chars = header.chars
    (chars.grep(' '..'~').size / chars.size.to_f) <= THRESHOLD_BINARY
  end
end