You are here

function hacked_file_is_binary in Hacked! 8.2

Same name and namespace in other branches
  1. 5 hacked.module \hacked_file_is_binary()
  2. 6.2 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 src/hackedFileGroup.php
Determine if the given file is binary.
hackedFileIgnoreEndingsHasher::perform_hash in src/hackedFileIgnoreEndingsHasher.php
Returns a hash of the given filename.

File

./hacked.module, line 64
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;
}