Skip to content

File.binary?

Daniel Berger edited this page Dec 5, 2022 · 2 revisions

File.binary?(file)

Returns whether or not +file+ is a binary non-image file, i.e. executable, shared object, ect.

Note that this is NOT guaranteed to be 100% accurate. It performs a "best guess" based on a simple test of the first File.blksize characters, or 4096, whichever is smaller. It simply looks for a double null sequence internally.

Example:

  File.binary?('somefile.exe') # => true
  File.binary?('somefile.txt') # => false
Clone this wiki locally