module Tins::FileBinary
def binary?(options = {})
from offset options[:offset]). If an option isn't given the one
buffer of size options[:buffer_size] that is checked (beginning
(8-th bit is 1) exceeds options[:percentage_binary] in the
options[:percentage_zeros] or the percentage of binary bytes
A file is considered to be binary if the percentage of zeros exceeds
considered to be binary, and nil if it was empty.
Returns true if this file is considered to be binary, false if it is not
def binary?(options = {}) options |= FileBinary.default_options old_pos = tell seek options[:offset], Constants::SEEK_SET data = read options[:buffer_size] !data or data.empty? and return nil data_size = data.size data.count(Constants::ZERO).to_f / data_size > options[:percentage_zeros] / 100.0 and return true data.count(Constants::BINARY).to_f / data_size > options[:percentage_binary] / 100.0 ensure old_pos and seek old_pos, Constants::SEEK_SET end