From: Rebhan, Gilbert [mailto:[email protected]]
Is there an exisiting standard what is considered as a binary file,
if you’re on a *nix (non-windows) box, you should use the os file
command and then just wrap it in ruby,
irb(main):022:0> def is_bin(f)
irb(main):023:1> %x(file #{f}) !~ /text/
irb(main):024:1> end
=> nil
irb(main):025:0> is_bin “test.rb”
=> false
irb(main):026:0> is_bin “test.txt”
=> false
irb(main):027:0> is_bin “/usr/local/bin/dnscache”
=> true
irb(main):028:0> is_bin “/bin/ps”
=> true
irb(main):029:0> def is_text(f)
irb(main):030:1> %x(file #{f}) =~ /text/
irb(main):031:1> end
=> nil
irb(main):032:0> is_text “test.rb”
=> 27
irb(main):033:0> is_text “test.txt”
=> 16
irb(main):034:0> is_text “/usr/local/bin/dnscache”
=> nil
irb(main):035:0> is_text “/bin/ps”
=> nil
kind regards -botp