Class: File
- Inherits:
-
Object
- Object
- File
- Defined in:
- lib/vim_printer/core_ext/file.rb
Overview
Class Method Summary collapse
-
.binary?(name) ⇒ Boolean
Note: monkey patch to check if a given file is a binary.
Class Method Details
.binary?(name) ⇒ Boolean
Note: monkey patch to check if a given file is a binary
4 5 6 7 8 9 10 11 12 13 14 15 16 |
# File 'lib/vim_printer/core_ext/file.rb', line 4 def self.binary?(name) name = File.(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 |