Sha256: 1d5275b6cc8af054360a2575dd3bdcdfa4cca2e5513898d7a42619ab7545857d

Contents?: true

Size: 498 Bytes

Versions: 14

Compression:

Stored size: 498 Bytes

Contents

# from: http://blade.nagaokaut.ac.jp/cgi-bin/scat.rb/ruby/ruby-talk/44936
class File
  # Note: monkey patch to check if a given file is a binary
  def self.binary?(name)
    name = File.expand_path(name)
    my_stat = stat(name)
    return false unless my_stat.file?
    open(name) do |file|
      blk = file.read(my_stat.blksize)
      if blk
        return blk.size == 0 || blk.count("^ -~", "^\r\n") / blk.size > 0.3 || blk.count("\x00") > 0
      else
        false
      end
    end
  end
end

Version data entries

14 entries across 14 versions & 1 rubygems

Version Path
vim_printer-0.2.7 lib/vim_printer/core_ext/file.rb
vim_printer-0.2.6 lib/vim_printer/core_ext/file.rb
vim_printer-0.2.5 lib/vim_printer/core_ext/file.rb
vim_printer-0.2.4 lib/vim_printer/core_ext/file.rb
vim_printer-0.2.3 lib/vim_printer/core_ext/file.rb
vim_printer-0.2.2 lib/vim_printer/core_ext/file.rb
vim_printer-0.2.1 lib/vim_printer/core_ext/file.rb
vim_printer-0.2.0 lib/vim_printer/core_ext/file.rb
vim_printer-0.1.12 lib/vim_printer/core_ext/file.rb
vim_printer-0.1.11 lib/vim_printer/core_ext/file.rb
vim_printer-0.1.10 lib/vim_printer/core_ext/file.rb
vim_printer-0.1.9 lib/vim_printer/core_ext/file.rb
vim_printer-0.1.8 lib/vim_printer/core_ext/file.rb
vim_printer-0.1.7 lib/vim_printer/core_ext/file.rb