function hacked_file_is_binary in Hacked! 5
Same name and namespace in other branches
- 8.2 hacked.module \hacked_file_is_binary()
- 6.2 hacked.module \hacked_file_is_binary()
- 6 hacked.module \hacked_file_is_binary()
- 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()
- hacked_reports_hacked_diff in ./
hacked.diff.inc - theme_hacked_detailed_report in ./
hacked.details.inc - Theme project status report.
File
- ./
hacked.module, line 499 - 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;
}