public function FileOperations::fileCompare in AT Tools 8
Compare two files. First compare file size, then compare their contents. Return true if the files are the same, otherwise false.
Parameters
string $afile: Path to 'a' file.
string $bfile: Path to 'b' file.
Return value
array $results
File
- at_theme_generator/
src/ File/ FileOperations.php, line 105 - Contains \Drupal\at_theme_generator\File\FileOperations
Class
Namespace
Drupal\at_theme_generator\FileCode
public function fileCompare($afile, $bfile) {
// Check if filesize is different
if (filesize($afile) !== filesize($bfile)) {
return false;
}
// Check if content is different
$aopen = fopen($afile, 'rb');
$bopen = fopen($bfile, 'rb');
$result = true;
while (!feof($aopen)) {
if (fread($aopen, 8192) != fread($bopen, 8192)) {
$result = false;
break;
}
}
fclose($aopen);
fclose($bopen);
return $result;
}