You are here

function hacked_file_is_binary in Hacked! 6.2

Same name and namespace in other branches
  1. 8.2 hacked.module \hacked_file_is_binary()
  2. 5 hacked.module \hacked_file_is_binary()
  3. 6 hacked.module \hacked_file_is_binary()
  4. 7.2 hacked.module \hacked_file_is_binary()

Determine if a file is a binary file.

Taken from: http://www.ultrashock.com/forums/server-side/checking-if-a-file-is-binar... and then tweaked in: http://drupal.org/node/760362.

2 calls to hacked_file_is_binary()
hackedFileGroup::is_not_binary in includes/hacked_project.inc
Determine if the given file is binary.
hackedFileIgnoreEndingsHasher::perform_hash in includes/hacked_project.inc
Returns a hash of the given filename.

File

./hacked.module, line 210
The Hacked! module, shows which project have been changed since download.

Code

function hacked_file_is_binary($file) {
  if (file_exists($file)) {
    if (!is_file($file)) {
      return 0;
    }
    if (!is_readable($file)) {
      return 1;
    }
    $fh = fopen($file, "r");
    $blk = fread($fh, 512);
    fclose($fh);
    clearstatcache();
    return 0 or substr_count($blk, "^\r\n") / 512 > 0.3 or substr_count($blk, "^ -~") / 512 > 0.3 or substr_count($blk, "\0") > 0;
  }
  return 0;
}