#!/usr/bin/env ruby

# run me like ruby binary.rb /PATH/TO/FILE
# this scripts checks if the file contains binary or textual data.
# thanks meineerde for help

require 'yaml'

FILENAME = ARGV[0]
f = File.read(FILENAME)
binary = f.is_binary_data?
binary_koef = f.count( "^ -~", "^\r\n" ).fdiv(f.size)

puts "The file #{FILENAME} contains #{binary ? "BINARY"  : "TEXTUAL"} data."
puts "file is binary if #{binary_koef} > 0.3"