Merge pull request #74 from kou/improve-binary-file-detection

Improve binary file detection
This commit is contained in:
uu59 2014-08-11 12:47:47 +09:00
commit a712acfa3a

View File

@ -36,8 +36,7 @@ class FileReverseReader
def binary_file?
sample = io.read(1024) || ""
sample2 = sample.force_encoding('ascii-8bit').encode('us-ascii', :undef => :replace, :invalid => :replace, :replace => "")
sample != sample2 # maybe binary file
!sample.force_encoding('us-ascii').valid_encoding?
ensure
io.rewind
end